home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / msj / msjv3_3 / windebug / bugtest.c next >
Encoding:
C/C++ Source or Header  |  1989-03-02  |  5.9 KB  |  252 lines

  1. /*
  2.  * DEBUG TEST PROGRAM - SOURCE CODE (BUGTEST.C)
  3.  *
  4.  * LANGUAGE : Microsoft C 5.0
  5.  * MODEL    : small
  6.  * STATUS   : operational
  7.  *
  8.  * 12/11/87 1.00 - Kevin P. Welch - initial creation.
  9.  *
  10.  */
  11.  
  12. #include <windows.h>
  13. #include "debug.h"
  14.  
  15. /* local definitions */
  16. #define    BUG_CONTROL    201
  17.  
  18. /* function definitions */
  19. LONG FAR PASCAL    TestWndFn( HWND, WORD, WORD, LONG );
  20.  
  21. /* */
  22.  
  23. /*
  24.  * MAINLINE - BUG TEST PROGRAM
  25.  *
  26.  * This mainline initializes the test program and processes
  27.  * and dispatches all messages relating to the debug test
  28.  * window.
  29.  *
  30.  */
  31.  
  32. int PASCAL WinMain( hInstance, hPrevInstance, lpsCmd, wCmdShow )
  33.    HANDLE    hInstance;
  34.    HANDLE       hPrevInstance;
  35.    LPSTR        lpsCmd;
  36.    WORD          wCmdShow;
  37. {
  38.     /* local variables */
  39.    MSG        Msg;    /* current system message */
  40.      
  41.     /* initialization */
  42.     if ( TestInit( hInstance, hPrevInstance, lpsCmd, wCmdShow ) ) {
  43.  
  44.         /* process system messages until finished */
  45.         while ( GetMessage( (LPMSG)&Msg, NULL, 0, 0 ) ) {
  46.             TranslateMessage( (LPMSG)&Msg );
  47.             DispatchMessage( (LPMSG)&Msg );
  48.         }
  49.  
  50.         /* terminate application */
  51.         exit( Msg.wParam );
  52.             
  53.     } else
  54.         exit( FALSE );
  55.  
  56. }
  57.  
  58. /* */
  59.  
  60. /*
  61.  *    TestInit( hInstance, hPrevInstance, lpsCmd, wCmdShow ) : BOOL;
  62.  *
  63.  *        hInstance    current instance handle
  64.  *        hPrevInstance    handle to previous instance
  65.  *        lpsCmd        command line string
  66.  *        wCmdShow    window display flag
  67.  *
  68.  * This utility function performs all the initialization required
  69.  * for testing the debug utility.  Included in this program is
  70.  * the registry and creation of the main window & the installation
  71.  * of the debug utility code.
  72.  *
  73.  */
  74.  
  75. static BOOL TestInit( hInstance, hPrevInstance, lpsCmd, wCmdShow )
  76.     HANDLE        hInstance;
  77.     HANDLE        hPrevInstance;
  78.     LPSTR        lpsCmd;
  79.     WORD        wCmdShow;
  80. {
  81.     /* local variables */
  82.     HWND        hWnd;    /* current window handle */
  83.     BOOL        bResult;    /* result of initialization */
  84.     WNDCLASS    WndClass;    /* window class */
  85.  
  86.     /* initialization */
  87.     bResult = FALSE;
  88.     
  89.     /* register window class */
  90.     if ( !hPrevInstance ) {
  91.     
  92.         /* define MAZE window class */
  93.         memset( &WndClass, 0, sizeof(WNDCLASS) );
  94.         WndClass.lpszClassName = (LPSTR)"TestWindow";
  95.         WndClass.hCursor = LoadCursor( NULL, IDC_ARROW );
  96.         WndClass.lpszMenuName = (LPSTR)NULL;
  97.         WndClass.style = CS_HREDRAW | CS_VREDRAW;
  98.         WndClass.lpfnWndProc = TestWndFn;
  99.         WndClass.hInstance = hInstance;
  100.         WndClass.hIcon = LoadIcon( hInstance, "BugTestIcon" );
  101.         WndClass.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
  102.     
  103.         /* register maze window class */        
  104.         if ( RegisterClass( (LPWNDCLASS)&WndClass ) ) {
  105.     
  106.             /* create window */
  107.             hWnd = CreateWindow(
  108.                     "TestWindow",                        /* class name */
  109.                     "Debug Test Window",                /* caption */
  110.                     WS_TILEDWINDOW,                    /* style */
  111.                     CW_USEDEFAULT,                        /* x position */
  112.                     CW_USEDEFAULT,                        /* y position */
  113.                     CW_USEDEFAULT,                        /* width */
  114.                     CW_USEDEFAULT,                        /* height */
  115.                     (HWND)NULL,                            /* parent window */
  116.                     (HMENU)NULL,                        /* menu */
  117.                     hInstance,                            /* application */
  118.                     (LPSTR)NULL                            /* other data */
  119.                 );
  120.  
  121.             /* continue if successful */
  122.             if ( hWnd ) {
  123.                 
  124.                 /* Here is where the debug utility is installed
  125.                  * into the program.  A response message number
  126.                  * is provided along with the maximum number of
  127.                  * debug statements which will be maintained
  128.                  * by the listbox.  The larger this number, the
  129.                  * less global memory available for your 
  130.                  * application.
  131.                  */
  132. #if DEBUG    
  133.                 DebugSetup( hWnd, BUG_CONTROL, 100 );
  134. #endif
  135.  
  136.                 /* make window visible */
  137.                 bResult = TRUE;
  138.                 ShowWindow( hWnd, wCmdShow );                                            
  139.  
  140.             }  
  141.                     
  142.         } 
  143.         
  144.     }
  145.     
  146.     /* return result */
  147.     return( bResult );
  148.     
  149. }
  150.  
  151. /* */
  152.  
  153. /*
  154.  * TEST WINDOW MESSAGE PROCESSING PROCEDURE
  155.  *
  156.  * TestWndFn( hWnd, wMessage, wParam, lParam ) : LONG FAR PASCAL
  157.  *
  158.  *        hWnd        window handle
  159.  *        wMessage    message number
  160.  *        wParam        additional message information
  161.  *        lParam        additional message information
  162.  *
  163.  * This window function processes all the messages related to
  164.  * the debug test window.  Using the system menu the user can
  165.  * display the debug control panel dialog box.
  166.  *
  167.  */
  168.  
  169. LONG FAR PASCAL TestWndFn( hWnd, wMessage, wParam, lParam )
  170.     HWND        hWnd;
  171.     WORD        wMessage;
  172.     WORD        wParam;
  173.     LONG        lParam;
  174. {
  175.     /* local variables */
  176.     LONG        lResult;    /* result of message */
  177.  
  178.     /* initialization */
  179.     lResult = FALSE;
  180.     
  181. #if DEBUG
  182.     /* sample debugging output */
  183.     switch( wMessage )
  184.         {
  185.     case WM_MOVE :
  186.         Debug( 1, "WM_MOVE: [%u,%u]", HIWORD(lParam), 
  187.             LOWORD(lParam) );
  188.         break;
  189.     case WM_SIZE :
  190.         Debug( 1, "WM_SIZE: [%u,%u]", HIWORD(lParam), 
  191.             LOWORD(lParam) );
  192.         break;
  193.     case WM_CHAR :
  194.         Debug( 2, "WM_CHAR: [%c,%u]", wParam, wParam );
  195.         break;
  196.     case WM_ACTIVATE :
  197.         Debug( 3, "WM_ACTIVATE: %s", 
  198.             (wParam)?"activate":"inactivate" );
  199.         break;
  200.     case WM_ACTIVATEAPP :
  201.         Debug( 3, "WM_ACTIVATEAPP: %s", 
  202.             (wParam)?"activate":"inactivate" );
  203.         break;
  204.     case WM_PAINT :
  205.         Debug( 4, "WM_PAINT:" );
  206.         break;
  207.     default : 
  208.         break;
  209.     }
  210. #endif
  211.  
  212.     /* process each message */
  213.     switch( wMessage )
  214.         {
  215.     case WM_SYSCOMMAND : /* system command */
  216.  
  217.         /* In here you need to handle the special case where the
  218.          * user asks for the debug control panel to be displayed.
  219.          * To do so you need to trap the control panel response
  220.          * message you provided when installing the debug
  221.          * utility.
  222.          */
  223.  
  224.         /* process sub-message */
  225.         switch( wParam )
  226.             {
  227. #if DEBUG
  228.         case BUG_CONTROL : /* debug control panel */
  229.             DebugControl( hWnd );
  230.             break;
  231. #endif
  232.         default :
  233.             lResult = DefWindowProc( hWnd, wMessage, 
  234.                         wParam, lParam );
  235.             break;
  236.         }        
  237.         
  238.         break;
  239.     case WM_DESTROY :    /* destroy window */
  240.         PostQuitMessage( 0 );
  241.         break;
  242.     default : /* send to default */
  243.         lResult = DefWindowProc( hWnd, wMessage, wParam, 
  244.                     lParam );
  245.         break;
  246.     }
  247.     
  248.     /* return normal result */
  249.     return( lResult );
  250.  
  251. }
  252.