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

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