--- mstools/samples/deb/debmain.c 2018/08/09 18:20:39 1.1 +++ mstools/samples/deb/debmain.c 2018/08/09 18:21:33 1.1.1.2 @@ -1,5 +1,10 @@ // ************************************************************************ -// MODULE : DEBMain.c +// +// Microsoft Developer Support +// Copyright (c) 1992 Microsoft Corporation +// +// ************************************************************************ +// MODULE : DEBMain.C // PURPOSE : A Win32 Application demonstrating the Debug APIs // FUNCTIONS : // WinMain() - application entry point @@ -10,14 +15,12 @@ // AboutDlgProc() - processes messages for "About" dialog box // NewListBoxWndProc() - subclass procedure to prevent listbox moving // COMMENTS : +// // ************************************************************************ +#define STRICT #include // required for all Windows applications -#include // sprintf() -#include // lstrcat() -#include // memcmp() #include "LinkList.H" // double linked list package (OBJ) -#include "ToolBar.H" // various ToolBar controls (DLL) #include "DEBDebug.H" // debugging support functions #include "DEBMisc.H" // misc support functions #include "DEBMain.H" // specific to this module @@ -35,10 +38,6 @@ TCHAR szAppTitle[32]; // name o HANDLE hProcess; // handle to current running debugee process LONG MaxStrLen = 0; // maximum string length in Debug Event listbox -//-- debugee specific data -PROCESS_INFORMATION pi; // process information -STARTUPINFO si; // debugee startup information - //-- private profile settings int xPos; // application window's horizontal position int yPos; // application window's vertical position @@ -82,13 +81,22 @@ TCHAR szExePathName[MAX_PATH]; // ful TCHAR szHelpPathName[MAX_PATH]; // full pathname of the application's help file TCHAR szIniPathName[MAX_PATH]; // full pathname of the application's ini file +//-- internal function prototypes +LRESULT CALLBACK MainWndProc ( HWND, UINT, WPARAM, LPARAM ); +LRESULT CALLBACK ProcessCommandsWndProc ( HWND, UINT, WPARAM, LPARAM ); +LRESULT CALLBACK NewListBoxWndProc ( HWND, UINT, WPARAM, LPARAM ); +BOOL CALLBACK PreferencesDlgProc ( HWND, UINT, WPARAM, LPARAM ); +LRESULT CALLBACK MainWndProc ( HWND, UINT, WPARAM, LPARAM ); +BOOL CALLBACK AttachDlgProc ( HWND, UINT, WPARAM, LPARAM ); +BOOL CALLBACK AboutDlgProc ( HWND, UINT, WPARAM, LPARAM ); + // ************************************************************************ // FUNCTION : WinMain( HINSTANCE, HINSTANCE, LPSTR, int ) // PURPOSE : initialize the window, process the message dispatch loop // COMMENTS : // ************************************************************************ -int PASCAL +int WINAPI WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow ) { MSG msg; @@ -189,17 +197,45 @@ WinMain( HINSTANCE hInst, HINSTANCE hPre // WM_COMMAND - passed to ProcessCommandsWndProc() // WM_DESTROY - destroy window // ... -// COMMENTS : !! I will document this better at a later date !! +// COMMENTS : +// // ************************************************************************ LRESULT CALLBACK MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { static HDC hDC; + BOOL fError; + switch( uMsg ) { case WM_COMMAND: - return( ProcessCommandsWndProc( hWnd, uMsg, wParam, lParam) ); + + switch( LOWORD(wParam) ) { + + case IDM_FILE_OPEN: + if( ActiveProcesses ) { + MessageBox( hWndMain, + (LPTSTR) "This build of DEB is limited to\n" + "debugging only one process at a time.", + (LPTSTR) "Cannot Open Debugee", + MB_OK | MB_ICONEXCLAMATION ); + return( FALSE ); + } + if( !(fError = OpenDebugee( )) ) { + // handle cancel condition + } + else { + if( fClearOnNew ) { + SendMessage( hWndDebugList, LB_RESETCONTENT, 0, 0 ); + MaxStrLen = 0; + } + } + return( FALSE ); + + default: + return( ProcessCommandsWndProc( hWnd, uMsg, wParam, lParam) ); + } //-- create debug event listbox case UM_CREATE_LISTBOX: { @@ -233,7 +269,7 @@ MainWndProc( HWND hWnd, UINT uMsg, WPARA SendMessage( hWndDebugList, WM_SETFONT, (DWORD) hFont, TRUE ); ReleaseDC( hWndDebugList, hDC ); - return( NULL ); + return( FALSE ); } //-- Create ToolBar & Debug Events listbox @@ -242,7 +278,7 @@ MainWndProc( HWND hWnd, UINT uMsg, WPARA if( fToolBar ) ShowWindow( hWndTextButtonBar, SW_SHOW ); PostMessage( hWnd, UM_CREATE_LISTBOX, 0, 0 ); - return( NULL ); + return( FALSE ); //-- resize the debug event listbox when the window size changes case WM_SIZE: @@ -275,7 +311,7 @@ MainWndProc( HWND hWnd, UINT uMsg, WPARA nHeight = (int) (rect.bottom - rect.top); } - return( NULL ); + return( FALSE ); case WM_MOVE: { RECT rect; @@ -285,7 +321,7 @@ MainWndProc( HWND hWnd, UINT uMsg, WPARA yPosOld = yPos; xPos = (int) rect.left; yPos = (int) rect.top; - return( NULL ); + return( FALSE ); } case WM_CTLCOLORLISTBOX: { @@ -312,7 +348,7 @@ MainWndProc( HWND hWnd, UINT uMsg, WPARA sizeof(szExitBoxText) ); if ( MessageBox( hWnd, szExitBoxText, szExitBoxTitle, MB_YESNO | MB_ICONEXCLAMATION ) == IDNO ) - return( NULL ); + return( FALSE ); } //-- store location information to private profile data @@ -322,19 +358,19 @@ MainWndProc( HWND hWnd, UINT uMsg, WPARA DestroyWindow( hWndDebugList ); DestroyWindow( hWndMain ); - return( NULL ); + return( FALSE ); case WM_DESTROY: if( fHelpUsed ) WinHelp( hWnd, szHelpPathName, (UINT) HELP_QUIT, (DWORD) NULL ); PostQuitMessage( 0 ); - return( NULL ); + return( FALSE ); default: // Passes it on if unproccessed return( DefWindowProc(hWnd, uMsg, wParam, lParam) ); } - return( NULL ); + return( FALSE ); } @@ -346,7 +382,8 @@ MainWndProc( HWND hWnd, UINT uMsg, WPARA // IDM_FILE_EXIT - exit the application // IDM_FILE_ABOUT - About Dialog Box // ... -// COMMENTS : !! I will document this better at a later date !! +// COMMENTS : +// // ************************************************************************ LRESULT CALLBACK ProcessCommandsWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) @@ -355,6 +392,8 @@ ProcessCommandsWndProc( HWND hWnd, UINT static LPCTSTR lpszAttachDlgBox = (LPCTSTR) "AttachDlgBox"; static LPCTSTR lpszPreferencesDlgBox = (LPCTSTR) "PreferencesDlgBox"; + BOOL fError; + switch( LOWORD(wParam) ) { case IDM_FILE_OPEN: @@ -366,7 +405,7 @@ ProcessCommandsWndProc( HWND hWnd, UINT MB_OK | MB_ICONEXCLAMATION ); return( FALSE ); } - if( !OpenDebugee( &pi, &si ) ) { + if( !(fError = OpenDebugee( )) ) { // handle cancel condition } else { @@ -375,7 +414,7 @@ ProcessCommandsWndProc( HWND hWnd, UINT MaxStrLen = 0; } } - return(NULL); + return( FALSE ); case IDM_FILE_ATTACH: if( ActiveProcesses ) { @@ -386,8 +425,8 @@ ProcessCommandsWndProc( HWND hWnd, UINT MB_OK | MB_ICONEXCLAMATION ); return( FALSE ); } - if( !DialogBox( hInstance, lpszAttachDlgBox, hWnd, - (DLGPROC) AttachDlgProc ) ) { + if( !(fError = DialogBox( hInstance, lpszAttachDlgBox, hWnd, + (DLGPROC) AttachDlgProc ) ) ) { // handle cancel condition } else { @@ -396,37 +435,37 @@ ProcessCommandsWndProc( HWND hWnd, UINT MaxStrLen = 0; } } - return(NULL); + return( FALSE ); case IDM_EDIT_CUT: CopyListBoxToClipboard( hWndDebugList, MaxStrLen ); SendMessage( hWnd, WM_COMMAND, IDM_EDIT_DELETE, 0 ); - return( NULL ); + return( FALSE ); case IDM_EDIT_COPY: { CopyListBoxToClipboard( hWndDebugList, MaxStrLen ); - return( NULL ); + return( FALSE ); } case IDM_EDIT_DELETE: SendMessage( hWndDebugList, LB_RESETCONTENT, 0, 0 ); MaxStrLen = 0; - return( NULL ); + return( FALSE ); case IDM_OPTIONS_FONT: if( !ChooseNewFont( hWndDebugList ) ) { // handle cancel condition } - return( NULL ); + return( FALSE ); case IDM_OPTIONS_COLOR: ChooseNewBkColor( hWndDebugList ); - return( NULL ); + return( FALSE ); case IDM_OPTIONS_PREFERENCES: DialogBox( hInstance, lpszPreferencesDlgBox, hWnd, (DLGPROC) PreferencesDlgProc ); - return( NULL ); + return( FALSE ); case IDM_OPTIONS_TOOLBAR: if( fToolBar ) { @@ -441,7 +480,7 @@ ProcessCommandsWndProc( HWND hWnd, UINT ShowWindow( hWndTextButtonBar, SW_SHOW ); SendWmSizeMessage( hWndMain ); } - return( NULL ); + return( FALSE ); case IDM_OPTIONS_SAVEDDIR: if( fSavedDirectory ) { @@ -454,7 +493,7 @@ ProcessCommandsWndProc( HWND hWnd, UINT CheckMenuItem( GetMenu(hWndMain), IDM_OPTIONS_SAVEDDIR, MF_CHECKED ); } - return( NULL ); + return( FALSE ); case IDM_OPTIONS_SAVEONEXIT: if( fSaveOnExit ) { @@ -467,35 +506,36 @@ ProcessCommandsWndProc( HWND hWnd, UINT CheckMenuItem( GetMenu(hWndMain), IDM_OPTIONS_SAVEONEXIT, MF_CHECKED ); } - return( NULL ); + return( FALSE ); case IDM_HELP_CONTENTS: fHelpUsed = TRUE; WinHelp( hWnd, (LPCTSTR) szHelpPathName, HELP_INDEX, (DWORD) NULL ); - return( NULL ); + return( FALSE ); case IDM_HELP_SEARCH: fHelpUsed = TRUE; WinHelp( hWnd, (LPCTSTR) szHelpPathName, HELP_PARTIALKEY, (DWORD) "" ); - return( NULL ); + return( FALSE ); case IDM_HELP_HOWTOUSE: fHelpUsed = TRUE; WinHelp( hWnd, (LPTSTR) NULL, HELP_HELPONHELP, (DWORD) NULL ); - return( NULL ); + return( FALSE ); case IDM_HELP_ABOUT: DialogBox( hInstance, lpszAboutDlgBox, hWnd, (DLGPROC) AboutDlgProc ); - return( NULL ); + return( FALSE ); case IDM_FILE_EXIT: SendMessage( hWndMain, WM_CLOSE, 0, 0 ); - return( NULL ); + return( FALSE ); default: - return( DefWindowProc(hWnd, uMsg, wParam, lParam) ); + return( DefWindowProc(hWnd, uMsg, wParam, lParam) ); } + return( FALSE ); } @@ -506,7 +546,6 @@ ProcessCommandsWndProc( HWND hWnd, UINT // WM_INITDIALOG - initialize dialog box // WM_COMMAND - Input received // COMMENTS : -// // Wait for user to click on "Ok" button, then close the dialog box. // ************************************************************************ BOOL CALLBACK @@ -607,7 +646,6 @@ PreferencesDlgProc( HWND hDlg, UINT uMsg // WM_INITDIALOG - initialize dialog box // WM_COMMAND - Input received // COMMENTS : -// // Wait for user to click on "Ok" button, then close the dialog box. // ************************************************************************ BOOL CALLBACK @@ -682,7 +720,6 @@ AttachDlgProc( HWND hDlg, UINT uMsg, WPA // COMMENTS : // No initialization is needed for this particular dialog box, but TRUE // must be returned to Windows. -// // Wait for user to click on "Ok" button, then close the dialog box. // ************************************************************************ BOOL CALLBACK @@ -728,7 +765,7 @@ NewListBoxWndProc( HWND hWnd, UINT uMsg, case WM_NCLBUTTONDOWN: if( wParam == HTCAPTION ) { SetFocus( hWnd ); - return( NULL ); + return( FALSE ); } else break;