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

  1. /*
  2.  *
  3.  *  GetCapture
  4.  *  
  5.  *  This program demonstrates the use of the function GetCapture.
  6.  *  This function retrieves a handle that identifies the window that
  7.  *  has the mouse capture.
  8.  *  
  9.  */
  10.  
  11. #include "windows.h"
  12.  
  13. static HWND hWnd;
  14. char szBuff [70];
  15.  
  16. int PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  17. HANDLE hInstance, hPrevInstance;
  18. LPSTR  lpszCmdLine;
  19. int    cmdShow;
  20. {
  21.   HWND hWndPrev;
  22.   HWND hWndGetCap;
  23.   int  i;
  24.   
  25.   if (!hPrevInstance)
  26.     {
  27.     WNDCLASS rClass;
  28.  
  29.     rClass.lpszClassName = (LPSTR)"getcap";
  30.     rClass.hInstance     = hInstance;
  31.     rClass.lpfnWndProc   = DefWindowProc;
  32.     rClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  33.     rClass.hIcon         = LoadIcon(hInstance, IDI_APPLICATION);
  34.     rClass.lpszMenuName  = (LPSTR)NULL;
  35.     rClass.hbrBackground = GetStockObject(WHITE_BRUSH);
  36.     rClass.style         = CS_HREDRAW | CS_VREDRAW;
  37.     rClass.cbClsExtra    = 0;
  38.     rClass.cbWndExtra    = 0;
  39.    
  40.     RegisterClass((LPWNDCLASS)&rClass);
  41.     }
  42.  
  43.   hWnd = CreateWindow((LPSTR)"getcap", (LPSTR)"GetCapture",
  44.                       WS_OVERLAPPEDWINDOW,
  45.                       CW_USEDEFAULT, CW_USEDEFAULT,
  46.                       CW_USEDEFAULT, CW_USEDEFAULT,
  47.                       (HWND)NULL, (HMENU)NULL,
  48.                       (HANDLE)hInstance, (LPSTR)NULL);
  49.  
  50.   ShowWindow(hWnd, cmdShow);
  51.  
  52.   MessageBox(GetFocus(), (LPSTR)"Getting window with mouse capture.",
  53.              (LPSTR)"GetCapture()",
  54.               MB_OK);
  55.   SetCapture(hWnd);
  56.   hWndGetCap = GetCapture();
  57.  
  58.   for (i = 0; i < 5; i++)
  59.     {
  60.     MessageBeep(NULL);
  61.     FlashWindow(hWndGetCap, NULL);
  62.     }
  63.  
  64.   MessageBox(GetFocus(), (LPSTR)"The capture window has been flashed.",
  65.              (LPSTR)"GetCapture()",
  66.              MB_OK);
  67.   ReleaseCapture();
  68.   return 0;
  69. }
  70.