--- mstools/samples/deb/debmain.c 2018/08/09 18:20:39 1.1 +++ mstools/samples/deb/debmain.c 2018/08/09 18:23:35 1.1.1.3 @@ -1,184 +1,215 @@ + +/******************************************************************************\ +* This is a part of the Microsoft Source Code Samples. +* Copyright (C) 1993 Microsoft Corporation. +* All rights reserved. +* This source code is only intended as a supplement to +* Microsoft Development Tools and/or WinHelp documentation. +* See these sources for detailed information regarding the +* Microsoft samples programs. +\******************************************************************************/ + // ************************************************************************ -// MODULE : DEBMain.c +// MODULE : DEBMain.C // PURPOSE : A Win32 Application demonstrating the Debug APIs // FUNCTIONS : -// WinMain() - application entry point -// MainWndProc() - processes messages -// ProcessCommandsWndProc() - processes WM_COMMAND messages -// PreferencesDlgProc() - processes messages for "Preferences" dialog box -// AttachDlgProc() - processes messages for "Attach" dialog box -// AboutDlgProc() - processes messages for "About" dialog box -// NewListBoxWndProc() - subclass procedure to prevent listbox moving +// WinMain() - application entry point +// MainWndProc() - processes messages +// ProcessCommandsWndProc() - processes WM_COMMAND messages +// PreferencesDlgProc() - processes messages for "Preferences" dialog box +// AttachDlgProc() - processes messages for "Attach" dialog box +// AboutDlgProc() - processes messages for "About" dialog box +// NewListBoxWndProc() - subclass procedure to prevent listbox moving +// TimerProc() - timer procedure for animated icon // COMMENTS : +// // ************************************************************************ +#define STRICT // enable strict typing #include // required for all Windows applications -#include // sprintf() -#include // lstrcat() -#include // memcmp() +#include "StdLib.H" // __argc, __argv #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 -// *********** // global data -// *********** -HWND hWndMain; // main window handle -HWND hWndDebugList; // debug event listbox handle -HWND hWndTextButtonBar; // windows handle to the text toolbar -HINSTANCE hInstance; // instance handle of this EXE -LIST ProcessList; // linked list of debugee process information -INT ActiveProcesses = 0; // count of active debugee processes -TCHAR szAppTitle[32]; // name of the application -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 -int nWidth; // application window's width -int nHeight; // application window's height -BOOL fMaximized; // flag: maximized state? -BOOL fToolBar; // flag: display the ToolBar? -BOOL fSaveOnExit; // flag: save settings upon exit? -BOOL fSavedDirectory; // flag: use saved directory for opening files? -BOOL fClearOnNew; // flag: clears the event listbox on a new debugee -BOOL fVerbose; // flag: verbose event listings -BOOL fShowSymbols; // flag: show symbols (limited) -BOOL fSavePreferences; // flag: save the preferences settings -HFONT hFont; // current handle to the Debug Event listbox font -LOGFONT LogFont; // current logical font -COLORREF rgbColor; // current listbox text foreground color -COLORREF rgbBkColor; // current listbox text foreground color -LONG DebugMode; // debug mode flag CreateProcess -LONG DebugeePriority; // debugee priority CreateProcess +// ------------------------------------------------------------------------ +GLOBAL Global; // various global data +PROFILE Profile; // various profile data -// ************* // internal data -// ************* -#define TOP_BORDER 4 -#define BOTTOM_BORDER 4 -#define SIDE_BORDER 4 -#define MIN_HEIGHT 128 - -WNDPROC OldListBoxWndProc; // original listbox procedure -TCHAR szShortAppTitle[16]; // short name of the application -BOOL fHelpUsed = FALSE; // boolean denoting online help invoked -SIZE ClientSize; // client windows size -SIZE DebugListBoxSize; // debug event listbox size -int TextButtonBarHeight; // text button bar height -int xPosOld; // application window's old horizontal position -int yPosOld; // application window's old vertical position - -//-- location of various files -TCHAR szPath[MAX_PATH]; // path where the running application resides +// ------------------------------------------------------------------------ +#define TIMEOUT_ANIMATED_ICON 150L // animated icon timeout +static LPCTSTR lpszSourceFileName = TEXT(__FILE__); + +// location of various files +// ------------------------------------------------------------------------ +TCHAR szPath[MAX_PATH]; // path where the running application + // resides TCHAR szExePathName[MAX_PATH]; // full pathname of the application -TCHAR szHelpPathName[MAX_PATH]; // full pathname of the application's help file -TCHAR szIniPathName[MAX_PATH]; // full pathname of the application's ini file +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 ); +BOOL CALLBACK AttachDlgProc ( HWND, UINT, WPARAM, LPARAM ); +BOOL CALLBACK AboutDlgProc ( HWND, UINT, WPARAM, LPARAM ); +VOID CALLBACK TimerProc ( HWND, UINT, UINT, DWORD ); // ************************************************************************ -// FUNCTION : WinMain( HINSTANCE, HINSTANCE, LPSTR, int ) +// FUNCTION : WinMain( HINSTANCE, HINSTANCE, LPSTR, INT ) // PURPOSE : initialize the window, process the message dispatch loop // COMMENTS : +// // ************************************************************************ -int PASCAL -WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow ) +INT WINAPI +WinMain( HINSTANCE hInstance, HINSTANCE hPrevInst, LPSTR lpCmdLine, + INT nCmdShow ) { - MSG msg; - WNDCLASS wndclass; - - LPCTSTR lpszMenuName = (LPCTSTR) "DebugMenu"; - LPCTSTR lpszClassName = (LPCTSTR) "DebugClass"; - LPCTSTR lpszIconName = (LPCTSTR) "DebugIcon"; - LPCTSTR lpszAccelName = (LPCTSTR) "DebugAccel"; - LPCTSTR lpszIniFileExt = (LPCTSTR) "INI"; - LPCTSTR lpszHelpFileExt = (LPCTSTR) "HLP"; - - HANDLE hAccel; // handle to the accelerator table - - UNREFERENCED_PARAMETER( lpCmdLine ); // avoid warnings - UNREFERENCED_PARAMETER( hPrevInst ); + MSG Msg; + WNDCLASS WndClass; + HACCEL hAccel; + + LPCTSTR lpszIconName = TEXT( "DebugIcon" ); + LPCTSTR lpszMenuName = TEXT( "DebugMenu" ); + LPCTSTR lpszClassName = TEXT( "DebugClass" ); + LPCTSTR lpszAccelName = TEXT( "DebugAccel" ); + LPCTSTR lpszIniFileExt = TEXT( "INI" ); + LPCTSTR lpszHelpFileExt = TEXT( "HLP" ); + + Global.hInstance = hInstance; + Global.dwActiveDebuggees = 0; + + //-- Load the "A Windows API Failed" resource string + { + TCHAR szApiFailedMsg[] = TEXT( "A Windows API Failed" ); + + if( !LoadString( Global.hInstance, IDS_API_FAILED_MSG, + Global.szApiFailedMsg, sizeof(Global.szApiFailedMsg) ) ) { + ErrorMessageBox( TEXT( "First LoadString()" ), + szApiFailedMsg, lpszSourceFileName, __LINE__ ); + lstrcpy( Global.szApiFailedMsg, szApiFailedMsg ); + } + } - hInstance = hInst; + //-- Load all other resource strings + if( !LoadString( Global.hInstance, IDS_APPNAME, Global.szAppName, + sizeof(Global.szAppName) ) ) + ErrorMessageBox( TEXT("LoadString()"), + Global.szApiFailedMsg, lpszSourceFileName, __LINE__ ); + if( !LoadString( Global.hInstance, IDS_SHORT_APPNAME, + Global.szShortAppName, sizeof(Global.szShortAppName) ) ) + ErrorMessageBox( TEXT("LoadString()"), + Global.szApiFailedMsg, lpszSourceFileName, __LINE__ ); + + //-- if compiled for Win32 (Unicode) and not Win32s then display + // notice and terminate + if( GetVersion() & 0x80000000 ) { + TCHAR szTitleBuffer[64]; + TCHAR szTextBuffer[256]; + + if( !LoadString( Global.hInstance, IDS_WINDOWS_NT_REQUIRED_TITLE, + szTitleBuffer, sizeof(szTitleBuffer) ) ) + ErrorMessageBox( TEXT("LoadString()"), + Global.szApiFailedMsg, lpszSourceFileName, __LINE__ ); + + if( !LoadString( Global.hInstance, IDS_WINDOWS_NT_REQUIRED, + szTextBuffer, sizeof(szTextBuffer) ) ) + ErrorMessageBox( TEXT("LoadString()"), + Global.szApiFailedMsg, lpszSourceFileName, __LINE__ ); + + MessageBox( NULL, szTextBuffer, szTitleBuffer, + MB_APPLMODAL | MB_ICONSTOP | MB_OK ); + return( -1 ); + } //-- register the debug event window class - wndclass.style = (UINT) NULL; - wndclass.lpfnWndProc = (WNDPROC) MainWndProc; - wndclass.cbClsExtra = (int) NULL; - wndclass.cbWndExtra = (int) NULL; - wndclass.hInstance = hInstance; - wndclass.hIcon = LoadIcon( hInstance, lpszIconName ); - wndclass.hCursor = LoadCursor( hInstance, (LPTSTR) IDC_ARROW ); - wndclass.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE+1); - wndclass.lpszMenuName = lpszMenuName; - wndclass.lpszClassName = lpszClassName; - - if( !RegisterClass(&wndclass) ) + WndClass.style = CS_DBLCLKS; + WndClass.lpfnWndProc = (WNDPROC) MainWndProc; + WndClass.cbClsExtra = (INT) NULL; + WndClass.cbWndExtra = (INT) NULL; + WndClass.hInstance = Global.hInstance; + WndClass.hIcon = NULL; + WndClass.hCursor = LoadCursor( Global.hInstance, (LPTSTR) IDC_ARROW ); + WndClass.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE+1); + WndClass.lpszMenuName = lpszMenuName; + WndClass.lpszClassName = lpszClassName; + + if( !RegisterClass(&WndClass) ) { + ErrorMessageBox( TEXT("RegisterClass()"), + Global.szApiFailedMsg, lpszSourceFileName, __LINE__ ); return( FALSE ); - - //-- Load resource strings - LoadString( hInstance, IDS_APPTITLE, szAppTitle, sizeof(szAppTitle) ); - LoadString( hInstance, IDS_SHORT_APPTITLE, szShortAppTitle, - sizeof(szShortAppTitle) ); + } //-- get application pathname and store the ini and help file pathname // (which is located in the same directory as the application) - GetModuleFileName( (HANDLE) NULL, szExePathName, sizeof(szExePathName)/sizeof(TCHAR) ); - GetPathFromFullPathName( szExePathName, szPath, sizeof(szPath) ); - wsprintf( szIniPathName, (LPCSTR) "%s\\%s.%s", szPath, szShortAppTitle, lpszIniFileExt ); - wsprintf( szHelpPathName, (LPCSTR) "%s\\%s.%s", szPath, szShortAppTitle, lpszHelpFileExt ); + GetModuleFileName( (HANDLE) NULL, szExePathName, + sizeof(szExePathName)/sizeof(TCHAR) ); + GetPathFromFullPathName( szExePathName, szPath, + sizeof(szPath)/sizeof(TCHAR) ); + wsprintf( szIniPathName, TEXT( "%s\\%s.%s" ), szPath, + Global.szShortAppName, lpszIniFileExt ); + wsprintf( szHelpPathName, TEXT( "%s\\%s.%s" ), szPath, + Global.szShortAppName, lpszHelpFileExt ); //-- retrieve stored default location from private profile data - GetPrivateProfileSettings( szAppTitle, szIniPathName ); + GetPrivateProfileSettings( Global.szAppName, szIniPathName, &Profile ); //-- Create a main window for this application instance - hWndMain = CreateWindow( - lpszClassName, // See RegisterClass() call - szAppTitle, // Text for window title bar - WS_OVERLAPPEDWINDOW, // Window style - xPos, // horizontal position - yPos, // vertical position - nWidth, // width - nHeight, // height - NULL, // Overlapped windows have no parent - NULL, // Use the window class menu - hInstance, // This instance owns this window - NULL ); // Extra pointer not needed + Global.hWndMain = CreateWindow( lpszClassName, Global.szAppName, + WS_OVERLAPPEDWINDOW, + Profile.xPos, Profile.yPos, + Profile.nWidth, Profile.nHeight, + NULL, NULL, Global.hInstance, NULL ); //-- If window could not be created, return "failure" - if( !hWndMain ) + if( !Global.hWndMain ) { + ErrorMessageBox( TEXT("CreateWindow()"), + Global.szApiFailedMsg, lpszSourceFileName, __LINE__ ); return( FALSE ); + } //-- Load main menu accelerators - if( !(hAccel = LoadAccelerators( hInstance, lpszAccelName) ) ) + if( !(hAccel = LoadAccelerators( Global.hInstance, lpszAccelName) ) ) { + ErrorMessageBox( TEXT("LoadAccelerators()"), + Global.szApiFailedMsg, lpszSourceFileName, __LINE__ ); return( FALSE ); + } //-- modify the menu to reflect saved settings - UpdateMenuSettings(); + UpdateMenuSettings( Global.hWndMain ); - //-- Make the window visible; update its client area; and return "success" - ShowWindow( hWndMain, (fMaximized) ? SW_SHOWMAXIMIZED : nCmdShow ); - UpdateWindow( hWndMain ); // Sends WM_PAINT message + //-- set the initial icon + Global.hIconCurrent = LoadIcon( Global.hInstance, lpszIconName ); - //-- initialize the double linked list package that stores the thread handles - InitList( &ProcessList, OrderFunc ); + //-- Make the window visible; update its client area; and return "success" + if( Profile.fMaximized ) + ShowWindow( Global.hWndMain, SW_SHOWMAXIMIZED ); + else if ( Profile.fMinimized ) + ShowWindow( Global.hWndMain, SW_SHOWMINIMIZED ); + else + ShowWindow( Global.hWndMain, SW_SHOWDEFAULT ); + UpdateWindow( Global.hWndMain ); //-- Acquire and dispatch messages until a WM_QUIT message is received. - while( GetMessage( &msg, NULL, 0, 0 ) ) { - if( !TranslateAccelerator( hWndMain, hAccel, &msg ) ) { - TranslateMessage( &msg ); // Translates virtual key codes - DispatchMessage( &msg ); // Dispatches message to window + while( GetMessage( &Msg, NULL, 0, 0 ) ) { + if( !TranslateAccelerator( Global.hWndMain, hAccel, &Msg ) ) { + TranslateMessage( &Msg ); + DispatchMessage( &Msg ); } } - return( msg.wParam ); // Returns the value from PostQuitMessage + return( Msg.wParam ); + UNREFERENCED_PARAMETER( lpCmdLine ); // avoid warnings + UNREFERENCED_PARAMETER( hPrevInst ); // always NULL under Windows NT + UNREFERENCED_PARAMETER( nCmdShow ); // } @@ -189,152 +220,218 @@ 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 ) { + #define TOP_BORDER 4 + #define BOTTOM_BORDER 4 + #define SIDE_BORDER 4 + #define MIN_HEIGHT 128 + static HDC hDC; switch( uMsg ) { + //-- forward all WM_COMMANDS to separate handler function case WM_COMMAND: return( ProcessCommandsWndProc( hWnd, uMsg, wParam, lParam) ); //-- create debug event listbox case UM_CREATE_LISTBOX: { TCHAR szWindowName[64]; + HFONT hFont; - LoadString( hInstance, IDS_DEBUG_EVENTS, szWindowName, - sizeof(szWindowName) ); + LoadString( Global.hInstance, IDS_DEBUG_EVENTS, szWindowName, + sizeof(szWindowName)/sizeof(TCHAR) ); - hWndDebugList = CreateWindow( - (LPCTSTR) "ListBox", - szWindowName, - WS_CHILD | WS_VISIBLE | - WS_CAPTION | WS_VSCROLL | - WS_HSCROLL | LBS_NOTIFY | - LBS_DISABLENOSCROLL | LBS_USETABSTOPS | - LBS_NOINTEGRALHEIGHT, - SIDE_BORDER, - fToolBar ? TextButtonBarHeight + TOP_BORDER : TOP_BORDER, - DebugListBoxSize.cx, DebugListBoxSize.cy, - hWnd, (HMENU) NULL, hInstance, NULL ); + Global.hWndListBox = CreateWindow( + TEXT( "ListBox" ), + szWindowName, + WS_CHILD | WS_VISIBLE | + WS_CAPTION | WS_VSCROLL | + WS_HSCROLL | LBS_NOTIFY | + LBS_DISABLENOSCROLL | LBS_USETABSTOPS | + LBS_NOINTEGRALHEIGHT, + (INT) SIDE_BORDER, + (INT) (Profile.fToolBar + ? (Global.ToolBarHeight + TOP_BORDER) + : TOP_BORDER), + (INT) Global.ListBoxSize.cx, + (INT) Global.ListBoxSize.cy, + hWnd, (HMENU) NULL, Global.hInstance, NULL ); //-- Subclass the listbox so the user cannot move it - OldListBoxWndProc = SubclassWindow( hWndDebugList, (WNDPROC) NewListBoxWndProc ); + Global.OldListBoxWndProc = SubclassWindow( Global.hWndListBox, + (WNDPROC) NewListBoxWndProc ); //-- set listbox font & background color - hDC = GetDC( hWndDebugList ); - hFont = CreateFontIndirect( &LogFont ); + hDC = GetDC( Global.hWndListBox ); + hFont = CreateFontIndirect( &(Profile.LogFont) ); SelectObject( hDC, hFont ); - SendMessage( hWndDebugList, WM_CTLCOLORLISTBOX, (DWORD) hDC, - (LONG) hWndDebugList ); - SendMessage( hWndDebugList, WM_SETFONT, (DWORD) hFont, TRUE ); - ReleaseDC( hWndDebugList, hDC ); + SendMessage( Global.hWndListBox, WM_CTLCOLORLISTBOX, (WPARAM) hDC, + (LPARAM) Global.hWndListBox ); + SendMessage( Global.hWndListBox, WM_SETFONT, (WPARAM) hFont, TRUE ); + ReleaseDC( Global.hWndListBox, hDC ); + + //-- if command line contains a debuggee name then + // start and detach the debug event processing thread + if( __argc == 2 ) + StartDebuggee( (LPTSTR) __argv[1], Global.hWndListBox ); - return( NULL ); + return( FALSE ); } - //-- Create ToolBar & Debug Events listbox + //-- create ToolBar & send message to create the Debug Events listbox case WM_CREATE: - hWndTextButtonBar = CreateTextButtonBar( hWnd, &TextButtonBarHeight ); - if( fToolBar ) - ShowWindow( hWndTextButtonBar, SW_SHOW ); + Global.hWndToolBar = CreateTextButtonBar( hWnd, &Global.ToolBarHeight ); + if( Profile.fToolBar ) + ShowWindow( Global.hWndToolBar, SW_SHOW ); PostMessage( hWnd, UM_CREATE_LISTBOX, 0, 0 ); - return( NULL ); + return( FALSE ); + + //-- handle icon painting + case WM_PAINT: + if( IsIconic( hWnd ) ) { + static PAINTSTRUCT ps; + + BeginPaint( hWnd, (LPPAINTSTRUCT) &ps ); + SendMessage( hWnd, WM_ICONERASEBKGND, (WPARAM) ps.hdc, 0L ); + DrawIcon( ps.hdc, 2, 2, Global.hIconCurrent ); + EndPaint( hWnd, (LPPAINTSTRUCT) &ps ); + return( FALSE ); + } + else + return( DefWindowProc(hWnd, uMsg, wParam, lParam) ); + + //-- reduce icon flickering + case WM_ERASEBKGND: + if( IsIconic( hWnd ) ) + return( TRUE ); + else + return( DefWindowProc(hWnd, uMsg, wParam, lParam) ); + + //-- update the icon when dragged + case WM_QUERYDRAGICON: + return( (LRESULT) (UINT) Global.hIconCurrent ); //-- resize the debug event listbox when the window size changes case WM_SIZE: - ClientSize.cx = LOWORD( lParam ); - ClientSize.cy = HIWORD( lParam ); - DebugListBoxSize.cx = ClientSize.cx - ( 2*SIDE_BORDER ); - DebugListBoxSize.cy = max( ClientSize.cy, MIN_HEIGHT + TOP_BORDER ) + Global.ClientSize.cx = LOWORD( lParam ); + Global.ClientSize.cy = HIWORD( lParam ); + Global.ListBoxSize.cx = Global.ClientSize.cx - ( 2*SIDE_BORDER ); + Global.ListBoxSize.cy = max( Global.ClientSize.cy, MIN_HEIGHT + + TOP_BORDER ) - (TOP_BORDER + BOTTOM_BORDER); - if( fToolBar ) - DebugListBoxSize.cy -= TextButtonBarHeight; + if( Profile.fToolBar ) + Global.ListBoxSize.cy -= Global.ToolBarHeight; - if( hWndDebugList != NULL) - MoveWindow( hWndDebugList, - SIDE_BORDER, - fToolBar ? TextButtonBarHeight + TOP_BORDER : TOP_BORDER, - DebugListBoxSize.cx, DebugListBoxSize.cy, TRUE ); - - if( wParam == SIZEFULLSCREEN ) { - fMaximized = 1; - xPos = xPosOld; - yPos = yPosOld; - } - else if( wParam == SIZENORMAL ) { - RECT rect; - - fMaximized = 0; - GetWindowRect( hWndMain, &rect ); - nWidth = (int) (rect.right - rect.left); - nHeight = (int) (rect.bottom - rect.top); - } + if( Global.hWndListBox != NULL) + MoveWindow( Global.hWndListBox, + (INT) SIDE_BORDER, + (INT) (Profile.fToolBar ? Global.ToolBarHeight + TOP_BORDER : TOP_BORDER), + (INT) Global.ListBoxSize.cx, (INT) Global.ListBoxSize.cy, TRUE ); + + switch( wParam ) { + + case SIZE_RESTORED: { + RECT rect; + + Profile.fMaximized = FALSE; + Profile.fMinimized = FALSE; + GetWindowRect( Global.hWndMain, &rect ); + Profile.nWidth = (INT) (rect.right - rect.left); + Profile.nHeight = (INT) (rect.bottom - rect.top); + if( Global.idIconTimer ) { + KillTimer( Global.hWndMain, Global.idIconTimer ); + Global.idIconTimer = 0; + } + return( FALSE ); + } + + case SIZE_MAXIMIZED: + Profile.fMaximized = TRUE; + Profile.fMinimized = FALSE; + Profile.xPos = Global.xPosOld; + Profile.yPos = Global.yPosOld; + return( FALSE ); + + case SIZE_MINIMIZED: + Profile.fMinimized = TRUE; + Profile.fMaximized = FALSE; + Profile.xPos = Global.xPosOld; + Profile.yPos = Global.yPosOld; + Global.idIconTimer = SetTimer( Global.hWndMain, 1, + TIMEOUT_ANIMATED_ICON, TimerProc ); + return( FALSE ); - return( NULL ); + } + return( DefWindowProc(hWnd, uMsg, wParam, lParam) ); + //-- keep track of window position so it can be saved case WM_MOVE: { RECT rect; - GetWindowRect( hWndMain, &rect ); - xPosOld = xPos; - yPosOld = yPos; - xPos = (int) rect.left; - yPos = (int) rect.top; - return( NULL ); + GetWindowRect( Global.hWndMain, &rect ); + Global.xPosOld = Profile.xPos; + Global.yPosOld = Profile.yPos; + Profile.xPos = (INT) rect.left; + Profile.yPos = (INT) rect.top; + return( FALSE ); } + //-- colorize the debug event listbox case WM_CTLCOLORLISTBOX: { LOGBRUSH LogBrush; LogBrush.lbStyle = BS_SOLID; - LogBrush.lbColor = rgbBkColor; - LogBrush.lbHatch = NULL; + LogBrush.lbColor = Profile.rgbBackColor; + LogBrush.lbHatch = (LONG) NULL; - SetTextColor( (HDC) wParam, rgbColor ); - SetBkColor( (HDC) wParam, rgbBkColor ); + SetTextColor( (HDC) wParam, Profile.rgbForeColor ); + SetBkColor( (HDC) wParam, Profile.rgbBackColor ); return( (LPARAM) CreateBrushIndirect( &LogBrush ) ); } + //-- check if a debuggee is still active, save profile settings case WM_CLOSE: - if( ActiveProcesses ) { + if( Global.dwActiveDebuggees ) { TCHAR szExitBoxTitle[64]; TCHAR szExitBoxText[256]; - LoadString( hInstance, IDS_EXIT_BOX_TITLE, szExitBoxTitle, - sizeof(szExitBoxTitle) ); - LoadString( hInstance, IDS_EXIT_BOX_TEXT, szExitBoxText, - sizeof(szExitBoxText) ); + LoadString( Global.hInstance, IDS_EXIT_BOX_TITLE, szExitBoxTitle, + sizeof(szExitBoxTitle)/sizeof(TCHAR) ); + LoadString( Global.hInstance, IDS_EXIT_BOX_TEXT, szExitBoxText, + sizeof(szExitBoxText)/sizeof(TCHAR) ); if ( MessageBox( hWnd, szExitBoxText, szExitBoxTitle, MB_YESNO | MB_ICONEXCLAMATION ) == IDNO ) - return( NULL ); + return( FALSE ); } //-- store location information to private profile data - WritePrivateProfileSettings( szAppTitle, szIniPathName ); + WritePrivateProfileSettings( Global.szAppName, szIniPathName, &Profile ); - DestroyWindow( hWndTextButtonBar ); - DestroyWindow( hWndDebugList ); - DestroyWindow( hWndMain ); + DestroyWindow( Global.hWndToolBar ); + DestroyWindow( Global.hWndListBox ); + DestroyWindow( Global.hWndMain ); - return( NULL ); + return( FALSE ); case WM_DESTROY: - if( fHelpUsed ) + if( Global.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,156 +443,187 @@ 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 ) { - static LPCTSTR lpszAboutDlgBox = (LPCTSTR) "AboutDlgBox"; - static LPCTSTR lpszAttachDlgBox = (LPCTSTR) "AttachDlgBox"; - static LPCTSTR lpszPreferencesDlgBox = (LPCTSTR) "PreferencesDlgBox"; + static LPCTSTR lpszAboutDlgBox = TEXT( "AboutDlgBox" ); + static LPCTSTR lpszAttachDlgBox = TEXT( "AttachDlgBox" ); + static LPCTSTR lpszPreferencesDlgBox = TEXT( "PreferencesDlgBox" ); 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 ); + //-- user requests to open a new debuggee + case IDM_FILE_OPEN: { + static TCHAR szDebuggeeFileName[MAX_PATH]; + + if( Global.dwActiveDebuggees ) { + MaxDebuggeesMessageBox( Global.hWndMain ); return( FALSE ); } - if( !OpenDebugee( &pi, &si ) ) { - // handle cancel condition + if( !GetDebuggeeFileName( szDebuggeeFileName, hWnd ) ) { + return( FALSE ); } else { - if( fClearOnNew ) { - SendMessage( hWndDebugList, LB_RESETCONTENT, 0, 0 ); - MaxStrLen = 0; + if( Profile.fClearOnNew ) { + SendMessage( Global.hWndListBox, LB_RESETCONTENT, 0, 0 ); + Global.MaxStrLen = 0; } + StartDebuggee( szDebuggeeFileName, Global.hWndListBox ); } - return(NULL); + return( FALSE ); + } + //-- user requests to attach to an existing process case IDM_FILE_ATTACH: - if( ActiveProcesses ) { - MessageBox( hWndMain, - (LPTSTR) "This build of DEB is limited to\n" - "debugging only one process at a time.", - (LPTSTR) "Cannot Attach to Debugee", - MB_OK | MB_ICONEXCLAMATION ); + if( Global.dwActiveDebuggees ) { + MaxDebuggeesMessageBox( Global.hWndMain ); return( FALSE ); } - if( !DialogBox( hInstance, lpszAttachDlgBox, hWnd, + if( !DialogBox( Global.hInstance, lpszAttachDlgBox, hWnd, (DLGPROC) AttachDlgProc ) ) { - // handle cancel condition + // handle cancel condition... } else { - if( fClearOnNew ) { - SendMessage( hWndDebugList, LB_RESETCONTENT, 0, 0 ); - MaxStrLen = 0; + if( Profile.fClearOnNew ) { + SendMessage( Global.hWndListBox, LB_RESETCONTENT, 0, 0 ); + Global.MaxStrLen = 0; } } - return(NULL); + return( FALSE ); + //-- copy listbox contents to the clipboard and clear the listbox case IDM_EDIT_CUT: - CopyListBoxToClipboard( hWndDebugList, MaxStrLen ); + CopyListBoxToClipboard( Global.hWndListBox, Global.MaxStrLen ); SendMessage( hWnd, WM_COMMAND, IDM_EDIT_DELETE, 0 ); - return( NULL ); + return( FALSE ); + //-- copy listbox contents to the clipboard case IDM_EDIT_COPY: { - CopyListBoxToClipboard( hWndDebugList, MaxStrLen ); - return( NULL ); + CopyListBoxToClipboard( Global.hWndListBox, Global.MaxStrLen ); + return( FALSE ); } + //-- clear the contents of the listbox case IDM_EDIT_DELETE: - SendMessage( hWndDebugList, LB_RESETCONTENT, 0, 0 ); - MaxStrLen = 0; - return( NULL ); + SendMessage( Global.hWndListBox, LB_RESETCONTENT, 0, 0 ); + Global.MaxStrLen = 0; + return( FALSE ); + //-- user requests a new font for the listbox case IDM_OPTIONS_FONT: - if( !ChooseNewFont( hWndDebugList ) ) { - // handle cancel condition + if( !ChooseNewFont( Global.hWndListBox ) ) { + // handle cancel condition... } - return( NULL ); + return( FALSE ); + //-- user requests a new background color for the listbox case IDM_OPTIONS_COLOR: - ChooseNewBkColor( hWndDebugList ); - return( NULL ); + ChooseNewBackColor( Global.hWndListBox ); + return( FALSE ); + //-- invoke the preferences dialog box case IDM_OPTIONS_PREFERENCES: - DialogBox( hInstance, lpszPreferencesDlgBox, hWnd, + DialogBox( Global.hInstance, lpszPreferencesDlgBox, hWnd, (DLGPROC) PreferencesDlgProc ); - return( NULL ); + return( FALSE ); + //-- toggle the toolbar on or off case IDM_OPTIONS_TOOLBAR: - if( fToolBar ) { - fToolBar = 0; - CheckMenuItem( GetMenu(hWndMain), IDM_OPTIONS_TOOLBAR, MF_UNCHECKED ); - ShowWindow( hWndTextButtonBar, SW_HIDE ); - SendWmSizeMessage( hWndMain ); + if( Profile.fToolBar ) { + Profile.fToolBar = 0; + CheckMenuItem( GetMenu(Global.hWndMain), IDM_OPTIONS_TOOLBAR, + MF_UNCHECKED ); + ShowWindow( Global.hWndToolBar, SW_HIDE ); + SendWmSizeMessage( Global.hWndMain ); } else { - fToolBar = 1; - CheckMenuItem( GetMenu(hWndMain), IDM_OPTIONS_TOOLBAR, MF_CHECKED ); - ShowWindow( hWndTextButtonBar, SW_SHOW ); - SendWmSizeMessage( hWndMain ); + Profile.fToolBar = 1; + CheckMenuItem( GetMenu(Global.hWndMain), IDM_OPTIONS_TOOLBAR, + MF_CHECKED ); + ShowWindow( Global.hWndToolBar, SW_SHOW ); + SendWmSizeMessage( Global.hWndMain ); } - return( NULL ); + return( FALSE ); + //-- toggles whether the used directory is used for the 'open' command case IDM_OPTIONS_SAVEDDIR: - if( fSavedDirectory ) { - fSavedDirectory = 0; - CheckMenuItem( GetMenu(hWndMain), IDM_OPTIONS_SAVEDDIR, + if( Profile.fSavedDirectory ) { + Profile.fSavedDirectory = 0; + CheckMenuItem( GetMenu(Global.hWndMain), IDM_OPTIONS_SAVEDDIR, MF_UNCHECKED ); } else { - fSavedDirectory = 1; - CheckMenuItem( GetMenu(hWndMain), IDM_OPTIONS_SAVEDDIR, + Profile.fSavedDirectory = 1; + CheckMenuItem( GetMenu(Global.hWndMain), IDM_OPTIONS_SAVEDDIR, MF_CHECKED ); } - return( NULL ); + return( FALSE ); + //-- toggles the 'save on exit' feature case IDM_OPTIONS_SAVEONEXIT: - if( fSaveOnExit ) { - fSaveOnExit = 0; - CheckMenuItem( GetMenu(hWndMain), IDM_OPTIONS_SAVEONEXIT, + if( Profile.fSaveOnExit ) { + Profile.fSaveOnExit = 0; + CheckMenuItem( GetMenu(Global.hWndMain), IDM_OPTIONS_SAVEONEXIT, MF_UNCHECKED ); } else { - fSaveOnExit = 1; - CheckMenuItem( GetMenu(hWndMain), IDM_OPTIONS_SAVEONEXIT, + Profile.fSaveOnExit = 1; + CheckMenuItem( GetMenu(Global.hWndMain), IDM_OPTIONS_SAVEONEXIT, MF_CHECKED ); } - return( NULL ); + return( FALSE ); + //-- store location information to private profile data now + case IDM_OPTIONS_SAVENOW: { + BOOL fOldSaveOnExit = Profile.fSaveOnExit; + BOOL fOldSavePreferences = Profile.fSavePreferences; + + Profile.fSaveOnExit = TRUE; + Profile.fSavePreferences = TRUE; + WritePrivateProfileSettings( Global.szAppName, szIniPathName, &Profile ); + Profile.fSaveOnExit = fOldSaveOnExit; + Profile.fSavePreferences = fOldSavePreferences; + return( FALSE ); + } + + //-- invoke help and display the contents panel case IDM_HELP_CONTENTS: - fHelpUsed = TRUE; - WinHelp( hWnd, (LPCTSTR) szHelpPathName, HELP_INDEX, (DWORD) NULL ); - return( NULL ); + Global.fHelpUsed = TRUE; + WinHelp( hWnd, (LPCTSTR) szHelpPathName, HELP_CONTENTS, (DWORD) NULL ); + return( FALSE ); + //-- search the help indexes case IDM_HELP_SEARCH: - fHelpUsed = TRUE; - WinHelp( hWnd, (LPCTSTR) szHelpPathName, HELP_PARTIALKEY, (DWORD) "" ); - return( NULL ); + Global.fHelpUsed = TRUE; + WinHelp( hWnd, (LPCTSTR) szHelpPathName, HELP_PARTIALKEY, + (DWORD) TEXT( "" ) ); + return( FALSE ); + //-- invoke the main 'how to use' help panel case IDM_HELP_HOWTOUSE: - fHelpUsed = TRUE; + Global.fHelpUsed = TRUE; WinHelp( hWnd, (LPTSTR) NULL, HELP_HELPONHELP, (DWORD) NULL ); - return( NULL ); + return( FALSE ); + //-- display the product information dialog box case IDM_HELP_ABOUT: - DialogBox( hInstance, lpszAboutDlgBox, hWnd, (DLGPROC) AboutDlgProc ); - return( NULL ); + DialogBox( Global.hInstance, lpszAboutDlgBox, hWnd, + (DLGPROC) AboutDlgProc ); + return( FALSE ); + //-- the usr requests to terminate the app case IDM_FILE_EXIT: - SendMessage( hWndMain, WM_CLOSE, 0, 0 ); - return( NULL ); + SendMessage( Global.hWndMain, WM_CLOSE, 0, 0 ); + return( FALSE ); default: - return( DefWindowProc(hWnd, uMsg, wParam, lParam) ); + return( DefWindowProc(hWnd, uMsg, wParam, lParam) ); } + return( FALSE ); } @@ -506,38 +634,69 @@ 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 PreferencesDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - UNREFERENCED_PARAMETER( lParam ); - switch( uMsg ) { case WM_COMMAND: switch( LOWORD(wParam) ) { case IDOK: - if( SendMessage( GetDlgItem( hDlg, IDC_DEBUG_PROCESS), BM_GETCHECK, 0, 0 ) ) - DebugMode = DEBUG_PROCESS; - if( SendMessage( GetDlgItem( hDlg, IDC_DEBUG_ONLY_THIS_PROCESS), BM_GETCHECK, 0, 0 ) ) - DebugMode = DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS; - if( SendMessage( GetDlgItem( hDlg, IDC_IDLE_PRIORITY_CLASS), BM_GETCHECK, 0, 0 ) ) - DebugeePriority = IDLE_PRIORITY_CLASS; - if( SendMessage( GetDlgItem( hDlg, IDC_NORMAL_PRIORITY_CLASS), BM_GETCHECK, 0, 0 ) ) - DebugeePriority = NORMAL_PRIORITY_CLASS; - if( SendMessage( GetDlgItem( hDlg, IDC_HIGH_PRIORITY_CLASS), BM_GETCHECK, 0, 0 ) ) - DebugeePriority = HIGH_PRIORITY_CLASS; - fClearOnNew = (BOOL) SendMessage( GetDlgItem( hDlg, IDC_CLEAR_ON_NEW), - BM_GETCHECK, 0 , 0 ); - fVerbose = (BOOL) SendMessage( GetDlgItem( hDlg, IDC_VERBOSE), - BM_GETCHECK, 0 , 0 ); - fShowSymbols = (BOOL) SendMessage( GetDlgItem( hDlg, IDC_SHOW_SYMBOLS), - BM_GETCHECK, 0 , 0 ); - fSavePreferences = (BOOL) SendMessage( GetDlgItem( hDlg, IDC_SAVE_PREFERENCES), - BM_GETCHECK, 0 , 0 ); + + //-- Debugger Setting Group + if( SendMessage( GetDlgItem( hDlg, IDC_DEBUG_PROCESS), + BM_GETCHECK, 0, 0 ) ) + Profile.DebugMode = DEBUG_PROCESS; + if( SendMessage( GetDlgItem( hDlg, IDC_DEBUG_ONLY_THIS_PROCESS), + BM_GETCHECK, 0, 0 ) ) + Profile.DebugMode = DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS; + + //-- Debuggee Priority Group + if( SendMessage( GetDlgItem( hDlg, IDC_IDLE_PRIORITY_CLASS), + BM_GETCHECK, 0, 0 ) ) + Profile.DebuggeePriority = IDLE_PRIORITY_CLASS; + if( SendMessage( GetDlgItem( hDlg, IDC_NORMAL_PRIORITY_CLASS), + BM_GETCHECK, 0, 0 ) ) + Profile.DebuggeePriority = NORMAL_PRIORITY_CLASS; + if( SendMessage( GetDlgItem( hDlg, IDC_HIGH_PRIORITY_CLASS), + BM_GETCHECK, 0, 0 ) ) + Profile.DebuggeePriority = HIGH_PRIORITY_CLASS; + if( SendMessage( GetDlgItem( hDlg, IDC_REALTIME_PRIORITY_CLASS), + BM_GETCHECK, 0, 0 ) ) + Profile.DebuggeePriority = REALTIME_PRIORITY_CLASS; + + //-- Miscellaneous Options Group + Profile.fClearOnNew = (BOOL) SendMessage( + GetDlgItem( hDlg, IDC_CLEAR_ON_NEW), + BM_GETCHECK, 0 , 0 ); + Profile.fVerbose = (BOOL) SendMessage( + GetDlgItem( hDlg, IDC_VERBOSE), + BM_GETCHECK, 0 , 0 ); + Profile.fShowSymbols = (BOOL) SendMessage( + GetDlgItem( hDlg, IDC_SHOW_SYMBOLS), + BM_GETCHECK, 0 , 0 ); + + //- Debug Error Level Group + if( SendMessage( GetDlgItem( hDlg, IDC_DEBUG_MODE_NONE), + BM_GETCHECK, 0, 0 ) ) + Profile.DebugErrorLevel = 0; + if( SendMessage( GetDlgItem( hDlg, IDC_DEBUG_MODE_ERROR), + BM_GETCHECK, 0, 0 ) ) + Profile.DebugErrorLevel = SLE_ERROR; + if( SendMessage( GetDlgItem( hDlg, IDC_DEBUG_MODE_MINORERROR), + BM_GETCHECK, 0, 0 ) ) + Profile.DebugErrorLevel = SLE_MINORERROR; + if( SendMessage( GetDlgItem( hDlg, IDC_DEBUG_MODE_WARNING), + BM_GETCHECK, 0, 0 ) ) + Profile.DebugErrorLevel = SLE_WARNING; + + Profile.fSavePreferences = (BOOL) SendMessage( + GetDlgItem( hDlg, + IDC_SAVE_PREFERENCES), + BM_GETCHECK, 0 , 0 ); EndDialog( hDlg, TRUE ); return( TRUE ); @@ -553,7 +712,8 @@ PreferencesDlgProc( HWND hDlg, UINT uMsg case WM_INITDIALOG: - switch( DebugMode ) { + //-- Debugger Setting Group + switch( Profile.DebugMode ) { case DEBUG_PROCESS: SendMessage( GetDlgItem( hDlg, IDC_DEBUG_PROCESS), @@ -566,7 +726,8 @@ PreferencesDlgProc( HWND hDlg, UINT uMsg break; } - switch( DebugeePriority ) { + //-- Debuggee Priority Group + switch( Profile.DebuggeePriority ) { case IDLE_PRIORITY_CLASS: SendMessage( GetDlgItem( hDlg, IDC_IDLE_PRIORITY_CLASS), @@ -582,21 +743,54 @@ PreferencesDlgProc( HWND hDlg, UINT uMsg SendMessage( GetDlgItem( hDlg, IDC_HIGH_PRIORITY_CLASS), BM_SETCHECK, 1, 0); break; + + case REALTIME_PRIORITY_CLASS: + SendMessage( GetDlgItem( hDlg, IDC_REALTIME_PRIORITY_CLASS), + BM_SETCHECK, 1, 0); + break; + } + //-- Miscellaneous Options Group SendMessage( GetDlgItem( hDlg, IDC_CLEAR_ON_NEW), BM_SETCHECK, - fClearOnNew, 0 ); + Profile.fClearOnNew, 0 ); SendMessage( GetDlgItem( hDlg, IDC_VERBOSE), BM_SETCHECK, - fVerbose, 0 ); + Profile.fVerbose, 0 ); SendMessage( GetDlgItem( hDlg, IDC_SHOW_SYMBOLS), BM_SETCHECK, - fShowSymbols, 0 ); + Profile.fShowSymbols, 0 ); SendMessage( GetDlgItem( hDlg, IDC_SAVE_PREFERENCES), BM_SETCHECK, - fSavePreferences, 0 ); + Profile.fSavePreferences, 0 ); + + //- Debug Error Level Group + switch( Profile.DebugErrorLevel ) { + + case 0: + SendMessage( GetDlgItem( hDlg, IDC_DEBUG_MODE_NONE), + BM_SETCHECK, 1, 0); + break; + + case SLE_ERROR: + SendMessage( GetDlgItem( hDlg, IDC_DEBUG_MODE_ERROR), + BM_SETCHECK, 1, 0); + break; + + case SLE_MINORERROR: + SendMessage( GetDlgItem( hDlg, IDC_DEBUG_MODE_MINORERROR), + BM_SETCHECK, 1, 0); + break; + + case SLE_WARNING: + SendMessage( GetDlgItem( hDlg, IDC_DEBUG_MODE_WARNING), + BM_SETCHECK, 1, 0); + break; + + } return( TRUE ); } return( FALSE ); + UNREFERENCED_PARAMETER( lParam ); } @@ -604,44 +798,34 @@ PreferencesDlgProc( HWND hDlg, UINT uMsg // FUNCTION : AttachDlgProc( HWND, UINT, WPARAM, LPARAM ) // PURPOSE : Processes messages for "Attach" dialog box // MESSAGES : -// WM_INITDIALOG - initialize dialog box // WM_COMMAND - Input received +// WM_INITDIALOG - initialize dialog box // COMMENTS : -// // Wait for user to click on "Ok" button, then close the dialog box. // ************************************************************************ BOOL CALLBACK AttachDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - static HWND hWndProcessList; - static DWORD idDebugEventThread; - static DWORD dwProcessId; - static LONG idx; - - UNREFERENCED_PARAMETER( lParam ); + static HWND hWndProcessList; switch( uMsg ) { case WM_COMMAND: switch( LOWORD(wParam) ) { - case IDOK: - idx = (UINT) SendMessage( hWndProcessList, LB_GETCURSEL, - NULL, NULL ); + case IDOK: { + LONG Index; + DWORD dwProcessId; + + Index = (UINT) SendMessage( hWndProcessList, LB_GETCURSEL, + (WPARAM) NULL, (LPARAM) NULL ); dwProcessId = (DWORD) SendMessage( hWndProcessList, LB_GETITEMDATA, - idx, NULL ); - - //-- create debug event processing thread and attach to the process - CreateThread( - (LPSECURITY_ATTRIBUTES) NULL, - (DWORD) 0, - (LPTHREAD_START_ROUTINE) DebugEventThread, - (LPVOID) dwProcessId, - (DWORD) NULL, - (LPDWORD) &idDebugEventThread); + (WPARAM) Index, (LPARAM) NULL ); + AttachToDebuggee( dwProcessId, Global.hWndListBox ); EndDialog( hDlg, TRUE ); return( TRUE ); + } case IDCANCEL: EndDialog( hDlg, FALSE ); @@ -651,9 +835,7 @@ AttachDlgProc( HWND hDlg, UINT uMsg, WPA return( TRUE ); } - switch( HIWORD( wParam ) ) { - case LBN_DBLCLK: SendMessage( hDlg, WM_COMMAND, (WPARAM) IDOK, (LPARAM) 0L ); return( TRUE ); @@ -670,47 +852,67 @@ AttachDlgProc( HWND hDlg, UINT uMsg, WPA } return( FALSE ); + UNREFERENCED_PARAMETER( lParam ); } -// ************************************************************************ +// ************************************************************************** // FUNCTION : AboutDlgProc( HWND, UINT, WPARAM, LPARAM ) // PURPOSE : Processes messages for "About" dialog box // MESSAGES : -// WM_INITDIALOG - initialize dialog box // WM_COMMAND - Input received -// COMMENTS : -// No initialization is needed for this particular dialog box, but TRUE -// must be returned to Windows. -// +// IDOK - OK button selected +// IDCANCEL - Cancel button selected +// ... +// WM_INITDIALOG - initialize dialog box +// WM_CLOSE - close the dialog box +// ... +// COMMENTS: +// No initialization is needed for this particular dialog box. +// In this case, TRUE must be returned to Windows. // Wait for user to click on "Ok" button, then close the dialog box. -// ************************************************************************ +// ************************************************************************** BOOL CALLBACK AboutDlgProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) { - UNREFERENCED_PARAMETER( lParam ); - switch( uMsg ) { case WM_COMMAND: switch( LOWORD(wParam) ) { case IDOK: + Global.fAboutBox = FALSE; EndDialog( hDlg, TRUE ); return( TRUE ); + + case IDCANCEL: + Global.fAboutBox = FALSE; + EndDialog( hDlg, FALSE ); + return( FALSE ); + } break; case WM_INITDIALOG: + Global.hDlgAbout = hDlg; + Global.fAboutBox = TRUE; + Global.idIconTimer = SetTimer( hDlg, 1, TIMEOUT_ANIMATED_ICON, + TimerProc ); // for the animated icon return( TRUE ); case WM_CLOSE: + Global.fAboutBox = FALSE; EndDialog( hDlg, TRUE ); return( TRUE ); + case WM_DESTROY: + KillTimer( hDlg, Global.idIconTimer ); + Global.idIconTimer = 0; + return( TRUE ); } return( FALSE ); + UNREFERENCED_PARAMETER( lParam ); } @@ -728,11 +930,54 @@ NewListBoxWndProc( HWND hWnd, UINT uMsg, case WM_NCLBUTTONDOWN: if( wParam == HTCAPTION ) { SetFocus( hWnd ); - return( NULL ); + return( FALSE ); } else break; } - return( CallWindowProc( OldListBoxWndProc, hWnd, uMsg, wParam, lParam) ); + return( CallWindowProc( Global.OldListBoxWndProc, hWnd, uMsg, wParam, lParam) ); +} + + +// ************************************************************************ +// FUNCTION : TimerProc( HWND, UINT, UINT, DWORD ) +// PURPOSE : +// COMMENTS : +// ************************************************************************ +VOID CALLBACK +TimerProc( HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime ) +{ + #define NUM_ICONS 8 + + static UINT uIconNumber = 0; + static HWND hWndIcon = NULL; + static HWND hWndIconOld = NULL; + static LPCTSTR lpszIconNames[NUM_ICONS] = { + TEXT( "DebugIcon1" ), TEXT( "DebugIcon2" ), + TEXT( "DebugIcon3" ), TEXT( "DebugIcon4" ), + TEXT( "DebugIcon5" ), TEXT( "DebugIcon6" ), + TEXT( "DebugIcon7" ), TEXT( "DebugIcon8" ) }; + + if( (++uIconNumber) >= NUM_ICONS ) + uIconNumber = 0; + + if( Global.fAboutBox ) { + hWndIconOld = hWndIcon; + hWndIcon = CreateIconWindow( Global.hDlgAbout, lpszIconNames[uIconNumber] ); + if( hWndIcon != NULL ) { + DestroyWindow( hWndIconOld ); + } + } + + if( IsIconic( Global.hWndMain ) ) { + InvalidateRect( Global.hWndMain, NULL, TRUE ); + Global.hIconCurrent = LoadIcon( Global.hInstance, lpszIconNames[uIconNumber] ); + } + + return; + UNREFERENCED_PARAMETER( hWnd ); + UNREFERENCED_PARAMETER( uMsg ); + UNREFERENCED_PARAMETER( idEvent ); + UNREFERENCED_PARAMETER( dwTime ); }