home *** CD-ROM | disk | FTP | other *** search
/ Windows Shareware GOLD / NuclearComputingVol3No1.cdr / other / f1490 / testapp.c < prev    next >
C/C++ Source or Header  |  1990-12-29  |  6KB  |  271 lines

  1. /*****************************************************************************
  2.  
  3.     testapp.c
  4.  
  5.     Main Program file.
  6.  
  7.     This file contains an example test application for WINPIPE.DLL and
  8.     stdio.exe.
  9.  
  10.     This program's operation is described in winpipe.wri.
  11.  
  12.  
  13. *****************************************************************************/
  14.  
  15. #include <windows.h>
  16. #include "winpipe.h"
  17. #include "testapp.h"
  18.  
  19.  
  20. #define PIPE_IN 10
  21.  
  22. #define toupper(a)  ( ( (a >= 'a') && (a <= 'z') )  ? (a - ('a'-'A')) : a)
  23.  
  24.  
  25. PIPE    Pipe;
  26.  
  27. HANDLE  hThisInstance;
  28. HANDLE  hThisWnd;
  29.  
  30. char szAppName[]="Entry";
  31.  
  32.  
  33. #define DEBUG_STRLEN    120
  34.  
  35. char szDebug[DEBUG_STRLEN];  /*    Place for debug commands    */
  36. static int iDebug=0;
  37.  
  38.  
  39. /*  Quick'n easy dialog routine */
  40.  
  41. BOOL PopupDLG( hParentWnd, lpszTemplate, lpfnDlgProc )
  42. HWND        hParentWnd;
  43. LPSTR       lpszTemplate;
  44. FARPROC     lpfnDlgProc;
  45. {
  46.     BOOL           bResult;
  47.     FARPROC        lpProc;                 
  48.  
  49.     lpProc = MakeProcInstance( lpfnDlgProc, INSTANCE(hParentWnd) );
  50.  
  51.     bResult = DialogBox( INSTANCE(hParentWnd), lpszTemplate, hParentWnd, lpProc );          
  52.  
  53.     FreeProcInstance( lpProc );
  54.  
  55.     return( bResult );
  56.  
  57. }
  58.  
  59. /*  Aboutbox proc   */
  60.  
  61. BOOL FAR PASCAL About(hDlg, message, wParam, lParam)
  62. HWND hDlg;
  63. unsigned message;
  64. WORD wParam;
  65. LONG lParam;
  66. {
  67.     switch (message) {
  68.         case WM_INITDIALOG:
  69.       return (TRUE);
  70.  
  71.         case WM_COMMAND:
  72.             switch(wParam){
  73.                 case IDOK:
  74.                     EndDialog(hDlg, TRUE);
  75.                     break;
  76.  
  77.                 case IDCANCEL:
  78.                     EndDialog(hDlg, TRUE);
  79.                     break;
  80.  
  81.                 default:
  82.                     break;
  83.  
  84.             }
  85.  
  86.     }
  87.     return (FALSE);
  88. }
  89.  
  90.  
  91. /*  See if szString matches szTemplate */
  92.  
  93. match(char *szString, char *szTemplate)
  94. {
  95.     while(*szTemplate){
  96.         if(toupper(*szString) != *szTemplate)
  97.             return(0);
  98.         szString++;
  99.         szTemplate++;
  100.  
  101.     }
  102.  
  103.     return(1);
  104.  
  105. }
  106.  
  107. /*  Parse debugging dialog  */
  108.  
  109. Parse(char *szString)
  110. {
  111.     char buffer[120];
  112.  
  113.     if(match(szString, "WHO:"))
  114.         Wputs("Testapp.exe\n");
  115.  
  116.     if(match(szString, "WHAT:"))
  117.         Wputs("Test of Winpipes and Stdio\n");
  118.  
  119.     if(match(szString, "STAT:")){
  120.         wsprintf((LPSTR)buffer, (LPSTR) "status:\niDebug=%d\nPipe=%d\nStdin=%d\n", iDebug, Pipe, Stdin);
  121.         Wputs((LPSTR)buffer);
  122.     }
  123.  
  124. }
  125.  
  126. /*  interact with debugging dialog from stdio */
  127.  
  128. Debugger()  /*    called on a WM_USER, wNotify    */
  129. {
  130.     int c;
  131.     while((c=Wgetc()) >= 0){            /*  non-error    */
  132.     Wputc((char) c);                        /*  echo to terminal */
  133.     szDebug[iDebug] = (char)c;        /*  save strlen */
  134.     switch(c){
  135.         case    13:                         /*  enter           */
  136.         case    10:                         /*  line feed       */
  137.         szDebug[iDebug] = 0;            /*  Null terminate    */
  138.         Parse(szDebug);
  139.         iDebug=0;                /*  Reset next    */
  140.                 break;
  141.  
  142.             case    8:                          /*  Backspace   */
  143.                 iDebug--;
  144.                 iDebug = (iDebug <= 0) ? 0 : iDebug;
  145.                 break;
  146.  
  147.             default:                            /*  every other character */
  148.                 iDebug++;
  149.             iDebug = (iDebug >= DEBUG_STRLEN) ? (DEBUG_STRLEN - 1): iDebug;
  150.                 break;
  151.  
  152.     }
  153.  
  154.     }
  155.  
  156. }
  157.  
  158.  
  159.  
  160. /*  Winproc for testapp */
  161.  
  162.  
  163. long FAR PASCAL WndProc(hWnd, message, wParam, lParam)
  164. HWND hWnd;
  165. unsigned message;
  166. WORD wParam;
  167. LONG lParam;
  168. {
  169.  
  170.     switch (message) {
  171.         case WM_COMMAND:
  172.         switch(wParam){
  173.  
  174.         case IDM_ABOUT:
  175.             Wputs("About Box Call\n");
  176.             PopupDLG(hWnd, "AboutBox", About);
  177.                     break;
  178.  
  179.         default:
  180.             Wputs("Unused WM_COMMAND\n");
  181.                     return (DefWindowProc(hWnd, message, wParam, lParam));
  182.             }
  183.             break;
  184.  
  185.     case WM_DESTROY:
  186.         ReleasePipe(Stdin);
  187.         Wputs("WM_DESTROY\n");
  188.         PostQuitMessage(0);
  189.         break;
  190.  
  191.     case    WM_USER:
  192.         if(wParam == PIPE_IN)
  193.         Debugger();
  194.         break;
  195.  
  196.  
  197.     case    WM_CHAR:
  198.         if(wParam == 13)
  199.         Wputc(10);
  200.         else
  201.         Wputc(wParam);
  202.         break;
  203.  
  204.     case    WM_CREATE:
  205.         if(OpenPipe(hWnd, "Stdin", PIPE_READ, PIPE_IN)<0)
  206.                 Wputs("Can't open pipe\n");
  207.  
  208.         Wputs("WM_CREATE\n");
  209.  
  210.         return (DefWindowProc(hWnd, message, wParam, lParam));
  211.             break;
  212.  
  213.     case    WM_PAINT:
  214.         Wputs("Paint Message\n");
  215.  
  216.         default:
  217.         return (DefWindowProc(hWnd, message, wParam, lParam));
  218.     }
  219.     return (NULL);
  220.  
  221. }
  222.  
  223.  
  224. /*  Winmain for testapp */
  225.  
  226.  
  227. int PASCAL WinMain(hInst, hPrevInstance, lpszCmdLine, nCmdShow)
  228.     HANDLE  hInst;
  229.     HANDLE  hPrevInstance;
  230.     LPSTR   lpszCmdLine;
  231.     int     nCmdShow;
  232.     {
  233.         MSG         msg;
  234.         BOOL        bStat;
  235.  
  236.         hThisInstance = hInst;
  237.  
  238.         if(!hPrevInstance){
  239.             WNDCLASS    wc;
  240.             wc.style            =   CS_HREDRAW | CS_VREDRAW;
  241.             wc.lpfnWndProc      =   WndProc;
  242.             wc.cbClsExtra       =   0;
  243.             wc.cbWndExtra       =   0;
  244.             wc.hInstance        =   hInst;
  245.             wc.hIcon            =   LoadIcon(hInst,"testIcon");
  246.             wc.hCursor          =   LoadCursor (NULL, IDC_ARROW);
  247.             wc.hbrBackground    =   GetStockObject(WHITE_BRUSH);
  248.             wc.lpszMenuName     =   "Testio";
  249.             wc.lpszClassName    =   "stdio_test";
  250.  
  251.             if(!RegisterClass(&wc))
  252.                 return(FALSE);
  253.  
  254.         }
  255.  
  256.  
  257.     hThisWnd = CreateWindow ("stdio_test", "Testapp", WS_OVERLAPPEDWINDOW, 25, 25, 300, 200, NULL, NULL, hInst, NULL);
  258.  
  259.     ShowWindow(hThisWnd, nCmdShow);
  260.     UpdateWindow(hThisWnd);
  261.  
  262.  
  263.     while(GetMessage(&msg, NULL, 0, 0)){
  264.         TranslateMessage(&msg);
  265.         DispatchMessage(&msg);
  266.         }
  267.  
  268.     return(msg.wParam);
  269.  
  270. }
  271.