|
|
1.1.1.3 ! root 1: ! 2: /******************************************************************************\ ! 3: * This is a part of the Microsoft Source Code Samples. ! 4: * Copyright (C) 1993 Microsoft Corporation. ! 5: * All rights reserved. ! 6: * This source code is only intended as a supplement to ! 7: * Microsoft Development Tools and/or WinHelp documentation. ! 8: * See these sources for detailed information regarding the ! 9: * Microsoft samples programs. ! 10: \******************************************************************************/ ! 11: 1.1.1.2 root 12: // ************************************************************************ 13: // MODULE : DEBMisc.C 1.1 root 14: // PURPOSE : Miscellaneous support functions for the Debug Event Browser 15: // FUNCTIONS : 1.1.1.3 ! root 16: // StartDebuggee() - starts a new debuggee process ! 17: // AttachToDebuggee() - attaches to an existing process 1.1 root 18: // EnumProcessListFunc() - enumeration func for active processes 1.1.1.3 ! root 19: // GetDebuggeeFileName() - get the name of a debugee file to open ! 20: // ChooseNewFont() - choose a new font ! 21: // ChooseNewBackColor() - choose a new background color ! 22: // MakeCommonDebugEventString() - create common debug event info string ! 23: // CreateTextButtonBar() - create a text button bar ! 24: // CreateIconWindow() - creates the icon window in the dialog 1.1 root 25: // GetPrivateProfileSettings() - gets stored profile settings 26: // WritePrivateProfileSettings() - stores default settings in profile 1.1.1.3 ! root 27: // WritePrivateProfileInt() - opposite of GetPrivateProfileInt() 1.1 root 28: // UpdateMenuSettings() - update menu check marks 1.1.1.3 ! root 29: // OutOfMemoryMessageBox() - displays an out of memory message box ! 30: // MaxDebuggeesMessageBox() - displays max debuggees exceeded ! 31: // ErrorMessageBox() - displays an error message box 1.1 root 32: // SubclassWindow() - generic window subclass func 1.1.1.3 ! root 33: // SendWmSizeMessage() - sends WM_SIZE with current size 1.1 root 34: // GetPathFromFullPathName() - extracts path from a pathname 1.1.1.3 ! root 35: // CopyListBoxToClipboard() - copies a listbox into the clipboard ! 36: // ListBoxInsert() - insert a string into a listbox ! 37: // ListBoxPrintF() - printf for listboxes ! 38: // StringPrintF() - formats a string buffer ! 39: // StringAppendF() - appends a formated string 1.1 root 40: // COMMENTS : 1.1.1.2 root 41: // 1.1 root 42: // ************************************************************************ 1.1.1.3 ! root 43: #define STRICT // enable strict typing ! 44: #include <Windows.H> // required for all Windows applications ! 45: #include <CommDlg.H> // GetOpenFileName(), ChooseFont(), etc. ! 46: #include <Dlgs.H> // templates and defines for the common dialogs ! 47: #include <StdArg.H> // va_list, va_start() ! 48: ! 49: #include "LinkList.H" // ! 50: #include "ToolBar.H" // ! 51: #include "DEBMisc.H" // 1.1 root 52: 53: 54: // ************************************************************************ 1.1.1.3 ! root 55: // FUNCTION : StartDebuggee( LPTSTR, HWND ) ! 56: // PURPOSE : starts a new debuggee process given a filename 1.1.1.2 root 57: // COMMENTS : 1.1.1.3 ! root 58: // Return TRUE on success else FALSE. 1.1.1.2 root 59: // ************************************************************************ 1.1.1.3 ! root 60: BOOL ! 61: StartDebuggee( LPTSTR lpszDebuggeeFileName, HWND hWndListBox ) 1.1.1.2 root 62: { 1.1.1.3 ! root 63: static PDEB_STARTUP_INFO pDebStartupInfo; ! 64: static BOOL fFirstTime = TRUE; 1.1.1.2 root 65: 1.1.1.3 ! root 66: static TCHAR szDebuggeeTitle[128]; 1.1.1.2 root 67: 1.1.1.3 ! root 68: HANDLE hDebugEventThread; ! 69: DWORD idDebugEventThread; ! 70: ! 71: //-- Load resource strings and init the OpenFileName struct ! 72: // (do this only one time) ! 73: if( fFirstTime ) { ! 74: fFirstTime = FALSE; ! 75: LoadString( NULL, IDS_OFN_DEBUGGEE_TITLE, szDebuggeeTitle, ! 76: sizeof(szDebuggeeTitle)/sizeof(TCHAR) ); ! 77: } ! 78: ! 79: //-- allocate the Debuggee Information structure ! 80: pDebStartupInfo = NULL; ! 81: pDebStartupInfo = (PDEB_STARTUP_INFO) VirtualAlloc( ! 82: pDebStartupInfo, ! 83: sizeof( DEB_STARTUP_INFO ), ! 84: MEM_RESERVE | MEM_COMMIT, ! 85: PAGE_READWRITE ); ! 86: ! 87: //-- init the StartupInfo struct ! 88: (pDebStartupInfo->StartupInfo).cb = sizeof( STARTUPINFO ); ! 89: (pDebStartupInfo->StartupInfo).lpDesktop = NULL; ! 90: (pDebStartupInfo->StartupInfo).lpTitle = szDebuggeeTitle; ! 91: (pDebStartupInfo->StartupInfo).dwX = 0; ! 92: (pDebStartupInfo->StartupInfo).dwY = 0; ! 93: (pDebStartupInfo->StartupInfo).dwXSize = 0; ! 94: (pDebStartupInfo->StartupInfo).dwYSize = 0; ! 95: (pDebStartupInfo->StartupInfo).dwFlags = (DWORD) NULL; ! 96: (pDebStartupInfo->StartupInfo).wShowWindow = SW_SHOWDEFAULT; ! 97: ! 98: (pDebStartupInfo->ProcessInfo).hProcess = NULL; ! 99: ! 100: //-- init other debuggee info ! 101: pDebStartupInfo->fActive = FALSE; ! 102: pDebStartupInfo->dwProcessId = (DWORD) NULL; ! 103: pDebStartupInfo->lpstrFileName = NULL; ! 104: pDebStartupInfo->lpstrPathName = lpszDebuggeeFileName; ! 105: pDebStartupInfo->hWndListBox = hWndListBox; ! 106: ! 107: //-- now start and detach the debug event processing thread ! 108: if( !( hDebugEventThread = CreateThread( ! 109: (LPSECURITY_ATTRIBUTES) NULL, ! 110: (DWORD) 0, ! 111: (LPTHREAD_START_ROUTINE) DebugEventThread, ! 112: (LPVOID) pDebStartupInfo, ! 113: (DWORD) NULL, ! 114: (LPDWORD) &idDebugEventThread) ) ) { ! 115: ! 116: VirtualFree( pDebStartupInfo, 0, MEM_RELEASE ); ! 117: return( FALSE ); ! 118: } ! 119: else{ ! 120: CloseHandle( hDebugEventThread ); ! 121: } 1.1.1.2 root 122: 1.1.1.3 ! root 123: return( TRUE ); 1.1.1.2 root 124: } 125: 126: 127: // ************************************************************************ 1.1.1.3 ! root 128: // FUNCTION : AttachToDebuggee( DWORD, HWND ) ! 129: // PURPOSE : attaches to a currently running process ! 130: // COMMENTS : ! 131: // Return TRUE on success else FALSE. 1.1 root 132: // ************************************************************************ 1.1.1.3 ! root 133: BOOL ! 134: AttachToDebuggee( DWORD dwProcessId, HWND hWndListBox ) 1.1 root 135: { 1.1.1.3 ! root 136: static PDEB_STARTUP_INFO pDebStartupInfo; ! 137: static BOOL fFirstTime = TRUE; 1.1 root 138: 1.1.1.3 ! root 139: static TCHAR szDebuggeeTitle[128]; 1.1 root 140: 1.1.1.3 ! root 141: HANDLE hDebugEventThread; ! 142: DWORD idDebugEventThread; 1.1 root 143: 1.1.1.3 ! root 144: //-- Load resource strings and init the OpenFileName struct ! 145: // (do this only one time) ! 146: if( fFirstTime ) { ! 147: fFirstTime = FALSE; ! 148: LoadString( NULL, IDS_OFN_DEBUGGEE_TITLE, szDebuggeeTitle, ! 149: sizeof(szDebuggeeTitle)/sizeof(TCHAR) ); ! 150: } 1.1 root 151: 1.1.1.3 ! root 152: //-- allocate the Debuggee Information structure ! 153: pDebStartupInfo = NULL; ! 154: pDebStartupInfo = (PDEB_STARTUP_INFO) VirtualAlloc( ! 155: pDebStartupInfo, ! 156: sizeof( DEB_STARTUP_INFO ), ! 157: MEM_RESERVE | MEM_COMMIT, ! 158: PAGE_READWRITE ); ! 159: ! 160: //-- init the StartupInfo struct ! 161: (pDebStartupInfo->StartupInfo).cb = sizeof( STARTUPINFO ); ! 162: (pDebStartupInfo->StartupInfo).lpDesktop = NULL; ! 163: (pDebStartupInfo->StartupInfo).lpTitle = szDebuggeeTitle; ! 164: (pDebStartupInfo->StartupInfo).dwX = 0; ! 165: (pDebStartupInfo->StartupInfo).dwY = 0; ! 166: (pDebStartupInfo->StartupInfo).dwXSize = 0; ! 167: (pDebStartupInfo->StartupInfo).dwYSize = 0; ! 168: (pDebStartupInfo->StartupInfo).dwFlags = (DWORD) NULL; ! 169: (pDebStartupInfo->StartupInfo).wShowWindow = SW_SHOWDEFAULT; ! 170: ! 171: (pDebStartupInfo->ProcessInfo).hProcess = NULL; ! 172: ! 173: //-- init other debuggee info ! 174: pDebStartupInfo->fActive = TRUE; ! 175: pDebStartupInfo->dwProcessId = dwProcessId; ! 176: pDebStartupInfo->lpstrFileName = NULL; ! 177: pDebStartupInfo->lpstrPathName = NULL; ! 178: pDebStartupInfo->hWndListBox = hWndListBox; 1.1 root 179: 1.1.1.3 ! root 180: //-- now start and detach the debug event processing thread ! 181: if( !( hDebugEventThread = CreateThread( ! 182: (LPSECURITY_ATTRIBUTES) NULL, ! 183: (DWORD) 0, ! 184: (LPTHREAD_START_ROUTINE) DebugEventThread, ! 185: (LPVOID) pDebStartupInfo, ! 186: (DWORD) NULL, ! 187: (LPDWORD) &idDebugEventThread) ) ) { 1.1 root 188: 1.1.1.3 ! root 189: VirtualFree( pDebStartupInfo, 0, MEM_RELEASE ); ! 190: return( FALSE ); ! 191: } ! 192: else{ ! 193: CloseHandle( hDebugEventThread ); ! 194: } 1.1 root 195: 1.1.1.3 ! root 196: return( TRUE ); ! 197: } 1.1 root 198: 199: 1.1.1.3 ! root 200: // ************************************************************************ ! 201: // FUNCTION : EnumProcessListFunc( HWND, LPARAM ) ! 202: // PURPOSE : Callback function for EnumWindows ! 203: // COMMENTS : Inserts found window title strings into the listbox. ! 204: // Return !NULL to continue enumeration. ! 205: // ************************************************************************ ! 206: BOOL CALLBACK ! 207: EnumProcessListFunc( HWND hWnd, LPARAM lParam ) ! 208: { ! 209: static DWORD dwCurrentProcessId; ! 210: static BOOL fFirstTime = TRUE; ! 211: static LONG MaxStrLen = 0; ! 212: static TCHAR TextBuffer[256]; 1.1 root 213: 1.1.1.3 ! root 214: if( fFirstTime ) { ! 215: fFirstTime = FALSE; ! 216: dwCurrentProcessId = GetCurrentProcessId(); ! 217: } 1.1 root 218: 1.1.1.3 ! root 219: if( hWnd ) { ! 220: GetWindowText( hWnd, (LPTSTR) &TextBuffer, sizeof(TextBuffer) ); ! 221: if( *TextBuffer ) { ! 222: DWORD dwProcessId; ! 223: ! 224: GetWindowThreadProcessId( hWnd, &dwProcessId ); ! 225: if( dwProcessId != dwCurrentProcessId ) { ! 226: LONG Index; ! 227: HWND hWndListBox = (HWND) lParam; ! 228: ! 229: Index = ListBoxInsert( hWndListBox, &MaxStrLen, TextBuffer ); ! 230: SendMessage( hWndListBox, LB_SETITEMDATA, (WPARAM) Index, ! 231: (LPARAM) dwProcessId ); ! 232: } ! 233: } ! 234: } ! 235: ! 236: return( TRUE ); 1.1 root 237: } 238: 239: 240: // ************************************************************************ 1.1.1.3 ! root 241: // FUNCTION : GetDebuggeeFileName( LPTSTR, HWND ) ! 242: // PURPOSE : Get the name of a debugee file to open. ! 243: // COMMENTS : ! 244: // Return TRUE on success else FALSE. 1.1 root 245: // ************************************************************************ 246: BOOL 1.1.1.3 ! root 247: GetDebuggeeFileName( LPTSTR lpszDebuggeeFileName, HWND hWnd ) 1.1 root 248: { 249: static BOOL fFirstTime = TRUE; 1.1.1.3 ! root 250: static TCHAR szFilter[128] = TEXT(""); ! 251: static TCHAR szTitle[32] = TEXT(""); ! 252: static TCHAR szFileTitle[MAX_PATH] = TEXT(""); ! 253: static TCHAR szFile[MAX_PATH] = TEXT(""); ! 254: static TCHAR szDefExt[8] = TEXT(""); 1.1 root 255: static OPENFILENAME OpenFileName; 256: 1.1.1.3 ! root 257: //-- Load resource strings and init the OpenFileName struct 1.1 root 258: // (do this only one time) 259: if( fFirstTime ) { 1.1.1.3 ! root 260: static UINT FilterNameLen; 1.1 root 261: 262: fFirstTime = FALSE; 1.1.1.3 ! root 263: FilterNameLen = (UINT) LoadString( NULL, IDS_OFN_FILTERNAME, ! 264: szFilter, sizeof(szFilter) ); 1.1 root 265: FilterNameLen++; 1.1.1.3 ! root 266: LoadString( NULL, IDS_OFN_FILTER, &szFilter[FilterNameLen], ! 267: sizeof(szFilter)-FilterNameLen ); ! 268: LoadString( NULL, IDS_OFN_TITLE, szTitle, sizeof(szTitle) ); 1.1 root 269: 270: OpenFileName.lStructSize = sizeof(OPENFILENAME); 1.1.1.3 ! root 271: OpenFileName.hwndOwner = hWnd; ! 272: OpenFileName.hInstance = (HANDLE) NULL; ! 273: OpenFileName.lpstrFilter = szFilter; ! 274: OpenFileName.lpstrCustomFilter = NULL; 1.1 root 275: OpenFileName.nMaxCustFilter = (DWORD) NULL; 1.1.1.3 ! root 276: OpenFileName.nFilterIndex = 1L; ! 277: OpenFileName.lpstrFile = szFile; 1.1 root 278: OpenFileName.nMaxFile = sizeof(szFile); 1.1.1.3 ! root 279: OpenFileName.lpstrFileTitle = szFileTitle; 1.1 root 280: OpenFileName.nMaxFileTitle = sizeof(szFileTitle); 1.1.1.3 ! root 281: OpenFileName.lpstrInitialDir = (Profile.fSavedDirectory ? Profile.szInitialDir : NULL); ! 282: OpenFileName.lpstrTitle = (LPTSTR) szTitle; 1.1 root 283: OpenFileName.Flags = OFN_HIDEREADONLY; 284: OpenFileName.nFileOffset = (WORD) NULL; 285: OpenFileName.nFileExtension = (WORD) NULL; 1.1.1.3 ! root 286: OpenFileName.lpstrDefExt = szDefExt; 1.1 root 287: OpenFileName.lCustData = (DWORD) NULL; 288: OpenFileName.lpfnHook = (LPOFNHOOKPROC) NULL; 1.1.1.3 ! root 289: OpenFileName.lpTemplateName = (LPTSTR) NULL; 1.1 root 290: } 291: 1.1.1.3 ! root 292: if( !GetOpenFileName( &OpenFileName ) ) { 1.1 root 293: return( FALSE ); 1.1.1.3 ! root 294: } 1.1 root 295: 296: //-- store recent directory by stripping off the EXE name from the full path 1.1.1.3 ! root 297: GetPathFromFullPathName( (LPTSTR) OpenFileName.lpstrFile, Profile.szInitialDir, ! 298: sizeof(Profile.szInitialDir) ); 1.1 root 299: 1.1.1.3 ! root 300: //-- copy name to return buffer ! 301: lstrcpy( lpszDebuggeeFileName, OpenFileName.lpstrFile ); 1.1.1.2 root 302: 303: return( TRUE ); 1.1 root 304: } 305: 306: 307: // ************************************************************************ 1.1.1.3 ! root 308: // FUNCTION : ChooseFontHookProc( ) ! 309: // PURPOSE : Disable the Effects group and its contents ! 310: // COMMENTS : ! 311: // ************************************************************************ ! 312: LRESULT CALLBACK ! 313: ChooseFontHookProc( HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam ) ! 314: { ! 315: UNREFERENCED_PARAMETER( lParam ); ! 316: UNREFERENCED_PARAMETER( wParam ); ! 317: ! 318: switch( uMsg ) { ! 319: ! 320: case WM_INITDIALOG: ! 321: ShowWindow( GetDlgItem(hDlg, grp1), SW_HIDE ); ! 322: ShowWindow( GetDlgItem(hDlg, chx1), SW_HIDE ); ! 323: ShowWindow( GetDlgItem(hDlg, chx2), SW_HIDE ); ! 324: break; ! 325: ! 326: } ! 327: ! 328: return( FALSE ); ! 329: } ! 330: ! 331: ! 332: // ************************************************************************ 1.1 root 333: // FUNCTION : ChooseNewFont( HWND ) 1.1.1.3 ! root 334: // PURPOSE : Choose a new font for a listbox 1.1 root 335: // COMMENTS : Return TRUE on success else FALSE 336: // ************************************************************************ 337: BOOL 1.1.1.3 ! root 338: ChooseNewFont( HWND hWndListBox ) 1.1 root 339: { 340: static CHOOSEFONT ChooseFontStruct; 341: static BOOL fFirstTime = TRUE; 1.1.1.3 ! root 342: HFONT hFont; 1.1 root 343: 344: if( fFirstTime ) { 345: fFirstTime = FALSE; 346: 347: ChooseFontStruct.lStructSize = sizeof( CHOOSEFONT ); 1.1.1.3 ! root 348: ChooseFontStruct.hwndOwner = hWndListBox; 1.1 root 349: ChooseFontStruct.hDC = (HDC) NULL; 1.1.1.3 ! root 350: ChooseFontStruct.lpLogFont = &(Profile.LogFont); ! 351: ChooseFontStruct.iPointSize = (INT) NULL; 1.1 root 352: ChooseFontStruct.Flags = CF_INITTOLOGFONTSTRUCT | 1.1.1.3 ! root 353: CF_SCREENFONTS | CF_EFFECTS | ! 354: CF_ENABLEHOOK; ! 355: ChooseFontStruct.rgbColors = Profile.rgbForeColor; 1.1 root 356: ChooseFontStruct.lCustData = (DWORD) NULL; 1.1.1.3 ! root 357: ChooseFontStruct.lpfnHook = (LPCFHOOKPROC) ChooseFontHookProc; ! 358: ChooseFontStruct.lpTemplateName = (LPTSTR) NULL; 1.1 root 359: ChooseFontStruct.hInstance = (HANDLE) NULL; 1.1.1.3 ! root 360: ChooseFontStruct.lpszStyle = (LPTSTR) NULL; 1.1 root 361: ChooseFontStruct.nFontType = SCREEN_FONTTYPE; 1.1.1.3 ! root 362: ChooseFontStruct.nSizeMin = (INT) NULL; ! 363: ChooseFontStruct.nSizeMax = (INT) NULL; 1.1 root 364: } 365: 366: if( ChooseFont( &ChooseFontStruct ) ) { 367: HDC hDC; 368: 1.1.1.3 ! root 369: hFont = CreateFontIndirect( &(Profile.LogFont) ); ! 370: hDC = GetDC( hWndListBox ); 1.1 root 371: SelectObject( hDC, hFont ); 1.1.1.3 ! root 372: Profile.rgbForeColor = ChooseFontStruct.rgbColors; ! 373: InvalidateRect( hWndListBox, NULL, TRUE ); ! 374: SendMessage( hWndListBox, WM_CTLCOLORLISTBOX, (DWORD) hDC, ! 375: (LONG) hWndListBox ); ! 376: SendMessage( hWndListBox, WM_SETFONT, (DWORD) hFont, TRUE ); ! 377: ReleaseDC( hWndListBox, hDC ); 1.1 root 378: } 379: 380: return( TRUE ); 381: } 382: 383: 384: // ************************************************************************ 1.1.1.3 ! root 385: // FUNCTION : ChooseNewBackColor( HWND ) ! 386: // PURPOSE : Choose the background color for a listbox 1.1 root 387: // COMMENTS : Return TRUE on success else FALSE 388: // ************************************************************************ 389: BOOL 1.1.1.3 ! root 390: ChooseNewBackColor( HWND hWndListBox ) 1.1 root 391: { 392: static BOOL fFirstTime = TRUE; 393: static CHOOSECOLOR ChooseColorStruct; 394: static DWORD dwCustColors[16]; 395: 396: if( fFirstTime ) { 397: int i; 398: 399: fFirstTime = FALSE; 400: 401: //-- set the custom colors to white 402: for( i = 0; i < 16; i++ ) 403: dwCustColors[i] = RGB(255,255,255); 404: 405: ChooseColorStruct.lStructSize = sizeof( CHOOSECOLOR ); 1.1.1.3 ! root 406: ChooseColorStruct.hwndOwner = hWndListBox; 1.1 root 407: ChooseColorStruct.hInstance = (HANDLE) NULL; 1.1.1.3 ! root 408: ChooseColorStruct.rgbResult = Profile.rgbBackColor; 1.1 root 409: ChooseColorStruct.lpCustColors = (LPDWORD) dwCustColors; 410: ChooseColorStruct.Flags = CC_RGBINIT; 411: ChooseColorStruct.lCustData = 0L; 412: ChooseColorStruct.lpfnHook = (LPCCHOOKPROC) NULL; 1.1.1.3 ! root 413: ChooseColorStruct.lpTemplateName = (LPTSTR) NULL; 1.1 root 414: } 415: 416: if( ChooseColor( &ChooseColorStruct ) ) { 417: HDC hDC; 418: 1.1.1.3 ! root 419: Profile.rgbBackColor = (COLORREF) ChooseColorStruct.rgbResult; ! 420: hDC = GetDC( hWndListBox ); ! 421: SendMessage( hWndListBox, WM_CTLCOLORLISTBOX, (DWORD) hDC, ! 422: (LONG) hWndListBox ); ! 423: ReleaseDC( hWndListBox, hDC ); ! 424: InvalidateRect( hWndListBox, NULL, TRUE ); 1.1 root 425: } 426: 427: return( TRUE ); 428: } 429: 430: 431: // ************************************************************************ 1.1.1.3 ! root 432: // FUNCTION : MakeCommonDebugEventString( LPTSTR, LPDEBUG_EVENT ) ! 433: // PURPOSE : Fill in the Debug Event information into a string buffer ! 434: // COMMENTS : The string buffer contains the information common to all ! 435: // debug events ( PID, TID ). 1.1 root 436: // ************************************************************************ 1.1.1.3 ! root 437: BOOL ! 438: MakeCommonDebugEventString( LPTSTR lpszBuffer, LPDEBUG_EVENT lpDebugEvent ) 1.1 root 439: { 1.1.1.3 ! root 440: StringPrintF( lpszBuffer, TEXT( "PID:0x%X \t TID:0x%X \t " ), ! 441: lpDebugEvent->dwProcessId, lpDebugEvent->dwThreadId ); 1.1 root 442: 1.1.1.3 ! root 443: return( TRUE ); 1.1 root 444: } 445: 446: 447: // ************************************************************************ 1.1.1.3 ! root 448: // FUNCTION : CreateTextButtonBar( HWND, LPINT ) ! 449: // PURPOSE : Creates a Text Button Bar from the resource strings. ! 450: // COMMENTS : Returns window handle to the created text button bar 1.1 root 451: // ************************************************************************ 1.1.1.3 ! root 452: HWND ! 453: CreateTextButtonBar( HWND hWndParent, LPINT lpTextButtonBarHeight ) 1.1 root 454: { 1.1.1.3 ! root 455: TEXTBUTTON TextButton[9]; ! 456: static TCHAR szButtonOpen[32]; ! 457: static TCHAR szButtonAttach[32]; ! 458: static TCHAR szButtonCut[32]; ! 459: static TCHAR szButtonCopy[32]; ! 460: static TCHAR szButtonDelete[32]; ! 461: static TCHAR szButtonHelp[32]; 1.1 root 462: 1.1.1.3 ! root 463: LoadString( NULL, IDS_BUTTON_OPEN, szButtonOpen, sizeof(szButtonOpen)/sizeof(TCHAR) ); ! 464: LoadString( NULL, IDS_BUTTON_ATTACH, szButtonAttach, sizeof(szButtonAttach)/sizeof(TCHAR) ); ! 465: LoadString( NULL, IDS_BUTTON_CUT, szButtonCut, sizeof(szButtonCut)/sizeof(TCHAR) ); ! 466: LoadString( NULL, IDS_BUTTON_COPY, szButtonCopy, sizeof(szButtonCopy)/sizeof(TCHAR) ); ! 467: LoadString( NULL, IDS_BUTTON_DELETE, szButtonDelete, sizeof(szButtonDelete)/sizeof(TCHAR) ); ! 468: LoadString( NULL, IDS_BUTTON_HELP, szButtonHelp, sizeof(szButtonHelp)/sizeof(TCHAR) ); 1.1 root 469: 1.1.1.3 ! root 470: TextButton[0].lpButtonText = szButtonOpen; ! 471: TextButton[0].idButton = IDM_FILE_OPEN; ! 472: TextButton[0].hWndButton = NULL; 1.1 root 473: 1.1.1.3 ! root 474: TextButton[1].lpButtonText = szButtonAttach; ! 475: TextButton[1].idButton = IDM_FILE_ATTACH; ! 476: TextButton[1].hWndButton = NULL; 1.1 root 477: 1.1.1.3 ! root 478: TextButton[2].lpButtonText = NULL; ! 479: TextButton[2].idButton = TB_SPACE; ! 480: TextButton[2].hWndButton = NULL; 1.1 root 481: 1.1.1.3 ! root 482: TextButton[3].lpButtonText = szButtonCut; ! 483: TextButton[3].idButton = IDM_EDIT_CUT; ! 484: TextButton[3].hWndButton = NULL; 1.1 root 485: 1.1.1.3 ! root 486: TextButton[4].lpButtonText = szButtonCopy; ! 487: TextButton[4].idButton = IDM_EDIT_COPY; ! 488: TextButton[4].hWndButton = NULL; 1.1 root 489: 1.1.1.3 ! root 490: TextButton[5].lpButtonText = szButtonDelete; ! 491: TextButton[5].idButton = IDM_EDIT_DELETE; ! 492: TextButton[5].hWndButton = NULL; 1.1 root 493: 1.1.1.3 ! root 494: TextButton[6].lpButtonText = NULL; ! 495: TextButton[6].idButton = TB_SPACE; ! 496: TextButton[6].hWndButton = NULL; 1.1 root 497: 1.1.1.3 ! root 498: TextButton[7].lpButtonText = szButtonHelp; ! 499: TextButton[7].idButton = IDM_HELP_CONTENTS; ! 500: TextButton[7].hWndButton = NULL; ! 501: ! 502: TextButton[8].lpButtonText = (LPTSTR) NULL; ! 503: TextButton[8].idButton = (INT) NULL; ! 504: TextButton[8].hWndButton = (HWND) NULL; ! 505: ! 506: return( TextButtonBar( hWndParent, TextButton, lpTextButtonBarHeight ) ); 1.1 root 507: } 508: 1.1.1.3 ! root 509: 1.1 root 510: // ************************************************************************ 1.1.1.3 ! root 511: // FUNCTION : CreateIconWindow( HWND, LPCTSTR ) ! 512: // PURPOSE : ! 513: // COMMENTS : 1.1 root 514: // ************************************************************************ 1.1.1.3 ! root 515: HWND ! 516: CreateIconWindow( HWND hDlg, LPCTSTR lpstrIcon ) 1.1 root 517: { 1.1.1.3 ! root 518: return ( CreateWindow( TEXT( "static" ), lpstrIcon, ! 519: WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | SS_ICON, ! 520: 7, 5, 0, 0, ! 521: hDlg, NULL, GetModuleHandle( NULL ), NULL ) ); 1.1 root 522: } 523: 524: 525: // ************************************************************************ 1.1.1.3 ! root 526: // FUNCTION : GetPrivateProfileSettings( LPCTSTR, LPCTSTR, PPROFILE ) ! 527: // PURPOSE : Retrieves the stored preferences and options from the ! 528: // profile (registry) ! 529: // COMMENTS : 1.1 root 530: // ************************************************************************ 1.1.1.3 ! root 531: BOOL ! 532: GetPrivateProfileSettings( LPCTSTR lpszAppTitle, LPCTSTR lpszIniPathName, ! 533: PPROFILE pProfile ) 1.1 root 534: { 1.1.1.3 ! root 535: pProfile->xPos = (INT) GetPrivateProfileInt( lpszAppTitle, TEXT( "xPos" ), CW_USEDEFAULT, lpszIniPathName ); ! 536: pProfile->yPos = (INT) GetPrivateProfileInt( lpszAppTitle, TEXT( "yPos" ), CW_USEDEFAULT, lpszIniPathName ); ! 537: pProfile->nWidth = (INT) GetPrivateProfileInt( lpszAppTitle, TEXT( "nWidth" ), CW_USEDEFAULT, lpszIniPathName ); ! 538: pProfile->nHeight = (INT) GetPrivateProfileInt( lpszAppTitle, TEXT( "nHeight" ), CW_USEDEFAULT, lpszIniPathName ); ! 539: pProfile->fMaximized = (BOOL) GetPrivateProfileInt( lpszAppTitle, TEXT( "fMaximized" ), (INT) FALSE, lpszIniPathName ); ! 540: pProfile->fMinimized = (BOOL) GetPrivateProfileInt( lpszAppTitle, TEXT( "fMinimized" ), (INT) FALSE, lpszIniPathName ); ! 541: ! 542: pProfile->fToolBar = (BOOL) GetPrivateProfileInt( lpszAppTitle, TEXT( "fToolBar" ), (INT) TRUE, lpszIniPathName ); ! 543: pProfile->fSavedDirectory = (BOOL) GetPrivateProfileInt( lpszAppTitle, TEXT( "fSavedDirectory" ), (INT) TRUE, lpszIniPathName ); ! 544: GetPrivateProfileString( lpszAppTitle, TEXT( "szInitialDir" ), NULL, pProfile->szInitialDir, ! 545: sizeof( pProfile->szInitialDir ), lpszIniPathName ); ! 546: ! 547: pProfile->LogFont.lfHeight = (LONG) GetPrivateProfileInt( lpszAppTitle, TEXT( "lfHeight" ), (INT) 13 , lpszIniPathName ); ! 548: pProfile->LogFont.lfWidth = (LONG) GetPrivateProfileInt( lpszAppTitle, TEXT( "lfWidth" ), (INT) 0 , lpszIniPathName ); ! 549: pProfile->LogFont.lfWeight = (LONG) GetPrivateProfileInt( lpszAppTitle, TEXT( "lfWeight" ), (INT) 400 , lpszIniPathName ); ! 550: pProfile->LogFont.lfItalic = (BYTE) GetPrivateProfileInt( lpszAppTitle, TEXT( "lfItalic" ), (INT) FALSE, lpszIniPathName ); ! 551: pProfile->LogFont.lfUnderline = (BYTE) GetPrivateProfileInt( lpszAppTitle, TEXT( "lfUnderline" ), (INT) FALSE, lpszIniPathName ); ! 552: pProfile->LogFont.lfStrikeOut = (BYTE) GetPrivateProfileInt( lpszAppTitle, TEXT( "lfStrikeOut" ), (INT) FALSE, lpszIniPathName ); ! 553: pProfile->LogFont.lfPitchAndFamily = (BYTE) GetPrivateProfileInt( lpszAppTitle, TEXT( "lfPitchAndFamily" ), (INT) FF_DONTCARE, lpszIniPathName ); ! 554: GetPrivateProfileString( lpszAppTitle, TEXT( "lfFaceName" ), TEXT( "Arial" ), pProfile->LogFont.lfFaceName, ! 555: LF_FACESIZE, lpszIniPathName ); ! 556: pProfile->rgbForeColor = (COLORREF) GetPrivateProfileInt( lpszAppTitle, TEXT( "rgbForeColor" ), ! 557: (INT) GetSysColor(COLOR_WINDOWTEXT), lpszIniPathName ); ! 558: pProfile->rgbBackColor = (COLORREF) GetPrivateProfileInt( lpszAppTitle, TEXT( "rgbBackColor" ), ! 559: (INT) GetSysColor(COLOR_WINDOW), lpszIniPathName ); ! 560: ! 561: pProfile->fClearOnNew = (BOOL) GetPrivateProfileInt( lpszAppTitle, TEXT( "fClearOnNew" ), (INT) TRUE, lpszIniPathName ); ! 562: pProfile->fVerbose = (BOOL) GetPrivateProfileInt( lpszAppTitle, TEXT( "fVerbose" ), (INT) FALSE, lpszIniPathName ); ! 563: pProfile->fShowSymbols = (BOOL) GetPrivateProfileInt( lpszAppTitle, TEXT( "fShowSymbols" ), (INT) FALSE, lpszIniPathName ); ! 564: pProfile->DebugMode = (LONG) GetPrivateProfileInt( lpszAppTitle, TEXT( "DebugMode" ), (INT) DEBUG_PROCESS , lpszIniPathName ); ! 565: pProfile->DebuggeePriority = (LONG) GetPrivateProfileInt( lpszAppTitle, TEXT( "DebuggeePriority" ), (INT) NORMAL_PRIORITY_CLASS, lpszIniPathName ); ! 566: pProfile->DebugErrorLevel = (DWORD) GetPrivateProfileInt( lpszAppTitle, TEXT( "DebugErrorLevel" ), (INT) 0, lpszIniPathName ); ! 567: pProfile->fSavePreferences = (BOOL) GetPrivateProfileInt( lpszAppTitle, TEXT( "fSavePreferences" ), (INT) FALSE, lpszIniPathName ); 1.1 root 568: 1.1.1.3 ! root 569: pProfile->fSaveOnExit = (BOOL) GetPrivateProfileInt( lpszAppTitle, TEXT( "fSaveOnExit" ), (INT) TRUE, lpszIniPathName ); 1.1 root 570: 1.1.1.3 ! root 571: return( TRUE ); 1.1 root 572: } 573: 574: 575: // ************************************************************************ 1.1.1.3 ! root 576: // FUNCTION : WritePrivateProfileSettings( LPCTSTR, LPCTSTR, PPROFILE ) ! 577: // PURPOSE : Saves the preferences and options to the profile (registry) ! 578: // COMMENTS : 1.1 root 579: // ************************************************************************ 580: BOOL 1.1.1.3 ! root 581: WritePrivateProfileSettings( LPCTSTR lpszAppTitle, LPCTSTR lpszIniPathName, ! 582: PPROFILE pProfile ) 1.1 root 583: { 1.1.1.3 ! root 584: if( pProfile->fSaveOnExit ) { ! 585: WritePrivateProfileInt( lpszAppTitle, TEXT( "xPos" ), (INT) pProfile->xPos, lpszIniPathName ); ! 586: WritePrivateProfileInt( lpszAppTitle, TEXT( "yPos" ), (INT) pProfile->yPos, lpszIniPathName ); ! 587: WritePrivateProfileInt( lpszAppTitle, TEXT( "nWidth" ), (INT) pProfile->nWidth, lpszIniPathName ); ! 588: WritePrivateProfileInt( lpszAppTitle, TEXT( "nHeight" ), (INT) pProfile->nHeight, lpszIniPathName ); ! 589: WritePrivateProfileInt( lpszAppTitle, TEXT( "fMaximized" ), (INT) pProfile->fMaximized, lpszIniPathName ); ! 590: WritePrivateProfileInt( lpszAppTitle, TEXT( "fMinimized" ), (INT) pProfile->fMinimized, lpszIniPathName ); ! 591: ! 592: WritePrivateProfileInt( lpszAppTitle, TEXT( "fToolBar" ), (INT) pProfile->fToolBar, lpszIniPathName ); ! 593: WritePrivateProfileInt( lpszAppTitle, TEXT( "fSavedDirectory" ), (INT) pProfile->fSavedDirectory, lpszIniPathName ); ! 594: WritePrivateProfileString( lpszAppTitle, TEXT( "szInitialDir" ), pProfile->szInitialDir, lpszIniPathName ); ! 595: ! 596: WritePrivateProfileInt( lpszAppTitle, TEXT( "lfHeight" ), (INT) pProfile->LogFont.lfHeight, lpszIniPathName ); ! 597: WritePrivateProfileInt( lpszAppTitle, TEXT( "lfWidth" ), (INT) pProfile->LogFont.lfWidth, lpszIniPathName ); ! 598: WritePrivateProfileInt( lpszAppTitle, TEXT( "lfWeight" ), (INT) pProfile->LogFont.lfWeight, lpszIniPathName ); ! 599: WritePrivateProfileInt( lpszAppTitle, TEXT( "lfItalic" ), (INT) pProfile->LogFont.lfItalic, lpszIniPathName ); ! 600: WritePrivateProfileInt( lpszAppTitle, TEXT( "lfUnderline" ), (INT) pProfile->LogFont.lfUnderline, lpszIniPathName ); ! 601: WritePrivateProfileInt( lpszAppTitle, TEXT( "lfStrikeOut" ), (INT) pProfile->LogFont.lfStrikeOut, lpszIniPathName ); ! 602: WritePrivateProfileInt( lpszAppTitle, TEXT( "lfPitchAndFamily" ), (INT) pProfile->LogFont.lfPitchAndFamily, lpszIniPathName ); ! 603: WritePrivateProfileString( lpszAppTitle, TEXT( "lfFaceName" ), pProfile->LogFont.lfFaceName, lpszIniPathName ); ! 604: WritePrivateProfileInt( lpszAppTitle, TEXT( "rgbForeColor" ), (INT) pProfile->rgbForeColor, lpszIniPathName ); ! 605: WritePrivateProfileInt( lpszAppTitle, TEXT( "rgbBackColor" ), (INT) pProfile->rgbBackColor, lpszIniPathName ); ! 606: ! 607: if( pProfile->fSavePreferences ) { ! 608: WritePrivateProfileInt( lpszAppTitle, TEXT( "fClearOnNew" ), (INT) pProfile->fClearOnNew, lpszIniPathName ); ! 609: WritePrivateProfileInt( lpszAppTitle, TEXT( "fVerbose" ), (INT) pProfile->fVerbose, lpszIniPathName ); ! 610: WritePrivateProfileInt( lpszAppTitle, TEXT( "fShowSymbols" ), (INT) pProfile->fShowSymbols, lpszIniPathName ); ! 611: WritePrivateProfileInt( lpszAppTitle, TEXT( "DebugMode" ), (INT) pProfile->DebugMode, lpszIniPathName ); ! 612: WritePrivateProfileInt( lpszAppTitle, TEXT( "DebuggeePriority" ), (INT) pProfile->DebuggeePriority, lpszIniPathName ); ! 613: WritePrivateProfileInt( lpszAppTitle, TEXT( "DebugErrorLevel" ), (INT) pProfile->DebugErrorLevel, lpszIniPathName ); ! 614: } ! 615: WritePrivateProfileInt( lpszAppTitle, TEXT( "fSavePreferences" ), (INT) pProfile->fSavePreferences, lpszIniPathName ); ! 616: } ! 617: WritePrivateProfileInt( lpszAppTitle, TEXT( "fSaveOnExit" ), (INT) pProfile->fSaveOnExit, lpszIniPathName ); 1.1 root 618: 619: return( TRUE ); 620: } 621: 622: 623: // ************************************************************************ 1.1.1.3 ! root 624: // FUNCTION: WritePrivateProfileInt( LPCTSTR, LPCTSTR, INT, LPCTSTR ) ! 625: // PURPOSE : Writes the value of an integer from a specified keyname within ! 626: // a specified section of the Private Profile ! 627: // COMMENTS: Matched pair to GetPrivateProfileInt 1.1 root 628: // ************************************************************************ 1.1.1.3 ! root 629: BOOL ! 630: WritePrivateProfileInt( LPCTSTR lpAppName, LPCTSTR lpKeyName, INT Value, LPCTSTR lpFileName ) 1.1 root 631: { 1.1.1.3 ! root 632: TCHAR ValBuf[16]; 1.1 root 633: 1.1.1.3 ! root 634: wsprintf( ValBuf, TEXT( "%i" ), Value); 1.1 root 635: 1.1.1.3 ! root 636: return( WritePrivateProfileString( lpAppName, lpKeyName, ValBuf, lpFileName ) ); 1.1 root 637: } 638: 639: 640: // ************************************************************************ 1.1.1.3 ! root 641: // FUNCTION : UpdateMenuSettings( HWND ) ! 642: // PURPOSE : Adds check marks to active menu items ! 643: // COMMENTS : 1.1 root 644: // ************************************************************************ 1.1.1.3 ! root 645: BOOL ! 646: UpdateMenuSettings( HWND hWnd ) 1.1 root 647: { 1.1.1.3 ! root 648: if( Profile.fToolBar ) ! 649: CheckMenuItem( GetMenu(hWnd), IDM_OPTIONS_TOOLBAR, MF_CHECKED ); ! 650: if( Profile.fSavedDirectory ) ! 651: CheckMenuItem( GetMenu(hWnd), IDM_OPTIONS_SAVEDDIR, MF_CHECKED ); ! 652: if( Profile.fSaveOnExit ) ! 653: CheckMenuItem( GetMenu(hWnd), IDM_OPTIONS_SAVEONEXIT, MF_CHECKED ); 1.1 root 654: 1.1.1.2 root 655: return( TRUE ); 1.1 root 656: } 657: 658: 659: // ************************************************************************ 1.1.1.3 ! root 660: // FUNCTION : OutOfMemoryMessageBox( HWND ) ! 661: // PURPOSE : If called, displays an "Out of Memory" message box 1.1 root 662: // COMMENTS : 663: // ************************************************************************ 664: BOOL 1.1.1.3 ! root 665: OutOfMemoryMessageBox( HWND hWndOwner ) 1.1 root 666: { 1.1.1.3 ! root 667: MessageBox( ! 668: hWndOwner, ! 669: TEXT( "Out of Memory" ), ! 670: TEXT( "Memory Error" ), ! 671: MB_ICONSTOP | MB_APPLMODAL ); 1.1 root 672: 673: return( TRUE ); 674: } 675: 676: 677: // ************************************************************************ 1.1.1.3 ! root 678: // FUNCTION : MaxDebuggeesMessageBox( HWND ) ! 679: // PURPOSE : If called, displays an "Max Debuggees" message box 1.1 root 680: // COMMENTS : 681: // ************************************************************************ 682: BOOL 1.1.1.3 ! root 683: MaxDebuggeesMessageBox( HWND hWndOwner ) 1.1 root 684: { 1.1.1.3 ! root 685: MessageBox( hWndOwner, ! 686: TEXT( "This build of the Debug Event Browser\n" ) ! 687: TEXT( "is limited to debugging only one debuggee\n" ) ! 688: TEXT( "at a time." ), ! 689: TEXT( "Cannot Open Debuggee" ), ! 690: MB_OK | MB_ICONEXCLAMATION ); 1.1 root 691: 692: return( TRUE ); 693: } 694: 695: 1.1.1.3 ! root 696: // ======================================================================== ! 697: // helper functions ! 698: // ======================================================================== ! 699: ! 700: 1.1 root 701: // ************************************************************************ 1.1.1.3 ! root 702: // FUNCTION : ErrorMessageBox( LPCTSTR, LPCTSTR, LPCTSTR, INT ) ! 703: // PURPOSE : Displays an error message box with various error information ! 704: // and allows the user to terminate or continue the process. ! 705: // For a Win32 Application, GetLastError and FormatMessage are ! 706: // user to retrieve the last API error code and error message. 1.1 root 707: // COMMENTS : 708: // ************************************************************************ 709: BOOL 1.1.1.3 ! root 710: ErrorMessageBox( LPCTSTR lpszText, LPCTSTR lpszTitle, LPCTSTR lpszFile, ! 711: INT Line ) 1.1 root 712: { 1.1.1.3 ! root 713: #define ERROR_BUFFER_SIZE 512 ! 714: ! 715: static TCHAR Format[] = ! 716: TEXT( "%s\n\n" ) ! 717: TEXT( "-- Error Information --\n" ) ! 718: TEXT( "File : %s\n" ) ! 719: TEXT( "Line : %d\n" ) ! 720: TEXT( "Error Number : %d\n" ) ! 721: TEXT( "Error Message : %s\n" ) ! 722: TEXT( "\n" ) ! 723: TEXT( "Press OK to terminate this application." ); ! 724: ! 725: LPTSTR lpFormatMessageBuffer; ! 726: DWORD dwFormatMessage; ! 727: DWORD dwGetLastError; ! 728: HLOCAL hMessageBoxBuffer; ! 729: LPVOID lpMessageBoxBuffer; ! 730: ! 731: //-- perform a simple check on the needed buffer size ! 732: if( lstrlen(lpszText) > (ERROR_BUFFER_SIZE - lstrlen(Format)) ) ! 733: return( FALSE ); ! 734: ! 735: //-- allocate the message box buffer ! 736: hMessageBoxBuffer = LocalAlloc( LMEM_FIXED, ERROR_BUFFER_SIZE ); ! 737: lpMessageBoxBuffer = LocalLock( hMessageBoxBuffer ); ! 738: ! 739: //-- get the system error and system error message ! 740: dwGetLastError = GetLastError(); ! 741: dwFormatMessage = FormatMessage( ! 742: FORMAT_MESSAGE_ALLOCATE_BUFFER ! 743: | FORMAT_MESSAGE_FROM_SYSTEM, ! 744: NULL, dwGetLastError, LANG_NEUTRAL, ! 745: (LPTSTR) &lpFormatMessageBuffer, 0, NULL ); ! 746: if( !dwFormatMessage ) ! 747: lpFormatMessageBuffer = TEXT("FormatMessage() failed!"); ! 748: ! 749: //-- format the error messge box string ! 750: wsprintf( lpMessageBoxBuffer, Format, lpszText, lpszFile, Line, ! 751: dwGetLastError, lpFormatMessageBuffer ); ! 752: ! 753: // -- display the error and allow the user to terminate or continue ! 754: if( MessageBox( NULL, lpMessageBoxBuffer, lpszTitle, ! 755: MB_APPLMODAL | MB_ICONSTOP | MB_OKCANCEL ) ! 756: == IDOK ) ! 757: ExitProcess( 0 ); ! 758: ! 759: //-- free all buffers ! 760: if( dwFormatMessage ) ! 761: LocalFree( (HLOCAL) lpFormatMessageBuffer ); ! 762: LocalFree( (HLOCAL) hMessageBoxBuffer ); 1.1 root 763: 764: return( TRUE ); 765: } 766: 767: 1.1.1.3 ! root 768: 1.1 root 769: // ************************************************************************ 770: // FUNCTION : SubclassWindow( HWND, WNDPROC ) 771: // PURPOSE : Subclasses a window procedure 772: // COMMENTS : Returns the old window procedure 773: // ************************************************************************ 774: WNDPROC 775: SubclassWindow( HWND hWnd, WNDPROC NewWndProc) 776: { 777: WNDPROC OldWndProc; 778: 779: OldWndProc = (WNDPROC) GetWindowLong( hWnd, GWL_WNDPROC ); 780: SetWindowLong( hWnd, GWL_WNDPROC, (LONG) NewWndProc ); 781: 782: return OldWndProc; 783: } 784: 785: 786: // ************************************************************************ 787: // FUNCTION : SendWmSizeMessage( HWND ) 788: // PURPOSE : Sends a WM_SIZE message containing the current size 789: // COMMENTS : Forces a WM_SIZE message without actually changing the size 790: // ************************************************************************ 791: BOOL 792: SendWmSizeMessage( HWND hWnd ) 793: { 1.1.1.3 ! root 794: RECT Rect; 1.1 root 795: 1.1.1.3 ! root 796: if( !GetClientRect( hWnd, &Rect ) ) 1.1 root 797: return( FALSE ); 798: 1.1.1.3 ! root 799: return( SendMessage( hWnd, WM_SIZE, SIZENORMAL, ! 800: MAKELONG( Rect.right - Rect.left, Rect.bottom - Rect.top) ) ); 1.1 root 801: } 802: 803: 804: // ************************************************************************ 805: // FUNCTION : GetPathFromFullPathName( LPCTSTR, LPTSTR, UINT ) 806: // PURPOSE : Extracts the path given a full pathname 807: // COMMENTS : 808: // ************************************************************************ 809: UINT 810: GetPathFromFullPathName( LPCTSTR lpFullPathName, LPTSTR lpPathBuffer, 811: UINT nPathBufferLength ) 812: { 813: UINT nLength; 814: int i; 815: 816: if( (nLength = (UINT) lstrlen( lpFullPathName ) ) > nPathBufferLength ) 817: return( nLength ); 818: 819: lstrcpy( lpPathBuffer, lpFullPathName ); 820: 821: for( i = lstrlen( lpPathBuffer ); 822: (lpPathBuffer[i] != '\\') && (lpPathBuffer[i] != ':'); 823: i-- ) 824: ; 825: if( lpPathBuffer[i] == ':' ) 826: lpPathBuffer[i+1] = '\0'; 827: else 828: lpPathBuffer[i] = '\0'; 829: 830: return( (UINT) i ); 831: } 832: 833: 834: // ************************************************************************ 1.1.1.3 ! root 835: // FUNCTION : CopyListBoxToClipboard( HWND, LONG ) ! 836: // PURPOSE : Copies the entire contents of a listbox into the clipboard. ! 837: // COMMENTS : Returns TRUE on success, FALSE otherwise ! 838: // ************************************************************************ ! 839: BOOL ! 840: CopyListBoxToClipboard( HWND hWndListBox, LONG MaxStrLen ) ! 841: { ! 842: LPTSTR lpDataBuffer; ! 843: HGLOBAL hDataBuffer; ! 844: ! 845: TCHAR TempBuffer[256]; ! 846: DWORD dwItemCount; ! 847: DWORD Count; ! 848: LONG StrLen; ! 849: DWORD dwMemSize; ! 850: ! 851: dwItemCount = (DWORD) SendMessage( hWndListBox, LB_GETCOUNT, 0 , 0 ); ! 852: dwMemSize = dwItemCount * (DWORD) MaxStrLen; ! 853: ! 854: //-- limit the size copied to the clipboard ! 855: if( dwMemSize > 0xFFFFF ) ! 856: dwMemSize = 0xFFFFF; ! 857: ! 858: if( !(hDataBuffer = GlobalAlloc( GMEM_DDESHARE, dwMemSize ) ) ) { ! 859: OutOfMemoryMessageBox( GetFocus() ); ! 860: return( FALSE ); ! 861: } ! 862: if( !(lpDataBuffer = (LPTSTR) GlobalLock( hDataBuffer ) ) ) { ! 863: GlobalFree( hDataBuffer ); ! 864: OutOfMemoryMessageBox( GetFocus() ); ! 865: return( FALSE ); ! 866: } ! 867: ! 868: *lpDataBuffer = '\0'; ! 869: ! 870: for( Count = 0; Count < dwItemCount; Count++ ) { ! 871: StrLen = SendMessage( hWndListBox, LB_GETTEXTLEN, Count, 0L ); ! 872: if( StrLen > (sizeof(TempBuffer)-3) ) ! 873: continue; ! 874: StrLen = SendMessage( hWndListBox, LB_GETTEXT, Count, (LPARAM) TempBuffer ); ! 875: TempBuffer[StrLen] = '\r'; ! 876: TempBuffer[StrLen+1] = '\n'; ! 877: TempBuffer[StrLen+2] = '\0'; ! 878: lstrcat( lpDataBuffer, TempBuffer ); ! 879: } ! 880: ! 881: GlobalUnlock( hDataBuffer ); ! 882: ! 883: if( !OpenClipboard( hWndListBox ) ) { ! 884: Sleep( 250 ); // wait a quarter second and try again. ! 885: if( !OpenClipboard( hWndListBox ) ) { ! 886: MessageBox( GetFocus(), ! 887: TEXT( "Could not open the Clipboard!" ), ! 888: TEXT( "Cannot Open Clipboard" ), ! 889: MB_ICONSTOP | MB_APPLMODAL ); ! 890: GlobalFree( hDataBuffer ); ! 891: return( FALSE ); ! 892: } ! 893: } ! 894: if( !EmptyClipboard() ) { ! 895: MessageBox( GetFocus(), ! 896: TEXT( "Could not empty the Clipboard!" ), ! 897: TEXT( "Cannot Empty Clipboard" ), ! 898: MB_ICONSTOP | MB_APPLMODAL ); ! 899: GlobalFree( hDataBuffer ); ! 900: return( FALSE ); ! 901: } ! 902: if( !SetClipboardData( CF_TEXT, hDataBuffer ) ) { ! 903: MessageBox( GetFocus(), ! 904: TEXT( "Could not copy data to the Clipboard!" ), ! 905: TEXT( "Cannot Set Clipboard Data" ), ! 906: MB_ICONSTOP | MB_APPLMODAL ); ! 907: GlobalFree( hDataBuffer ); ! 908: return( FALSE ); ! 909: } ! 910: CloseClipboard(); ! 911: ! 912: return( TRUE ); ! 913: } ! 914: ! 915: ! 916: // ************************************************************************ ! 917: // FUNCTION : ListBoxInsert( HWND, LPLONG, LPCTSTR ) ! 918: // PURPOSE : Inserts the string into the listbox. ! 919: // COMMENTS : Returns the index of the string inserted ! 920: // ************************************************************************ ! 921: LONG ! 922: ListBoxInsert( HWND hWndListBox, LPLONG lpMaxStrLen, LPCTSTR lpszString ) ! 923: { ! 924: static LONG MaxTextExtent = 0; ! 925: ! 926: LONG Index; ! 927: ! 928: if( lpszString == NULL ) { ! 929: MaxTextExtent = 0; ! 930: SendMessage( hWndListBox, LB_SETHORIZONTALEXTENT, 0, 0 ); ! 931: return( 0 ); ! 932: } ! 933: ! 934: if( hWndListBox != NULL ) { ! 935: HDC hDC; ! 936: SIZE Size; ! 937: LONG StrLen; ! 938: ! 939: if( (StrLen = lstrlen( lpszString)) > *lpMaxStrLen ) ! 940: *lpMaxStrLen = StrLen; ! 941: hDC = GetDC( hWndListBox ); ! 942: GetTextExtentPoint( hDC, lpszString, StrLen, &Size ); ! 943: ReleaseDC( hWndListBox, hDC ); ! 944: if( Size.cx > MaxTextExtent ) { ! 945: MaxTextExtent = Size.cx; ! 946: SendMessage( hWndListBox, LB_SETHORIZONTALEXTENT, (WPARAM) (MaxTextExtent*1.1), 0 ); ! 947: } ! 948: Index = SendMessage( hWndListBox, LB_ADDSTRING, 0, (LPARAM) lpszString ); ! 949: SendMessage( hWndListBox, LB_SETCURSEL, Index, 0 ); ! 950: } ! 951: ! 952: return( Index ); ! 953: } ! 954: ! 955: ! 956: // ************************************************************************ ! 957: // FUNCTION : ListBoxPrintF( HWND, LPCTSTR, ... ) ! 958: // PURPOSE : Inserts the string format into the listbox. ! 959: // COMMENTS : Returns the index of the last string inserted ! 960: // ************************************************************************ ! 961: LONG ! 962: ListBoxPrintF( HWND hWndListBox, LPCTSTR szFormat, ... ) ! 963: { ! 964: static TCHAR szBuffer[ 1024 ]; ! 965: ! 966: va_list valist; ! 967: LONG Index; ! 968: LPTSTR lpCurrentString, lpCurrentChar; ! 969: ! 970: va_start( valist, szFormat ); ! 971: wvsprintf( szBuffer, szFormat, valist ); ! 972: va_end( valist ); ! 973: ! 974: //-- insert strings line-by-line ! 975: for( lpCurrentString = lpCurrentChar = szBuffer; *lpCurrentChar != '\0'; ) { ! 976: if( *lpCurrentChar == '\n' ) { ! 977: LPTSTR lpNextChar = CharNext( lpCurrentChar ); ! 978: *lpCurrentChar = '\0'; ! 979: Index = ListBoxInsert( hWndListBox, &(Global.MaxStrLen), lpCurrentString ); ! 980: lpCurrentString = lpCurrentChar = lpNextChar; ! 981: } ! 982: else ! 983: lpCurrentChar = CharNext( lpCurrentChar ); ! 984: } ! 985: Index = ListBoxInsert( hWndListBox, &(Global.MaxStrLen), lpCurrentString ); ! 986: ! 987: return( Index ); ! 988: } ! 989: ! 990: ! 991: // ************************************************************************ ! 992: // FUNCTION : StringPrintF( LPTSTR, LPCTSTR, ... ) ! 993: // PURPOSE : Formats a string buffer according to the format-control ! 994: // string. This function is wsprintf but the return ! 995: // values is a pointer to the string instead of the count. 1.1 root 996: // COMMENTS : 997: // ************************************************************************ 998: LPTSTR 1.1.1.3 ! root 999: StringPrintF( LPTSTR lpString, LPCTSTR szFormat, ... ) 1.1 root 1000: { 1.1.1.3 ! root 1001: va_list valist; ! 1002: ! 1003: va_start( valist, szFormat ); ! 1004: wvsprintf( lpString, szFormat, valist ); ! 1005: va_end( valist ); 1.1 root 1006: 1.1.1.3 ! root 1007: return( lpString ); ! 1008: } ! 1009: ! 1010: ! 1011: // ************************************************************************ ! 1012: // FUNCTION : StringAppendF( LPTSTR, LPCTSTR, ... ) ! 1013: // PURPOSE : Append a variable number of characters and values to the end ! 1014: // of an existing string buffer according to the format string ! 1015: // (which uses standard printf() formating notation). ! 1016: // COMMENTS : ! 1017: // ************************************************************************ ! 1018: BOOL ! 1019: StringAppendF( LPTSTR lpszBuffer, LPCTSTR szFormat, ... ) ! 1020: { ! 1021: static TCHAR szLgBuffer[1024]; ! 1022: ! 1023: va_list valist; ! 1024: int n; ! 1025: ! 1026: //-- add event specific information ! 1027: va_start( valist, szFormat ); ! 1028: n = wvsprintf( szLgBuffer, szFormat, valist ); ! 1029: va_end( valist ); ! 1030: ! 1031: //-- append information to the string buffer ! 1032: lstrcat( lpszBuffer, szLgBuffer ); ! 1033: ! 1034: return( TRUE ); 1.1 root 1035: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.