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

  1. /*
  2. Function(s) demonstrated in this program:  ShowCursor
  3.  
  4. Compiler version:  5.10
  5.  
  6. Description:  Use ShowCursor to hide the cursor each time the right mouse
  7.           button is pressed, and display it again when the button is
  8.           released.
  9.  
  10. Additional Comments:
  11.  
  12.  
  13.  
  14. ****************************************************************************/
  15.  
  16. #include <windows.h>
  17.  
  18. long FAR PASCAL WndProc (HWND, unsigned, WORD, LONG) ;
  19.  
  20. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  21.      HANDLE      hInstance, hPrevInstance ;
  22.      LPSTR       lpszCmdLine ;
  23.      int         nCmdShow ;
  24.      {
  25.      static char szAppName [] = "SampleWindow" ;
  26.      HWND        hWnd ;
  27.      WNDCLASS    wndclass ;
  28.      MSG     msg;
  29.  
  30.      if (!hPrevInstance) 
  31.           {
  32.           wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  33.           wndclass.lpfnWndProc   = WndProc ;
  34.           wndclass.cbClsExtra    = 0 ;
  35.           wndclass.cbWndExtra    = 0 ;
  36.           wndclass.hInstance     = hInstance ;
  37.           wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  38.       wndclass.hCursor     = LoadCursor (NULL, IDC_CROSS);
  39.           wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  40.           wndclass.lpszMenuName  = NULL ;
  41.           wndclass.lpszClassName = szAppName ;
  42.  
  43.           if (!RegisterClass (&wndclass))
  44.                return FALSE ;
  45.           }
  46.  
  47.      hWnd = CreateWindow (szAppName,            /* window class name       */
  48.             "Using the ShowCursor function",  /* window caption      */
  49.                     WS_OVERLAPPEDWINDOW,        /* window style            */
  50.                     CW_USEDEFAULT,              /* initial x position      */
  51.                     0,                          /* initial y position      */
  52.                     CW_USEDEFAULT,              /* initial x size          */
  53.                     0,                          /* initial y size          */
  54.                     NULL,                       /* parent window handle    */
  55.                     NULL,                       /* window menu handle      */
  56.                     hInstance,                  /* program instance handle */
  57.                     NULL) ;                     /* create parameters       */
  58.  
  59.      ShowWindow (hWnd, nCmdShow) ;
  60.  
  61.      UpdateWindow (hWnd) ;
  62.  
  63.      while (GetMessage(&msg, NULL, 0, 0))
  64.      {
  65.       TranslateMessage(&msg);
  66.       DispatchMessage(&msg);
  67.      } 
  68.      return (msg.wParam) ;     
  69.      }
  70.  
  71. long FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  72. HWND     hWnd ;
  73. unsigned iMessage ;
  74. WORD     wParam ;
  75. LONG     lParam ;
  76.     {
  77.     PAINTSTRUCT ps;
  78.     HDC     hDC;
  79.     switch(iMessage)
  80.     {
  81.     case WM_CREATE:
  82.         {
  83.         break;
  84.         }
  85.     case WM_PAINT:
  86.         {
  87.         hDC = BeginPaint(hWnd, (LPPAINTSTRUCT)&ps);
  88.         EndPaint(hWnd, (LPPAINTSTRUCT)&ps);
  89.         break;
  90.         }
  91.     case WM_RBUTTONDOWN:
  92.         {
  93.         ShowCursor(0);
  94.         break;
  95.         }
  96.     case WM_RBUTTONUP:
  97.         {
  98.         ShowCursor(1);
  99.         break;
  100.         }
  101.     case WM_DESTROY:
  102.         {
  103.         PostQuitMessage(0);
  104.         break;
  105.         }
  106.     default:
  107.         {
  108.         return DefWindowProc (hWnd, iMessage, wParam, lParam) ;
  109.         }
  110.     }
  111.     return (0L);
  112.     }
  113.