Subclassing the cygwin console window?

vischne@ibm.net-nospam vischne@ibm.net-nospam
Sat Nov 1 08:47:00 GMT 1997


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 <windows.h>
#include <stdio.h>

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@cygnus.com" with one line of text: "help".



More information about the Cygwin mailing list