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

  1. /*
  2.  *  Function Name:   EscapeCommFunction
  3.  *  Program Name:    esccomf.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 carry out the extended function given
  10.  *   with LPT2.
  11.  */
  12.  
  13. #include "windows.h"
  14.  
  15. long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  16.  
  17. /***********************************************************************/
  18.  
  19. void CALL_EscapeCommFunction(hWnd, hDC)
  20. HWND hWnd;
  21. HDC hDC;
  22. {
  23.   int     nCid, nResult;
  24.  
  25.   nCid = OpenComm ((LPSTR)"LPT2", 20, 20);
  26.                                           /*  function demonstrated  */
  27.   nResult = EscapeCommFunction (nCid, SETXOFF);
  28.  
  29.   if (nResult != 0)
  30.        MessageBox (hWnd, (LPSTR)"EscapeCommFunction failed",
  31.                   (LPSTR)"ERROR",MB_ICONHAND);
  32.   else
  33.       TextOut(hDC, 10, 10, (LPSTR)"EscapeCommFunction successful", 29);
  34.  
  35.   CloseComm (nCid);
  36.  
  37.   return;
  38. }
  39.  
  40. /**************************************************************************/
  41.  
  42. /* Procedure called when the application is loaded for the first time */
  43. BOOL WinInit( hInstance )
  44. HANDLE hInstance;
  45. {
  46.     WNDCLASS   wcClass;
  47.  
  48.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  49.     wcClass.lpfnWndProc    = WndProc;
  50.     wcClass.cbClsExtra     =0;
  51.     wcClass.cbWndExtra     =0;
  52.     wcClass.hInstance      = hInstance;
  53.     wcClass.hIcon          = LoadIcon( hInstance,NULL );
  54.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  55.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  56.     wcClass.lpszMenuName   = (LPSTR)NULL;
  57.     wcClass.lpszClassName  = (LPSTR)"EscapeCommFunction";
  58.  
  59.     if (!RegisterClass( (LPWNDCLASS)&wcClass ) )
  60.         /* Initialization failed.
  61.          * Windows will automatically deallocate all allocated memory.
  62.          */
  63.         return FALSE;
  64.  
  65.     return TRUE;        /* Initialization succeeded */
  66. }
  67.  
  68.  
  69. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  70. HANDLE hInstance, hPrevInstance;
  71. LPSTR lpszCmdLine;
  72. int cmdShow;
  73. {
  74.     MSG   msg;
  75.     HWND  hWnd;
  76.  
  77.     if (!hPrevInstance)
  78.         {
  79.         /* Call initialization procedure if this is the first instance */
  80.         if (!WinInit( hInstance ))
  81.             return FALSE;
  82.         }
  83.  
  84.     hWnd = CreateWindow((LPSTR)"EscapeCommFunction",
  85.                         (LPSTR)"EscapeCommFunction()",
  86.                         WS_OVERLAPPEDWINDOW,
  87.                         CW_USEDEFAULT,
  88.                         CW_USEDEFAULT,
  89.                         CW_USEDEFAULT,
  90.                         CW_USEDEFAULT,
  91.                         (HWND)NULL,        /* no parent */
  92.                         (HMENU)NULL,       /* use class menu */
  93.                         (HANDLE)hInstance, /* handle to window instance */
  94.                         (LPSTR)NULL        /* no params to pass on */
  95.                         );
  96.  
  97.     /* Make window visible according to the way the app is activated */
  98.     ShowWindow( hWnd, cmdShow );
  99.     UpdateWindow( hWnd );
  100.  
  101.     /* Polling messages from event queue */
  102.     while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  103.         {
  104.         TranslateMessage((LPMSG)&msg);
  105.         DispatchMessage((LPMSG)&msg);
  106.         }
  107.  
  108.     return (int)msg.wParam;
  109. }
  110.  
  111. /* Procedures which make up the window class. */
  112. long FAR PASCAL WndProc( hWnd, message, wParam, lParam )
  113. HWND hWnd;
  114. unsigned message;
  115. WORD wParam;
  116. LONG lParam;
  117. {
  118.     PAINTSTRUCT ps;
  119.  
  120.     switch (message)
  121.     {
  122.  
  123.     case WM_PAINT:
  124.         BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
  125.         CALL_EscapeCommFunction(hWnd, ps.hdc);
  126.         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
  127.         break;
  128.  
  129.     case WM_DESTROY:
  130.         PostQuitMessage( 0 );
  131.         break;
  132.  
  133.     default:
  134.         return DefWindowProc( hWnd, message, wParam, lParam );
  135.         break;
  136.     }
  137.     return(0L);
  138. }
  139.