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

  1. /*
  2.  *  This program demonstrates the use of ChangeClipboardChain function.
  3.  *  This funtion removes the window specified by a handle from the chain
  4.  *  of clipboard viewers and makes the window next in the viewer chain the
  5.  *  descendent of the removing window's ancestor.
  6.  */
  7.  
  8. #include <windows.h>
  9.  
  10. long    FAR PASCAL WndProc (HANDLE, unsigned, WORD, LONG);
  11.  
  12. static char    szAppName[] = "clipchan";
  13. static char    szFuncName[] = "ChangeClipboardChain";
  14.  
  15. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  16. HANDLE hInstance;
  17. HANDLE hPrevInstance;
  18. LPSTR  lpszCmdLine;
  19. int    cmdShow;
  20.   {
  21.   WNDCLASS rClass;
  22.   HWND     hWnd;
  23.   MSG      msg;
  24.   HMENU    hMenu;
  25.  
  26.   if (!hPrevInstance)
  27.     {
  28.     rClass.style         = CS_HREDRAW | CS_VREDRAW;
  29.     rClass.lpfnWndProc   = WndProc;
  30.     rClass.cbClsExtra    = 0;
  31.     rClass.cbWndExtra    = 0;
  32.     rClass.hInstance     = hInstance;
  33.     rClass.hIcon         = LoadIcon (hInstance, IDI_APPLICATION);
  34.     rClass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  35.     rClass.hbrBackground = GetStockObject (WHITE_BRUSH);
  36.     rClass.lpszMenuName  = (LPSTR) NULL;
  37.     rClass.lpszClassName = (LPSTR) szAppName;
  38.  
  39.     if (!RegisterClass (&rClass))
  40.       return FALSE;
  41.     }
  42.  
  43.   hMenu = CreateMenu ();
  44.   ChangeMenu (hMenu, NULL, (LPSTR)"Clipboard Chain", 100, MF_APPEND);
  45.  
  46.   hWnd = CreateWindow (szAppName,            /* window class name       */
  47.                       szFuncName,                 /* window caption          */
  48.                       WS_OVERLAPPEDWINDOW,        /* window style            */
  49.                       CW_USEDEFAULT,              /* initial x position      */
  50.                       0,                          /* initial y position      */
  51.                       CW_USEDEFAULT,              /* initial x size          */
  52.                       0,                          /* initial y size          */
  53.                       NULL,                       /* parent window handle    */
  54.                       hMenu,                      /* window menu handle      */
  55.                       hInstance,                  /* program instance handle */
  56.                       NULL);                     /* create parameters       */
  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. long    FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  70. HWND        hWnd;
  71. unsigned    iMessage;
  72. WORD        wParam;
  73. LONG        lParam;
  74.   {
  75.   HMENU  hMenu;
  76.   HWND   hWndStatic;
  77.   BOOL   bRemoved;
  78.  
  79.   switch (iMessage)
  80.     {
  81.     case WM_COMMAND:
  82.       if (wParam == 100)
  83.         {
  84.         hWndStatic = SetClipboardViewer (hWnd);
  85.         MessageBox (NULL,
  86.             (LPSTR)"Removing current window from the viewer chain",
  87.             (LPSTR)szFuncName, MB_OK);
  88.         bRemoved = ChangeClipboardChain (hWnd, hWndStatic);
  89.         if (bRemoved != 0)
  90.           MessageBox (NULL,
  91.               (LPSTR)"Current window removed from the viewer chain",
  92.               (LPSTR)szFuncName, MB_OK);
  93.         else
  94.           MessageBox (NULL,
  95.               (LPSTR)"Current window not removed from viewer chain",
  96.               (LPSTR)szFuncName, MB_OK);
  97.         }
  98.       break;
  99.  
  100.     case WM_DESTROY:
  101.       PostQuitMessage (0);
  102.       break;
  103.  
  104.     default:
  105.       return (DefWindowProc (hWnd, iMessage, wParam, lParam));
  106.     }
  107.   return (0L);
  108.   }
  109.