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

  1. /*
  2.  *
  3.  *  GetInstanceData
  4.  *  
  5.  *  This program demonstrates the use of the function GetInstanceData.
  6.  *  This function copies data from a previous intance of an application
  7.  *  into the data area of the current instance.
  8.  *  
  9.  *  Other references: numerous apps. with SDK
  10.  *
  11.  *  Windows Version 2.0 function demonstration application
  12.  *
  13.  */
  14.  
  15. #include <windows.h>
  16.  
  17. LPSTR far PASCAL lstrcpy( LPSTR, LPSTR );
  18.  
  19. static HANDLE hWnd;
  20.  
  21. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  22. HANDLE hInstance, hPrevInstance;
  23. LPSTR  lpszCmdLine;
  24. int    cmdShow;
  25. {
  26.   int nBytes = 0;
  27.   char szAppName[25];
  28.   char szFuncName[25];
  29.   char szBuffer[80];
  30.   
  31.   lstrcpy ( (LPSTR) szAppName, (LPSTR) "ginstdat" );
  32.  
  33.   lstrcpy ( (LPSTR) szFuncName, (LPSTR) "GetIntanceData" );
  34.  
  35.   if ( !hPrevInstance )
  36.      {
  37.      WNDCLASS rClass;
  38.  
  39.      rClass.lpszClassName = ( LPSTR ) szAppName;
  40.      rClass.hInstance     = hInstance;
  41.      rClass.lpfnWndProc   = DefWindowProc;
  42.      rClass.hCursor       = LoadCursor ( NULL , IDC_ARROW );
  43.      rClass.hIcon         = LoadIcon ( hInstance, IDI_APPLICATION );
  44.      rClass.lpszMenuName  = ( LPSTR ) NULL;
  45.      rClass.hbrBackground = GetStockObject ( WHITE_BRUSH );
  46.      rClass.style         = CS_HREDRAW | CS_VREDRAW;
  47.      rClass.cbClsExtra    = 0;
  48.      rClass.cbWndExtra    = 0;
  49.    
  50.      RegisterClass ( ( LPWNDCLASS ) &rClass );
  51.      }
  52.   else
  53.      {
  54.      MessageBox (NULL, (LPSTR)"Getting instance data", 
  55.        (LPSTR)szFuncName, MB_OK );
  56.  
  57.      nBytes = GetInstanceData( hPrevInstance, (PSTR)szAppName, 25 );
  58.  
  59.      sprintf ( szBuffer, "%s%d", "The number of bytes copied is ", nBytes );
  60.  
  61.      MessageBox ( NULL, (LPSTR)szBuffer, (LPSTR)szFuncName, MB_OK );
  62.      }
  63.  
  64.   hWnd = CreateWindow ( ( LPSTR ) szAppName, ( LPSTR ) szFuncName,
  65.                       WS_OVERLAPPEDWINDOW,
  66.                       CW_USEDEFAULT, CW_USEDEFAULT,
  67.                       CW_USEDEFAULT, CW_USEDEFAULT,
  68.                       ( HWND ) NULL, ( HMENU ) NULL,
  69.                       ( HANDLE ) hInstance, ( LPSTR ) NULL );
  70.  
  71.   ShowWindow ( hWnd , cmdShow );
  72.  
  73.   if ( nBytes == 0 )
  74.   MessageBox ( NULL, (LPSTR)"Start another instance before \npushing ok", 
  75.       (LPSTR)szFuncName, MB_OK );
  76.      
  77.   return 0;
  78. }
  79.