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

  1. /*
  2.  *  This program demonstrates the use of EnumClipboardFormats function.
  3.  *  This function numbers a list of formats and returns the next format in
  4.  *  the list.
  5.  *  
  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.  
  21.   if (!hPrevInstance)
  22.     {
  23.     rClass.style         = CS_HREDRAW | CS_VREDRAW;
  24.     rClass.lpfnWndProc   = WndProc;
  25.     rClass.cbClsExtra    = 0;
  26.     rClass.cbWndExtra    = 0;
  27.     rClass.hInstance     = hInstance;
  28.     rClass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  29.     rClass.hIcon         = LoadIcon (hInstance, IDI_APPLICATION);
  30.     rClass.hbrBackground = GetStockObject (WHITE_BRUSH);
  31.     rClass.lpszMenuName  = NULL;
  32.     rClass.lpszClassName = "clipenum";
  33.  
  34.     if (!RegisterClass (&rClass))
  35.       return FALSE;
  36.     }
  37.  
  38.   hWnd = CreateWindow ("clipenum",            /* window class name       */
  39.                       "EnumClipboardFormats",                 /* window caption          */
  40.                       WS_OVERLAPPEDWINDOW,        /* window style            */
  41.                       CW_USEDEFAULT,              /* initial x position      */
  42.                       0,                          /* initial y position      */
  43.                       CW_USEDEFAULT,              /* initial x size          */
  44.                       0,                          /* initial y size          */
  45.                       NULL,                       /* parent window handle    */
  46.                       NULL,                       /* window menu handle      */
  47.                       hInstance,                  /* program instance handle */
  48.                       NULL);                      /* create parameters       */
  49.  
  50.   ShowWindow (hWnd, cmdShow);
  51.   UpdateWindow (hWnd);
  52.  
  53.   while (GetMessage (&msg, NULL, 0, 0))
  54.     {
  55.     TranslateMessage (&msg);
  56.     DispatchMessage (&msg);
  57.     }
  58.   return (msg.wParam);
  59.   }
  60.  
  61. long    FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  62. HWND     hWnd;
  63. unsigned iMessage;
  64. WORD     wParam;
  65. LONG     lParam;
  66.   {
  67.   HMENU hMenu;
  68.   int    nNextFormat;
  69.  
  70.   switch (iMessage)
  71.     {
  72.     case WM_CREATE:
  73.       hMenu = CreateMenu ();
  74.       ChangeMenu (hMenu, NULL, (LPSTR)"Number Formats", 100, MF_APPEND);
  75.       SetMenu (hWnd, hMenu);
  76.       break;
  77.  
  78.     case WM_COMMAND:
  79.       if (wParam == 100)
  80.         {
  81.         MessageBox (NULL, (LPSTR)"Getting first format in list",
  82.                    (LPSTR)"EnumClipboardFormats", MB_OK);
  83.         nNextFormat = EnumClipboardFormats (0);
  84.         if (nNextFormat == 0)
  85.           MessageBox (NULL, (LPSTR)"First format returned",
  86.                      (LPSTR)"EnumClipboardFormats", MB_OK);
  87.         else
  88.           MessageBox (NULL, (LPSTR)"First format not returned",
  89.                      (LPSTR)"EnumClipboardFormats", 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.