home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / clipbord / clipreg.c < prev    next >
C/C++ Source or Header  |  1988-08-10  |  5KB  |  165 lines

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