From: vischne AT ibm DOT net-nospam Subject: Subclassing the cygwin console window? 1 Nov 1997 09:03:54 -0800 Message-ID: <199711011647.QAA32278.cygnus.gnu-win32@out1.ibm.net> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit To: gnu-win32 AT cygnus DOT com One interesting thing to do with the cygwin console window is to subclass it so that it handles fgetc() programming, but can be used as a graphics window. The following code fragment optimistically gets the handle of the console window, then acquires its callback function and substitutes another in its place. Unfortunately, the example doesn't work. Has anyone else tried this or seen a book with an explanation of why this doesn't work? ======================================================================= #include #include HWND hWndVGA; WNDPROC lpfnTextProc; LRESULT CALLBACK VGAWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); int vga_init () { /* Subclass the cygwin text window: */ hWndVGA = GetActiveWindow(); lpfnTextProc = (WNDPROC)GetWindowLong(hWndVGA, GWL_WNDPROC); SetWindowLong(hWndVGA, GWL_WNDPROC, (LONG)VGAWndProc); /* Start the subclassing process: */ return (int)SendMessage(hWndVGA, WM_PAINT, (WORD)0, (LONG)0); } LRESULT CALLBACK VGAWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { static HPALETTE hPal; switch( uMsg ) { case WM_ERASEBKGND: SetWindowPos(hWndVGA, HWND_TOP, 0, 0, 640, 480, SWP_SHOWWINDOW); return DefWindowProc(hWnd, uMsg, wParam, lParam); case WM_PAINT: SetWindowPos(hWndVGA, HWND_TOP, 0, 0, 640, 480, SWP_SHOWWINDOW); return DefWindowProc(hWnd, uMsg, wParam, lParam); case WM_QUERYNEWPALETTE: /* About to get focus, so realize our palette. */ /*............................................ */ { HDC hDC = GetDC( hWnd ); SelectPalette( hDC, hPal, 0 ); if ( RealizePalette( hDC ) ) InvalidateRect( hWnd, NULL, TRUE ); ReleaseDC( hWnd, hDC ); } break; case WM_PALETTECHANGED: /* Another application changed the palette. */ /*......................................... */ if ( (HWND)wParam != hWnd ) { HDC hDC = GetDC( hWnd ); SelectPalette( hDC, hPal, 0 ); if ( RealizePalette( hDC ) ) UpdateColors( hDC ); ReleaseDC( hWnd, hDC ); } break; default: return lpfnTextProc(hWnd, uMsg, wParam, lParam); return 0L; }; } /* Note the Unix main entry: */ int main (int argc, char **argv) { MSG msg; printf("About to subclass the Cygwin text window.\n"); vga_init(); sleep(5); if (getc(stdin) == (int)'q') exit(0); while (GetMessage(&msg, hWndVGA, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); }; } - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".