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

  1. /*
  2.  *  This program demonstrates the use of CountClipboardFormats function.
  3.  *  This function retieves a count of the number of formats that the clip-
  4.  *  board can render.
  5.  */
  6.  
  7. #include <windows.h>
  8. #include <stdio.h>
  9.  
  10. static char    szAppName[] = "clipcoun";
  11. static char    szFuncName[] = "CountClipboardFormats";
  12.  
  13. long    FAR PASCAL WndProc (HANDLE, unsigned, WORD, LONG);
  14.  
  15. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  16. HANDLE    hInstance, hPrevInstance;
  17. LPSTR     lpszCmdLine;
  18. int       cmdShow;
  19.   {
  20.   HWND     hWnd;
  21.   WNDCLASS rClass;
  22.   MSG      msg;
  23.  
  24.   if (!hPrevInstance)
  25.     {
  26.     rClass.style         = CS_HREDRAW | CS_VREDRAW;
  27.     rClass.lpfnWndProc   = WndProc;
  28.     rClass.cbClsExtra    = 0;
  29.     rClass.cbWndExtra    = 0;
  30.     rClass.hInstance     = hInstance;
  31.     rClass.hIcon         = LoadIcon (hInstance, IDI_APPLICATION);
  32.     rClass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  33.     rClass.hbrBackground = GetStockObject (WHITE_BRUSH);
  34.     rClass.lpszMenuName  = (LPSTR) NULL;
  35.     rClass.lpszClassName = (LPSTR) szAppName;
  36.  
  37.     if (!RegisterClass (&rClass))
  38.       return FALSE;
  39.     }
  40.  
  41.   hWnd = CreateWindow (szAppName,
  42.                       szFuncName,
  43.                       WS_OVERLAPPEDWINDOW,
  44.                       CW_USEDEFAULT,
  45.                       0,
  46.                       CW_USEDEFAULT,
  47.                       0,
  48.                       NULL,
  49.                       NULL,
  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. long    FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  65. HWND        hWnd;
  66. unsigned    iMessage;
  67. WORD        wParam;
  68. LONG        lParam;
  69.   {
  70.   HMENU  hMenu;
  71.   int    nCount;
  72.   char    szBuff[80];
  73.  
  74.   switch (iMessage)
  75.     {
  76.     case WM_CREATE:
  77.       hMenu = CreateMenu ();
  78.       ChangeMenu (hMenu, NULL, (LPSTR)"Clipboard Formats", 100, MF_APPEND);
  79.       SetMenu (hWnd, hMenu);
  80.       break;
  81.  
  82.     case WM_COMMAND:
  83.       if (wParam == 100)
  84.         {
  85.         MessageBox (NULL, (LPSTR)"Counting clipboard formats",
  86.                    (LPSTR)szFuncName, MB_OK);
  87.         nCount = CountClipboardFormats ();
  88.         sprintf (szBuff, "There is %d clipboard formats right now.", nCount);
  89.         MessageBox (NULL, (LPSTR)szBuff, (LPSTR)szFuncName, MB_OK);
  90.         }
  91.       break;
  92.  
  93.     case WM_DESTROY:
  94.       PostQuitMessage (0);
  95.       break;
  96.     default:
  97.       return (DefWindowProc (hWnd, iMessage, wParam, lParam));
  98.     }
  99.   return (0L);
  100.   }
  101.