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

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