Hi i really want to set the window position of my console applicaton
I've managed to find Console:: SetWindowPosition bu using google but cant find how to use it...
http://msdn2.microsoft.com/en-us/library/system.console.setwindowposition.aspx
This link shows an example.
But it wont compile
I'm guessing its missing header files, what are they?

I dont realy care how i do it, o if there is another way, then that would be great

Here are the win32 api console functions. include windows.h and you will probably have to have the Windows Platform SDK, free for download from Microsoft.com

First call GetConsoleWindow() to get the handle to the console window, they you can call MoveWindow() to move it to wherever you want. I have not done it myself with a console window.

Is this how you use it?
It won't work!!!!
thanks

#include <iostream>
#include "Windows.h"
#include "Wincon.h"

//
int main()
{
  HWND a;

//a = GetConsoleWindow();
  //HWND WINAPI GetConsoleWindow(void);
a = GetConsoleWindow();
   MoveWindow(a,1,1,55,55,1);

} // end Mai

this works with VC++ 2005 Express and the Windows Platform SDK installed You have to add User32.lib to the list of link libraries.

#include <windows.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    HWND hWnd = GetConsoleWindow();
    MoveWindow(hWnd,100,100,300,400,TRUE);
    cin.ignore();
	return 0;
}

I get these errors:
error C3861: 'GetConsoleWindow': identifier not found, even with argument-dependent lookup
error C2061: syntax error : identifier '_TCHAR'

I'm have not got windows sdk installed, checked and its like 800mb, is it possible just to download the specific library?
thanks

this works with VC++ 2005 Express and the Windows Platform SDK installed You have to add User32.lib to the list of link libraries.

#include <windows.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    HWND hWnd = GetConsoleWindow();
    MoveWindow(hWnd,100,100,300,400,TRUE);
    cin.ignore();
    return 0;
}

I don't think you can get just part of the SDK. But I think you can get it on CD for just a few $$$.

The _TCHAR allows the compiler to compile for either UNICODE or not. If your compiler doesn't understand that macro you can replace it with char

try this it will work!


#include<iostream>
#include<windows.h>
using namespace std;
void gotoxy(int a, int b);
int main()
{
    cout << "Cursor before:" << endl;
    gotoxy(23, 12);
    cout << "Cursor after:";
}

void gotoxy(int x, int y)
{
    HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD coord;
    coord.X = x;
    coord.Y = y;
    SetConsoleCursorPosition(hStdOut, coord);
}
This article has been dead for over six months. Start a new discussion instead.