Saturday, March 19, 2011

Move console windows using C++ and windows function.

You can move your console windows at your desire location in screen and also resize the size of console windows  by using this source code in code::block.

#include <windows.h>
HWND WINAPI GetConsoleWindowNT(void)
    // declare function pointer type

    typedef HWND WINAPI (*GetConsoleWindowT)(void);

    // declare one such function pointer

    GetConsoleWindowT GetConsoleWindow;

    // get a handle on kernel32.dll

    HMODULE hK32Lib = GetModuleHandle(TEXT("KERNEL32.DLL"));

    // assign procedure address to function pointer

    GetConsoleWindow = (GetConsoleWindowT)GetProcAddress(hK32Lib,TEXT("GetConsoleWindow"));

    // check if the function pointer is valid

    // since the function is undocumented

    if ( GetConsoleWindow == NULL ) {
         return NULL;

    // call the undocumented function

    return GetConsoleWindow();

int main()
    HWND hWnd=GetConsoleWindowNT();



  1. THANK YOU - I was wondering if I had to call some windows to get this working -- apparently yes.

  2. THANK YOU so much bro! You saved my day! Keep up the good work.