home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / cursor / setcurso.c < prev    next >
C/C++ Source or Header  |  1988-08-10  |  3KB  |  87 lines

  1. /*
  2.  *
  3.  *  SetCursor
  4.  *  setcurso.c
  5.  *
  6.  *  This program demonstrates the use of the function SetCursor. 
  7.  *  It sets the cursor shape to the cursor specified by hCursor. HCursor
  8.  *  is a handle to a cursor resource, which must have been loaded 
  9.  *  previously using the LoadCursor function. The cursor is set only if the 
  10.  *  new shape is different from the existing shape. If hCursor is NULL, the 
  11.  *  cursor is removed from the screen. To change the cursor while it is in
  12.  *  a window, the class cursor for the given window's class must be set to 
  13.  *  NULL. If the class cursor is not null, Windows restores the old shape
  14.  *  each time the mouse moves.
  15.  *
  16.  */
  17.  
  18. #include "windows.h"
  19.  
  20. /* Procedure called when the application is loaded for the first time */
  21. BOOL WinInit( hInstance )
  22. HANDLE hInstance;
  23. {
  24.     WNDCLASS   wcClass;
  25.  
  26.     /* registering the parent window class */
  27.     wcClass.hCursor        = (HCURSOR)NULL;
  28.     wcClass.hIcon          = LoadIcon (hInstance, (LPSTR)"WindowIcon");
  29.     wcClass.lpszMenuName   = (LPSTR)NULL;
  30.     wcClass.lpszClassName  = (LPSTR)"Setcurso";
  31.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  32.     wcClass.hInstance      = hInstance;
  33.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  34.     wcClass.lpfnWndProc    = DefWindowProc;
  35.     wcClass.cbClsExtra     = 0;
  36.     wcClass.cbWndExtra     = 0;
  37.  
  38.     RegisterClass( (LPWNDCLASS)&wcClass );
  39.     return TRUE;        /* Initialization succeeded */
  40. }
  41.  
  42.  
  43. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  44. HANDLE hInstance, hPrevInstance;
  45. LPSTR lpszCmdLine;
  46. int cmdShow;
  47. {
  48.     HWND    hWnd;              /* Handle to the parent window    */
  49.     HCURSOR hCursor;           /* Handle to the cursor           */
  50.     MSG     msg;               /* Window messages                */
  51.     
  52.     WinInit (hInstance);
  53.  
  54.     hWnd = CreateWindow((LPSTR)"Setcurso",
  55.                         (LPSTR)"Changing Cursor",
  56.                         WS_OVERLAPPEDWINDOW,
  57.                         50,                /* x         */
  58.                         50,                /* y         */
  59.                         600,               /* width     */
  60.                         250,               /* height    */
  61.                         (HWND)NULL,        /* no parent */
  62.                         (HMENU)NULL,       /* use class menu */
  63.                         (HANDLE)hInstance, /* handle to window instance */
  64.                         (LPSTR)NULL        /* no params to pass on */
  65.                        );
  66.  
  67.     /* Make window visible according to the way the app is activated */
  68.     ShowWindow( hWnd, cmdShow );
  69.     UpdateWindow( hWnd );
  70.  
  71.     /* Setting the new cursor */
  72.     MessageBox (hWnd, (LPSTR)"This is the old cursor", (LPSTR)"Before", MB_OK);
  73.     hCursor = LoadCursor (NULL, IDC_CROSS);
  74.     MessageBox (hWnd, (LPSTR)"Press OK to see the new cursor", 
  75.                 (LPSTR)"After", MB_OK);
  76.     SetCursor (hCursor);
  77.  
  78.     /* Window message loop */
  79.     while (GetMessage ((LPMSG) &msg, NULL, 0, 0))
  80.       { 
  81.          TranslateMessage ((LPMSG) &msg);
  82.          DispatchMessage ((LPMSG) &msg);
  83.       }
  84.     
  85.     return (int) msg.wParam;
  86. }
  87.