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

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