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

  1. /*
  2.  *
  3.  *  GetClipboardFormatName
  4.  *
  5.  *  clipforn.c, charlesl, v2.00, 29-Dec-1987
  6.  *  
  7.  *  This program demonstrates the use of GetClipboardFormatName function.
  8.  *  This function retrieves from the clipboard the name of the register
  9.  *  format specified by an unsigned short integer. The name is copied to
  10.  *  the buffer pointed to by long pointer.
  11.  *  
  12.  *  Other references: CFClip.c
  13.  *  
  14.  *  Microsoft Product Support Services
  15.  *  Windows Version 2.0 function demonstration application
  16.  *  Copyright (c) Microsoft 1987
  17.  *
  18.  */
  19.  
  20. /*************************************************************************/
  21. /*                           INCLUDE FILES                               */
  22. /*************************************************************************/
  23.  
  24. #include <windows.h>
  25.  
  26. /*************************************************************************/
  27. /*                        STRUCTURE DEFINTIONS                           */
  28. /*************************************************************************/
  29.  
  30. typedef struct
  31. {
  32.    int nDummy;
  33. }
  34. SETUPDATA;
  35.  
  36. /*************************************************************************/
  37. /*                         GLOBAL VARIABLES                              */
  38. /*************************************************************************/
  39.  
  40. static SETUPDATA strSetUpData;
  41. static HANDLE hInst;
  42. static char szFileName[] = "clipforn";
  43. static char szFuncName[] = "GetClipboardFormatName";
  44.  
  45. /*************************************************************************/
  46. /*                       FORWARD REFERENCES                              */
  47. /*************************************************************************/
  48.  
  49. long FAR PASCAL WindowProc ( HANDLE , unsigned , WORD , LONG );
  50.  
  51. /*************************************************************************/
  52. /*                         MAIN PROCEDURE                                */
  53. /*************************************************************************/
  54.  
  55. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  56. HANDLE hInstance, hPrevInstance;
  57. LPSTR  lpszCmdLine;
  58. int    cmdShow;
  59. {
  60.   MSG  msg;
  61.  
  62.   WindowInit (hInstance, hPrevInstance, cmdShow );
  63.  
  64.   while ( GetMessage((LPMSG)&msg, NULL, 0 , 0 ))
  65.     {
  66.     TranslateMessage((LPMSG)&msg);
  67.     DispatchMessage((LPMSG)&msg);
  68.     }
  69.   exit(msg.wParam);
  70. }
  71.  
  72. /*************************************************************************/
  73. /*                      INITIALIZATION                                   */
  74. /*************************************************************************/
  75.  
  76. BOOL WindowInit (hInstance , hPrevInstance , cmdShow)
  77. HANDLE hInstance, hPrevInstance;
  78. int cmdShow;
  79. {
  80.   HWND  hWnd;
  81.  
  82.   if ( !hPrevInstance )
  83.      {
  84.      WNDCLASS rClass;
  85.  
  86.      rClass.style         = CS_HREDRAW | CS_VREDRAW;
  87.      rClass.lpfnWndProc   = WindowProc;
  88.      rClass.cbClsExtra    = 0;
  89.      rClass.cbWndExtra    = 0;
  90.      rClass.hInstance     = hInstance;
  91.      rClass.hCursor       = LoadCursor ( NULL , IDC_ARROW );
  92.      rClass.hIcon         = LoadIcon ( hInstance, IDI_APPLICATION );
  93.      rClass.hbrBackground = GetStockObject ( WHITE_BRUSH );
  94.      rClass.lpszMenuName  = (LPSTR) NULL;
  95.      rClass.lpszClassName = (LPSTR) szFileName;
  96.    
  97.      RegisterClass ( ( LPWNDCLASS ) &rClass );
  98.      }
  99.   else
  100.      GetInstanceData ( hPrevInstance, (PSTR) &strSetUpData,
  101.         sizeof ( SETUPDATA ) );
  102.  
  103.   hInst = hInstance;
  104.  
  105.   hWnd = CreateWindow ( (LPSTR) szFileName, (LPSTR) szFuncName,
  106.                       WS_OVERLAPPEDWINDOW,
  107.                       CW_USEDEFAULT, CW_USEDEFAULT,
  108.                       CW_USEDEFAULT, CW_USEDEFAULT,
  109.                       (HWND) NULL, (HMENU) NULL,
  110.                       (HANDLE) hInstance, (LPSTR) NULL );
  111.  
  112.   ShowWindow ( hWnd , cmdShow );
  113.   UpdateWindow (hWnd);
  114.  
  115.   return TRUE;
  116. }
  117.  
  118. /*************************************************************************/
  119. /*                 WINDOW PROCEDURE - PROCESS MESSAGES                   */
  120. /*************************************************************************/
  121.  
  122. long FAR PASCAL WindowProc (hWnd , message , wParam , lParam)
  123. HWND        hWnd;
  124. unsigned    message;
  125. WORD        wParam;
  126. LONG        lParam;
  127. {
  128.     PAINTSTRUCT ps;
  129.  
  130.     switch (message)
  131.     {
  132.  
  133.     case WM_PAINT:
  134.         BeginPaint ( hWnd, (LPPAINTSTRUCT)&ps );
  135.         FunctionDemonstrated ( hWnd );
  136.         EndPaint ( hWnd, (LPPAINTSTRUCT)&ps );
  137.         break;
  138.  
  139.     case WM_DESTROY:
  140.         PostQuitMessage ( 0 );
  141.         break;
  142.  
  143.     default:
  144.         return ( DefWindowProc ( hWnd , message , wParam , lParam ) );
  145.         break;
  146.     }
  147.   return ( 0L );
  148. }
  149.  
  150. /*************************************************************************/
  151. /*              FUNCTION DEMONSTRATED HERE - LOOK HERE                   */
  152. /*************************************************************************/
  153.  
  154. FunctionDemonstrated ( hWnd )
  155. HWND hWnd;
  156. {
  157.   WORD wFormat;
  158.   int nCopied;
  159.   LPSTR lpFormatName;
  160.  
  161.   MessageBox (NULL, (LPSTR)"Getting clipboard format name",
  162.      (LPSTR)szFuncName, MB_OK);
  163.  
  164.   wFormat = RegisterClipboardFormat ( (LPSTR)"format_name" );
  165.   nCopied = GetClipboardFormatName ( wFormat, lpFormatName, 20 );
  166.   
  167.   if ( nCopied != 0 )
  168.       MessageBox (NULL, (LPSTR)"Format name gotten", (LPSTR)szFuncName,
  169.          MB_OK);
  170.   else
  171.       MessageBox (NULL, (LPSTR)"Format does not exits", (LPSTR)szFuncName,
  172.          MB_OK);
  173.  
  174.   return TRUE;
  175. }
  176.  
  177.