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

  1. /*
  2.  *   LoadCursor
  3.  *
  4.  *   This program demonstrates the use of the LoadCursor function. The
  5.  *   LoadCursor function loads either a standard windows cursor or a user
  6.  *   defined cursor created with the Icon Editor. LoadCursor is called in
  7.  *   LoadCursInit in this sample application.
  8.  */
  9.  
  10. #include "windows.h"
  11.  
  12. long    FAR PASCAL LoadCursWndProc (HWND, unsigned, WORD, LONG);
  13. int     PASCAL WinMain (HANDLE, HANDLE, LPSTR, int);
  14. BOOL FAR PASCAL About (HWND, unsigned, WORD, LONG);
  15.  
  16. /***************************************************************************/
  17.  
  18. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  19. HANDLE    hInstance, hPrevInstance;
  20. LPSTR     lpszCmdLine;
  21. int       cmdShow;
  22.   {
  23.   MSG   msg;
  24.   HWND  hWnd;
  25.   HMENU hMenu;
  26.  
  27.   if (!hPrevInstance)
  28.     {
  29.     WNDCLASS   LoadCursClass;
  30.  
  31.   /*----------------------- Invoke LoadCursor -------------------------------*/
  32.     LoadCursClass.hCursor        = LoadCursor (hInstance, "mycursor");
  33.   /*-------------------------------------------------------------------------*/
  34.     LoadCursClass.hIcon          = LoadIcon (hInstance, NULL);
  35.     LoadCursClass.lpszMenuName   = (LPSTR)NULL;
  36.     LoadCursClass.lpszClassName  = (LPSTR)"Sample Application";
  37.     LoadCursClass.hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
  38.     LoadCursClass.hInstance      = hInstance;
  39.     LoadCursClass.style          = CS_HREDRAW | CS_VREDRAW;
  40.     LoadCursClass.lpfnWndProc    = LoadCursWndProc;
  41.  
  42.     if (!RegisterClass ( (LPWNDCLASS)&LoadCursClass))
  43.       return FALSE;
  44.     }
  45.  
  46.   hWnd = CreateWindow ( (LPSTR)"Sample Application",
  47.       (LPSTR)"LoadCursor Application",
  48.       WS_OVERLAPPEDWINDOW,
  49.       CW_USEDEFAULT,
  50.       CW_USEDEFAULT,
  51.       CW_USEDEFAULT,
  52.       CW_USEDEFAULT,
  53.       (HWND)NULL,        /* no parent */
  54.       (HMENU)NULL,       /* use class menu */
  55.       (HANDLE)hInstance, /* handle to window instance */
  56.       (LPSTR)NULL);      /* no params to pass on */
  57.  
  58.   ShowWindow (hWnd, cmdShow);
  59.   UpdateWindow (hWnd);
  60.  
  61.   while (GetMessage ( (LPMSG) & msg, NULL, 0, 0))
  62.     {
  63.     TranslateMessage ( (LPMSG) & msg);
  64.     DispatchMessage ( (LPMSG) & msg);
  65.     }
  66.   return (int)msg.wParam;
  67.   }
  68.  
  69.  
  70. /***************************************************************************/
  71. long    FAR PASCAL LoadCursWndProc (hWnd, message, wParam, lParam)
  72. HWND     hWnd;
  73. unsigned message;
  74. WORD     wParam;
  75. LONG     lParam;
  76.   {
  77.   switch (message)
  78.     {
  79.     case WM_DESTROY:
  80.   /* Remove the cursor bitmap from memory or decrement the
  81.            * reference count if it is greater than 1.
  82.            */
  83.       FreeResource (GetClassWord (hWnd, GCW_HCURSOR));
  84.       PostQuitMessage (0);
  85.       break;
  86.  
  87.     default:
  88.       return DefWindowProc (hWnd, message, wParam, lParam);
  89.       break;
  90.     }
  91.   return (0L);
  92.   }
  93.