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

  1. /*
  2.  *
  3.  *  clipown.c
  4.  *  
  5.  *  This program demonstrates the use of the GetClipboardOwner functions.
  6.  *  This function retrieves the window handle of the current ower of clip-
  7.  *  board.
  8.  *  
  9.  */
  10.  
  11. #include <windows.h>
  12.  
  13. long    FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
  14.  
  15. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  16. HANDLE     hInstance, hPrevInstance;
  17. LPSTR      lpszCmdLine;
  18. int        cmdShow;
  19.   {
  20.   HWND     hWnd;
  21.   WNDCLASS rClass;
  22.   MSG      msg;
  23.   HMENU    hMenu;
  24.  
  25.   if (!hPrevInstance)
  26.     {
  27.     rClass.style         = CS_HREDRAW | CS_VREDRAW;
  28.     rClass.lpfnWndProc   = WndProc;
  29.     rClass.cbClsExtra    = 0;
  30.     rClass.cbWndExtra    = 0;
  31.     rClass.hInstance     = hInstance;
  32.     rClass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  33.     rClass.hIcon         = LoadIcon (hInstance, IDI_APPLICATION);
  34.     rClass.hbrBackground = GetStockObject (WHITE_BRUSH);
  35.     rClass.lpszMenuName  = NULL;
  36.     rClass.lpszClassName = "clipown";
  37.  
  38.     if (!RegisterClass (&rClass))
  39.       return FALSE;
  40.     }
  41.   hMenu = CreateMenu ();
  42.   ChangeMenu (hMenu, NULL, (LPSTR)"Clipboard Owner", 100, MF_APPEND);
  43.  
  44.   hWnd = CreateWindow ("clipown",
  45.                       "GetClipboardOwner",
  46.                       WS_OVERLAPPEDWINDOW,
  47.                       CW_USEDEFAULT,
  48.                       0,
  49.                       CW_USEDEFAULT,
  50.                       0,
  51.                       NULL,
  52.                       hMenu,
  53.                       hInstance,
  54.                       NULL);
  55.  
  56.   ShowWindow (hWnd, cmdShow);
  57.   UpdateWindow (hWnd);
  58.  
  59.   while (GetMessage (&msg, NULL, 0, 0))
  60.     {
  61.     TranslateMessage (&msg);
  62.     DispatchMessage (&msg);
  63.     }
  64.   return (msg.wParam);
  65.   }
  66.  
  67.  
  68. long    FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  69. HWND     hWnd;
  70. unsigned    iMessage;
  71. WORD     wParam;
  72. LONG     lParam;
  73.   {
  74.   HWND  hClipWnd;
  75.  
  76.   switch (iMessage)
  77.     {
  78.     case WM_COMMAND:
  79.       if (wParam == 100)
  80.         {
  81.         MessageBox (NULL, (LPSTR)"Getting clipboard owner",
  82.                     (LPSTR)"GetClipboardOwner", MB_OK);
  83.         hClipWnd = GetClipboardOwner ();
  84.         if (hClipWnd)
  85.           MessageBox (NULL, (LPSTR)"Clipboard has an owner",
  86.                      (LPSTR)"GetClipboardOwner", MB_OK);
  87.         else
  88.           MessageBox (NULL, (LPSTR)"Clipboard does not has an owner",
  89.                      (LPSTR)"GetClipboardOwner", MB_OK);
  90.         }
  91.       break;
  92.  
  93.     case WM_DESTROY:
  94.       PostQuitMessage (0);
  95.       break;
  96.  
  97.     default:
  98.       return (DefWindowProc (hWnd, iMessage, wParam, lParam));
  99.     }
  100.   return (0L);
  101.   }
  102.