home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / windows / c / wmseri / wmserial.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-05  |  4.6 KB  |  195 lines

  1. //
  2. //     W M S E R I A L - Windows Modem Example
  3. //
  4. // This is only part of a multiple source project.  To build the
  5. // executable please use the makefile provided or construct
  6. // a project file containing the files and settings listed in
  7. // PROJECT.TXT.
  8. //
  9. // Remember to modify the directories to reflect your configuration.
  10. //
  11. //                                                     - J A A
  12.  
  13. // WMSERIAL.C
  14.  
  15. #define _MAIN
  16. #include <windows.h>
  17. #include "wmserial.h"
  18.  
  19.  
  20. char szAppName[] = "WMSERIAL";
  21.  
  22. #pragma argsused
  23.  
  24. int PASCAL WinMain( HANDLE hInstance, HANDLE hPrevious,
  25.                    LPSTR lpszCmdLine, int nCmdShow )
  26.    {
  27.    MSG msg;
  28.    HWND hWnd;
  29.  
  30.    hWnd = InitWinApp( hInstance,hPrevious,lpszCmdLine,nCmdShow );
  31.    if (!hWnd)
  32.        {
  33.        MessageBeep( MB_ICONEXCLAMATION );
  34.        MessageBox( NULL,"Could not create main window.","Example Windows Terminal",MB_ICONSTOP );
  35.        return FALSE;
  36.        }
  37.  
  38.  
  39.    while (GetMessage(&msg,NULL,0,0))
  40.        {
  41.        TranslateMessage(&msg);
  42.        DispatchMessage(&msg);
  43.        }
  44.  
  45.    return msg.wParam;
  46.    }
  47.  
  48.  
  49.  
  50. #pragma argsused
  51.  
  52. HWND InitWinApp( HANDLE hInstance, HANDLE hPrevious,
  53.                LPSTR lpszCmdLine, int nCmdShow )
  54.    {
  55.    HWND hwnd;
  56.    WNDCLASS wndclass;
  57.                            
  58.    if ( !hPrevious )
  59.        {                     
  60.        wndclass.style       = CS_HREDRAW | CS_VREDRAW;
  61.        wndclass.lpfnWndProc = WndProc;
  62.        wndclass.cbClsExtra  = 0;
  63.        wndclass.cbWndExtra  = 0;
  64.        wndclass.hInstance   = hInstance;
  65.        wndclass.hIcon       = LoadIcon( NULL, IDI_APPLICATION );
  66.        wndclass.hCursor     = LoadCursor( NULL, IDC_ARROW );
  67.        wndclass.hbrBackground = GetStockObject( WHITE_BRUSH );
  68.        wndclass.lpszMenuName = szAppName;
  69.        wndclass.lpszClassName = szAppName;
  70.  
  71.        if ( !RegisterClass ( &wndclass ) ) return NULL;
  72.        }
  73.  
  74.    hwnd = CreateWindow( szAppName,"Example Windows Terminal",
  75.                        WS_OVERLAPPED|WS_VISIBLE|WS_MAXIMIZE,
  76.                        CW_USEDEFAULT, CW_USEDEFAULT,
  77.                        CW_USEDEFAULT, CW_USEDEFAULT,
  78.                        NULL, NULL, hInstance, NULL );
  79.  
  80.    if (!hwnd) return NULL;
  81.  
  82.    ShowWindow( hwnd, SW_SHOWMAXIMIZED );
  83.    UpdateWindow(hwnd);            
  84.  
  85.    return hwnd;
  86.    }
  87.  
  88.  
  89.  
  90.  
  91. LRESULT CALLBACK _export WndProc ( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
  92.    {
  93.    char szTemp[3];
  94.  
  95.    switch( message ) 
  96.        {
  97.  
  98.        case WM_CREATE:
  99.            TTYInit( hWnd );
  100.            PostMessage( hWnd,WM_CONNECT,0,0L );
  101.            return 0;
  102.  
  103.  
  104.  
  105.        case WM_CONNECT:
  106.            if ( !Connect( hWnd ) )
  107.                PostMessage( hWnd,WM_CLOSE,0,0L );
  108.            return 0;
  109.  
  110.  
  111.  
  112.        case WM_COMMNOTIFY:
  113.            ProcessCommNotify( hWnd, wParam, LOWORD( lParam ));
  114.            CheckComPort( wParam,NULL );
  115.            return 0;
  116.  
  117.  
  118.  
  119.        case WM_COMMAND:
  120.            switch ( wParam )
  121.                {
  122.                case USER_DISCONNECT:
  123.                    PostMessage( hWnd, WM_CLOSE, 0, 0L );
  124.                    break;
  125.                }
  126.            return 0;
  127.  
  128.  
  129.                    
  130.        case WM_SETFOCUS:
  131.            TTYSetFocus();
  132.            return 0;
  133.  
  134.  
  135.  
  136.        case WM_KILLFOCUS:
  137.            HideCaret( hWnd );
  138.            DestroyCaret();
  139.            return 0;
  140.  
  141.  
  142.  
  143.        case WM_KEYDOWN:
  144.            switch (wParam)
  145.                {
  146.                case VK_RETURN:
  147.                    WriteComPort( nActiveComPort,"\r",1 );
  148.                    CheckComPort( nActiveComPort,NULL );
  149.                    if (bEcho)
  150.                        TTYWriteScreen("\r\n");
  151.                    return 0;
  152.  
  153.                default:
  154.                    return( DefWindowProc( hWnd, message, wParam, lParam ) );
  155.                }
  156.  
  157.  
  158.  
  159.        case WM_CHAR:
  160.            // process keystrokes
  161.            switch( wParam ) 
  162.                {
  163.                case '\r':
  164.                case '\n':
  165.                    break;
  166.  
  167.                default:
  168.                    szTemp[0] = (char)wParam;
  169.                    szTemp[1] = '\0';
  170.                    WriteComPort( nActiveComPort,szTemp,1 );
  171.                    CheckComPort( nActiveComPort,NULL );
  172.                    if (bEcho)
  173.                        TTYWriteScreen( szTemp );
  174.                    break;
  175.                }
  176.            return 0;
  177.  
  178.        case WM_CLOSE:
  179.            Disconnect();
  180.            DestroyWindow( hWnd );
  181.            PostQuitMessage( 0 );
  182.            return 0;
  183.  
  184.        default:
  185.            return( DefWindowProc( hWnd, message, wParam, lParam ) );
  186.        }
  187.    }
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.