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

  1. /*
  2.  *   This program demonstrates the use of the IsClipboardFormatAvailable
  3.  *   function. IsClipboardFormatAvailable checks to see if the given
  4.  *   data format is available in the clipboard. In this sample application,
  5.  *   the format checked for in the clipboard is CF_BITMAP. IsClipboardFormat-
  6.  *   Available is called from WinMain in this sample application. To test
  7.  *   the function, bring up Paint and this application at the same time.
  8.  *   If you cut anything from Paint, it goes to the clipboard and IsClipboard-
  9.  *   FormatAvailable should return TRUE. If there is no bitmap in the clipboard
  10.  *   then IsClipBoardFormatAvailable should return FALSE. Using Paint, once
  11.  *   you have put a bitmap in the clipboard, there will be a bitmap format
  12.  *   in the clipboard until your windows session is ended.
  13.  */
  14.  
  15. #include <windows.h>
  16.  
  17. long    FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
  18.  
  19. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  20. HANDLE    hInstance, hPrevInstance;
  21. LPSTR     lpszCmdLine;
  22. int       cmdShow;
  23.   {
  24.   HWND      hWnd;
  25.   WNDCLASS  wndclass;
  26.   MSG       msg;
  27.   HMENU     hMenu;
  28.  
  29.   if (!hPrevInstance)
  30.     {
  31.     wndclass.style         = CS_HREDRAW | CS_VREDRAW;
  32.     wndclass.lpfnWndProc   = WndProc;
  33.     wndclass.cbClsExtra    = 0;
  34.     wndclass.cbWndExtra    = 0;
  35.     wndclass.hInstance     = hInstance;
  36.     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
  37.     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  38.     wndclass.hbrBackground = GetStockObject (WHITE_BRUSH);
  39.     wndclass.lpszMenuName  = NULL;
  40.     wndclass.lpszClassName = "CLIPFORM";
  41.  
  42.     if (!RegisterClass (&wndclass))
  43.       return FALSE;
  44.     }
  45.   hMenu = CreateMenu ();
  46.   ChangeMenu (hMenu, NULL, (LPSTR)"Format", 100, MF_APPEND);
  47.  
  48.   hWnd = CreateWindow ("CLIPFORM",
  49.                       "IsClipboardFormatAvailable",
  50.                       WS_OVERLAPPEDWINDOW,
  51.                       CW_USEDEFAULT,
  52.                       0,
  53.                       CW_USEDEFAULT,
  54.                       0,
  55.                       NULL,
  56.                       hMenu,
  57.                       hInstance,
  58.                       NULL);
  59.  
  60.   ShowWindow (hWnd, cmdShow);
  61.   UpdateWindow (hWnd);
  62.  
  63.   while (GetMessage (&msg, NULL, 0, 0))
  64.     {
  65.     TranslateMessage (&msg);
  66.     DispatchMessage (&msg);
  67.     }
  68.   return (int)msg.wParam;
  69.   }
  70.  
  71. long    FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  72. HWND     hWnd;
  73. unsigned iMessage;
  74. WORD     wParam;
  75. LONG     lParam;
  76.   {
  77.   BOOL  bFormat;
  78.  
  79.   switch (iMessage)
  80.     {
  81.     case WM_COMMAND:
  82.       if (wParam == 100)
  83.         {
  84.         bFormat = IsClipboardFormatAvailable (CF_BITMAP);
  85.         if (bFormat)
  86.           MessageBox (hWnd, (LPSTR)"There IS a bitmap format available",
  87.                      (LPSTR)"IsClipboardFormatAvailable", MB_OK);
  88.         else
  89.           MessageBox (hWnd, (LPSTR)"There is NOT a bitmap format available",
  90.                      (LPSTR)"IsClipboardFormatAvailable", MB_OK);
  91.         }
  92.       break;
  93.  
  94.     case WM_DESTROY:
  95.       PostQuitMessage (0);
  96.       break;
  97.  
  98.     default:
  99.       return DefWindowProc (hWnd, iMessage, wParam, lParam);
  100.     }
  101.   return (0L);
  102.   }
  103.