EDN Admin
Well-known member
I am trying to access window messages from a console app. Using http://bobobobo.wordpress.com/2008/02/03/getting-the-hwnd-and-hinstance-of-the-console-window/ as a reference i created something that looks like this<br/> <br/> <br/> // these are defined in another part of the code<br/> HWND gConsoleHWND;<br/> HDC gConsoleHDC;<br/> HINSTANCE gConsoleHInstance;<br/> <br/> LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)<br/> {<br/> // note: frame movement must be passed on to the last return<br/> // note2: any functions that have issues because of the return 0 in this function, have the subfunction call<br/> // DefWindowProc with the appropriate arguments<br/> switch(message)<br/> {<br/> ...<br/> }<br/> return DefWindowProc( hwnd, message, wparam, lparam );<br/> }<br/> <br/> ATOM RegisterInstance(HINSTANCE hInstance)<br/> {<br/> WNDCLASSEX wc = {<br/> sizeof(WNDCLASSEX),<br/> (CS_HREDRAW | CS_VREDRAW),<br/> (WNDPROC) WndProc, // function that will receive messages<br/> 0,<br/> 0,<br/> hInstance,<br/> NULL,<br/> LoadCursor(NULL, IDC_ARROW),<br/> (HBRUSH)GetStockObject(BLACK_BRUSH),<br/> NULL,<br/> title,<br/> NULL<br/> };<br/> <br/> return RegisterClassEx(&wc);<br/> }<br/> <br/> int main()<br/> {<br/> setupConsole(); // setup the hdc, hwnd, and hinstance<br/> // Register the console window -> HINSTANCE, HDC, and HWND<br/> if(!RegisterInstance(gConsoleHInstance))<br/> MessageBox(GetDesktopWindow(),L"could not register instance",L"!",MB_OK);<br/> // pump messages<br/> MSG msg;<br/> while( GetMessage( &msg, gConsoleHWND, 0, 0 ) )<br/> {<br/> TranslateMessage(&msg);<br/> DispatchMessage(&msg);<br/> }<br/> system("pause");<br/> return 0;<br/> }<br/> <br/> <br/> the code runs fine but it will never enter WndProc, any suggestions? Or will the console not let me define a process for it using RegisterClassEx?<br/>
View the full article
View the full article