home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / class / setclswd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  3.0 KB  |  83 lines

  1. /*
  2.  *  SetClassWord
  3.  *  setclswd.c
  4.  *
  5.  *  This program demonstrates the use of the function SetClassWord.
  6.  *  It replaces the word at the specified index in the WNDCLASS structure
  7.  *  of the window. It is used to change the attributes of the window class
  8.  *  after the window class has been registered.  
  9.  *
  10.  */
  11.  
  12. #include "windows.h"
  13.  
  14. /* Procedure called when the application is loaded for the first time */
  15. BOOL WinInit( hInstance )
  16. HANDLE hInstance;
  17. {
  18.     WNDCLASS   wcClass;
  19.  
  20.     /* registering the parent window class */
  21.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  22.     wcClass.hIcon          = LoadIcon (hInstance, (LPSTR)"WindowIcon");
  23.     wcClass.lpszMenuName   = (LPSTR)NULL;
  24.     wcClass.lpszClassName  = (LPSTR)"Setclswd";
  25.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  26.     wcClass.hInstance      = hInstance;
  27.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  28.     wcClass.lpfnWndProc    = DefWindowProc;
  29.     wcClass.cbClsExtra     = 0;
  30.     wcClass.cbWndExtra     = 0;
  31.  
  32.     RegisterClass( (LPWNDCLASS)&wcClass );
  33.     return TRUE;        /* Initialization succeeded */
  34. }
  35.  
  36.  
  37. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  38. HANDLE hInstance, hPrevInstance;
  39. LPSTR lpszCmdLine;
  40. int cmdShow;
  41. {
  42.     HWND    hWnd;              /* Handle to the parent window    */
  43.     HCURSOR hCursor;           /* Handle to the brushes          */
  44.     MSG     msg;               /* Window messages                */
  45.     
  46.     WinInit (hInstance);
  47.  
  48.     hWnd = CreateWindow((LPSTR)"Setclswd",
  49.                         (LPSTR)"Changing Window Class Information",
  50.                         WS_OVERLAPPEDWINDOW,
  51.                         50,                /* x         */
  52.                         50,                /* y         */
  53.                         600,               /* width     */
  54.                         250,               /* height    */
  55.                         (HWND)NULL,        /* no parent */
  56.                         (HMENU)NULL,       /* use class menu */
  57.                         (HANDLE)hInstance, /* handle to window instance */
  58.                         (LPSTR)NULL        /* no params to pass on */
  59.                        );
  60.  
  61.     /* Make window visible according to the way the app is activated */
  62.     ShowWindow( hWnd, cmdShow );
  63.     UpdateWindow( hWnd );
  64.  
  65.     /* SetClassWord is used here to change the cursor in the window class
  66.      * structure. It can be used also to change the icon, window style, and
  67.      * other attributes of the window class.
  68.      */
  69.     MessageBox (hWnd, (LPSTR)"This is the old cursor", (LPSTR)"Before", MB_OK);
  70.     hCursor = LoadCursor (NULL, IDC_CROSS);
  71.     SetClassWord (hWnd, GCW_HCURSOR, hCursor);
  72.     MessageBox (hWnd, (LPSTR)"Press OK to see the new cursor", (LPSTR)"After", MB_OK);
  73.  
  74.     /* the message loop */
  75.     while (GetMessage ((LPMSG) &msg, NULL, 0, 0))
  76.       { 
  77.          TranslateMessage ((LPMSG) &msg);
  78.          DispatchMessage ((LPMSG) &msg);
  79.       }
  80.     
  81.     return (int) msg.wParam;
  82. }
  83.