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

  1. /*
  2.  *  Function Name:   Escape
  3.  *  Program Name:    esc.c
  4.  *  SDK Version:         2.03
  5.  *  Runtime Version:     2.03
  6.  *  Microsoft C Version: 5.1
  7.  *
  8.  *  Description:
  9.  *   The program below will retrieve and display the physical page size
  10.  *   for the installed printer.
  11.  */
  12.  
  13. #include "windows.h"
  14. #include "stdio.h"
  15.  
  16. long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  17.  
  18. /***********************************************************************/
  19.  
  20. void CALL_Escape(hWnd, hDC)
  21. HWND hWnd;
  22. HDC hDC;
  23. {
  24.   HDC    hDCDevice;
  25.   char   szDevice[81], szstring[80];
  26.   PSTR   spDeviceName, spFileName, spPort, strtok();
  27.   int    PageCnt, Pages, nResult, nLength;
  28.   POINT  ptPageSize;
  29.  
  30.   GetProfileString ("windows", "device", "", szDevice, 81);
  31.   spDeviceName = strtok (szDevice, ",");
  32.   spFileName   = strtok (NULL, ", ");
  33.   spPort       = strtok (NULL, ", ");
  34.   hDCDevice = CreateDC(spFileName, szDevice, spPort, 0);
  35.                                                /* function demonstrated  */
  36.   nResult = Escape (hDCDevice, GETPHYSPAGESIZE, 0, 0, (LPSTR)&ptPageSize);
  37.  
  38.   if (nResult < 0)
  39.   {
  40.     MessageBox(hWnd,(LPSTR)"Escape failed",(LPSTR)"ERROR",MB_ICONHAND);
  41.     return;
  42.   }
  43.   nLength = sprintf(szstring, "Physical page size for %s is  x=%d,  y=%d",
  44.                                spDeviceName, ptPageSize.x, ptPageSize.y);
  45.   TextOut (hDC, 10, 10, szstring, nLength);
  46.  
  47.   return;
  48. }
  49.  
  50. /**************************************************************************/
  51.  
  52. /* Procedure called when the application is loaded for the first time */
  53. BOOL WinInit( hInstance )
  54. HANDLE hInstance;
  55. {
  56.     WNDCLASS   wcClass;
  57.  
  58.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  59.     wcClass.lpfnWndProc    = WndProc;
  60.     wcClass.cbClsExtra     =0;
  61.     wcClass.cbWndExtra     =0;
  62.     wcClass.hInstance      = hInstance;
  63.     wcClass.hIcon          = LoadIcon( hInstance,NULL );
  64.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  65.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  66.     wcClass.lpszMenuName   = (LPSTR)NULL;
  67.     wcClass.lpszClassName  = (LPSTR)"Escape";
  68.  
  69.     if (!RegisterClass( (LPWNDCLASS)&wcClass ) )
  70.         /* Initialization failed.
  71.          * Windows will automatically deallocate all allocated memory.
  72.          */
  73.         return FALSE;
  74.  
  75.     return TRUE;        /* Initialization succeeded */
  76. }
  77.  
  78.  
  79. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  80. HANDLE hInstance, hPrevInstance;
  81. LPSTR lpszCmdLine;
  82. int cmdShow;
  83. {
  84.     MSG   msg;
  85.     HWND  hWnd;
  86.  
  87.     if (!hPrevInstance)
  88.         {
  89.         /* Call initialization procedure if this is the first instance */
  90.         if (!WinInit( hInstance ))
  91.             return FALSE;
  92.         }
  93.  
  94.     hWnd = CreateWindow((LPSTR)"Escape",
  95.                         (LPSTR)"Escape()",
  96.                         WS_OVERLAPPEDWINDOW,
  97.                         CW_USEDEFAULT,
  98.                         CW_USEDEFAULT,
  99.                         CW_USEDEFAULT,
  100.                         CW_USEDEFAULT,
  101.                         (HWND)NULL,        /* no parent */
  102.                         (HMENU)NULL,       /* use class menu */
  103.                         (HANDLE)hInstance, /* handle to window instance */
  104.                         (LPSTR)NULL        /* no params to pass on */
  105.                         );
  106.  
  107.     /* Make window visible according to the way the app is activated */
  108.     ShowWindow( hWnd, cmdShow );
  109.     UpdateWindow( hWnd );
  110.  
  111.     /* Polling messages from event queue */
  112.     while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  113.         {
  114.         TranslateMessage((LPMSG)&msg);
  115.         DispatchMessage((LPMSG)&msg);
  116.         }
  117.  
  118.     return (int)msg.wParam;
  119. }
  120.  
  121. /* Procedures which make up the window class. */
  122. long FAR PASCAL WndProc( 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.         CALL_Escape(hWnd, ps.hdc);
  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.