Annotation of mstools/samples/deb/debmisc.c, revision 1.1.1.2

1.1       root        1: // ************************************************************************
1.1.1.2 ! root        2: //
        !             3: //                      Microsoft Developer Support
        !             4: //               Copyright (c) 1992 Microsoft Corporation
        !             5: //
        !             6: // ************************************************************************
        !             7: // MODULE    : DEBMisc.C
1.1       root        8: // PURPOSE   : Miscellaneous support functions for the Debug Event Browser
                      9: // FUNCTIONS :
1.1.1.2 ! root       10: //   ErrorBox()                    - displays and error box when called
1.1       root       11: //   CreateTextButtonBar()         - create a text button bar
                     12: //   OpenDebugee()                 - open a debugee application
1.1.1.2 ! root       13: //   AttachToDebugee()             - attach to a running process
1.1       root       14: //   ChooseNewFont()               - choose a new font
                     15: //   ChooseNewBkColor()            - choose a new background color
                     16: //   CopyListBoxToClipboard()      - copies a listbox into the clipboard
                     17: //   ListBoxInsert()               - insert a string into a listbox
                     18: //   ListBoxPrintF()               - printf for listboxes
                     19: //   MakeDebugEventString()        - creates standard event info string
1.1.1.2 ! root       20: //   OrderFunc()                   - double linked list ordering function
1.1       root       21: //   EnumProcessListFunc()         - enumeration func for active processes
                     22: //   GetPrivateProfileSettings()   - gets stored profile settings
                     23: //   WritePrivateProfileSettings() - stores default settings in profile
                     24: //   UpdateMenuSettings()          - update menu check marks
                     25: //   SubclassWindow()              - generic window subclass func
                     26: //   WritePrivateProfileInt()      - opposite of GetPrivateProfileInt()
1.1.1.2 ! root       27: //   SendWmSizeMessage()           - sends a WM_SIZE message with current
        !            28: //                                   size
1.1       root       29: //   GetPathFromFullPathName()     - extracts path from a pathname
                     30: //   LongToCharUpper()             - converts a long to upper-case string
                     31: // COMMENTS  :
1.1.1.2 ! root       32: //
1.1       root       33: // ************************************************************************
1.1.1.2 ! root       34: #define   STRICT
1.1       root       35: #include <Windows.H>
                     36: #include <CommDlg.H>         // GetOpenFileName(), ChooseFont(), etc.
                     37: #include <StdArg.H>          // va_list, va_start()
1.1.1.2 ! root       38: #include <StdLib.H>          // ltoa(), abs()
1.1       root       39: 
                     40: #include "LinkList.H"
                     41: #include "ToolBar.H"
                     42: #include "DEBMain.H"
                     43: #include "DEBDebug.H"
                     44: #include "DEBMisc.H"
                     45: 
                     46: // *************
                     47: // internal data
                     48: // *************
                     49: TCHAR  szInitialDir[256];
                     50: 
                     51: 
                     52: // ************************************************************************
1.1.1.2 ! root       53: // FUNCTION : ErrorBox( LPCTSTR, LPCTSTR, LPCTSTR, int )
        !            54: // PURPOSE  :
        !            55: // COMMENTS :
        !            56: // ************************************************************************
        !            57: int
        !            58: ErrorBox( LPCTSTR lpszText, LPCTSTR lpszTitle, LPCTSTR lpszFile, int Line )
        !            59: {
        !            60:   static char TextBuffer[512];
        !            61: 
        !            62:   wsprintf( TextBuffer, "%s.\n\nFILE : %s\nLINE : %d\nGetLastError : %d\n\nPress Cancel to abort.",
        !            63:     lpszText, lpszFile, Line, GetLastError() );
        !            64: 
        !            65:   if( MessageBox( GetDesktopWindow(), TextBuffer, lpszTitle, MB_OKCANCEL )  == IDCANCEL )
        !            66:     ExitProcess( 0 );
        !            67: 
        !            68:   return( 0 );
        !            69: }
        !            70: 
        !            71: 
        !            72: // ************************************************************************
1.1       root       73: // FUNCTION : CreateTextButtonBar( HWND, LPINT )
                     74: // PURPOSE  : Creates a Text Button Bar from the resource strings.
                     75: // COMMENTS : Returns window handle to the created text button bar
                     76: // ************************************************************************
                     77: HWND
                     78: CreateTextButtonBar( HWND hWndParent, LPINT lpTextButtonBarHeight )
                     79: {
                     80:   TEXTBUTTON   TextButton[9];
                     81:   static TCHAR szButtonOpen[32];
                     82:   static TCHAR szButtonAttach[32];
                     83:   static TCHAR szButtonCut[32];
                     84:   static TCHAR szButtonCopy[32];
                     85:   static TCHAR szButtonDelete[32];
                     86:   static TCHAR szButtonHelp[32];
                     87: 
                     88:   LoadString( hInstance, IDS_BUTTON_OPEN,   szButtonOpen,   sizeof(szButtonOpen)/sizeof(TCHAR)   );
                     89:   LoadString( hInstance, IDS_BUTTON_ATTACH, szButtonAttach, sizeof(szButtonAttach)/sizeof(TCHAR) );
                     90:   LoadString( hInstance, IDS_BUTTON_CUT,    szButtonCut,    sizeof(szButtonCut)/sizeof(TCHAR)    );
                     91:   LoadString( hInstance, IDS_BUTTON_COPY,   szButtonCopy,   sizeof(szButtonCopy)/sizeof(TCHAR)   );
                     92:   LoadString( hInstance, IDS_BUTTON_DELETE, szButtonDelete, sizeof(szButtonDelete)/sizeof(TCHAR) );
                     93:   LoadString( hInstance, IDS_BUTTON_HELP,   szButtonHelp,   sizeof(szButtonHelp)/sizeof(TCHAR)   );
                     94: 
                     95:   TextButton[0].lpButtonText = szButtonOpen;
                     96:   TextButton[0].idButton     = IDM_FILE_OPEN;
                     97:   TextButton[0].hWndButton   = NULL;
                     98: 
                     99:   TextButton[1].lpButtonText = szButtonAttach;
                    100:   TextButton[1].idButton     = IDM_FILE_ATTACH;
                    101:   TextButton[1].hWndButton   = NULL;
                    102: 
                    103:   TextButton[2].lpButtonText = NULL;
                    104:   TextButton[2].idButton     = TB_SPACE;
                    105:   TextButton[2].hWndButton   = NULL;
                    106: 
                    107:   TextButton[3].lpButtonText = szButtonCut;
                    108:   TextButton[3].idButton     = IDM_EDIT_CUT;
                    109:   TextButton[3].hWndButton   = NULL;
                    110: 
                    111:   TextButton[4].lpButtonText = szButtonCopy;
                    112:   TextButton[4].idButton     = IDM_EDIT_COPY;
                    113:   TextButton[4].hWndButton   = NULL;
                    114: 
                    115:   TextButton[5].lpButtonText = szButtonDelete;
                    116:   TextButton[5].idButton     = IDM_EDIT_DELETE;
                    117:   TextButton[5].hWndButton   = NULL;
                    118: 
                    119:   TextButton[6].lpButtonText = NULL;
                    120:   TextButton[6].idButton     = TB_SPACE;
                    121:   TextButton[6].hWndButton   = NULL;
                    122: 
                    123:   TextButton[7].lpButtonText = szButtonHelp;
                    124:   TextButton[7].idButton     = IDM_HELP_CONTENTS;
                    125:   TextButton[7].hWndButton   = NULL;
                    126: 
                    127:   TextButton[8].lpButtonText = NULL;
                    128:   TextButton[8].idButton     = NULL;
                    129:   TextButton[8].hWndButton   = NULL;
                    130: 
                    131:   return( TextButtonBar( hWndParent, TextButton, lpTextButtonBarHeight ) );
                    132: }
                    133: 
                    134: 
                    135: // ************************************************************************
1.1.1.2 ! root      136: // FUNCTION : OpenDebugee( )
1.1       root      137: // PURPOSE  : Open a debugee and create a debug event processing thread
                    138: // COMMENTS : Return TRUE on success else FALSE
                    139: // ************************************************************************
                    140: BOOL
1.1.1.2 ! root      141: OpenDebugee( )
1.1       root      142: {
                    143:   static BOOL  fFirstTime = TRUE;
                    144: 
                    145:   static TCHAR szFilter[128];
                    146:   static TCHAR szTitle[32];
                    147:   static TCHAR szDirName[256];
                    148:   static TCHAR szFile[256];
                    149:   static TCHAR szFileTitle[256];
                    150:   static TCHAR szDefExt[8];
                    151: 
                    152:   static OPENFILENAME OpenFileName;
                    153: 
1.1.1.2 ! root      154:   static HANDLE hDebugEventThread;
        !           155:   static DWORD  idDebugEventThread;
1.1       root      156: 
                    157:   //-- Load resource strings and init the OpenFileName & lpProcInfo structs
                    158:   //   (do this only one time)
                    159:   if( fFirstTime ) {
                    160:     UINT    FilterNameLen;
                    161: 
                    162:     fFirstTime = FALSE;
                    163:     FilterNameLen = (UINT) LoadString( hInstance, IDS_OFN_FILTERNAME,
                    164:                              szFilter, sizeof(szFilter)/sizeof(TCHAR) );
                    165:     FilterNameLen++;
                    166:     LoadString( hInstance, IDS_OFN_FILTER, &szFilter[FilterNameLen],
                    167:       (sizeof(szFilter)-(FilterNameLen))/sizeof(TCHAR) );
                    168:     LoadString( hInstance, IDS_OFN_TITLE, szTitle, sizeof(szTitle)/sizeof(TCHAR) );
                    169: 
                    170:     OpenFileName.lStructSize       = sizeof(OPENFILENAME);
                    171:     OpenFileName.hwndOwner         = hWndMain;
                    172:     OpenFileName.hInstance         = hInstance;
                    173:     OpenFileName.lpstrFilter       = (LPSTR) szFilter;
                    174:     OpenFileName.lpstrCustomFilter = (LPSTR) NULL;
                    175:     OpenFileName.nMaxCustFilter    = (DWORD) NULL;
                    176:     OpenFileName.nFilterIndex      = (DWORD) 1;
                    177:     OpenFileName.lpstrFile         = (LPSTR) szFile;
                    178:     OpenFileName.nMaxFile          = sizeof(szFile);
                    179:     OpenFileName.lpstrFileTitle    = (LPSTR) szFileTitle;
                    180:     OpenFileName.nMaxFileTitle     = sizeof(szFileTitle);
                    181:     OpenFileName.lpstrInitialDir   = (LPSTR) (fSavedDirectory ? szInitialDir : NULL);
                    182:     OpenFileName.lpstrTitle        = (LPSTR) szTitle;
                    183:     OpenFileName.Flags             = OFN_HIDEREADONLY;
                    184:     OpenFileName.nFileOffset       = (WORD) NULL;
                    185:     OpenFileName.nFileExtension    = (WORD) NULL;
                    186:     OpenFileName.lpstrDefExt       = (LPSTR) szDefExt;
                    187:     OpenFileName.lCustData         = (DWORD) NULL;
                    188:     OpenFileName.lpfnHook          = (LPOFNHOOKPROC) NULL;
                    189:     OpenFileName.lpTemplateName    = (LPSTR) NULL;
                    190:   }
                    191: 
                    192:   if( !GetOpenFileName(&OpenFileName) )
                    193:     return( FALSE );
                    194: 
                    195:   //-- store recent directory by stripping off the EXE name from the full path
                    196:   GetPathFromFullPathName( (LPTSTR) OpenFileName.lpstrFile, szInitialDir,
                    197:     sizeof(szInitialDir) );
                    198: 
                    199:   //-- now start and detach the debug event processing thread
1.1.1.2 ! root      200:   if( !(hDebugEventThread = CreateThread(
1.1       root      201:                               (LPSECURITY_ATTRIBUTES) NULL,
                    202:                               (DWORD) 0,
                    203:                               (LPTHREAD_START_ROUTINE) DebugEventThread,
                    204:                               (LPVOID) OpenFileName.lpstrFile,
1.1.1.2 ! root      205:                               (DWORD) 0,
1.1       root      206:                               (LPDWORD) &idDebugEventThread) ) ) {
1.1.1.2 ! root      207:     ErrorBox( "Failed", "CreateThread()", __FILE__, __LINE__ );
1.1       root      208:     return( FALSE );
1.1.1.2 ! root      209:   }
        !           210:   CloseHandle( hDebugEventThread );
        !           211: 
        !           212:   return( TRUE );
1.1       root      213: }
                    214: 
                    215: 
                    216: // ************************************************************************
                    217: // FUNCTION : ChooseNewFont( HWND )
                    218: // PURPOSE  : Choose the displayed font of the debug event listbox
                    219: // COMMENTS : Return TRUE on success else FALSE
                    220: // ************************************************************************
                    221: BOOL
                    222: ChooseNewFont( HWND hWndOwner )
                    223: {
                    224:   static CHOOSEFONT ChooseFontStruct;
                    225:   static BOOL       fFirstTime = TRUE;
                    226: 
                    227:   if( fFirstTime ) {
                    228:     fFirstTime = FALSE;
                    229: 
                    230:     ChooseFontStruct.lStructSize    = sizeof( CHOOSEFONT );
                    231:     ChooseFontStruct.hwndOwner      = hWndOwner;
                    232:     ChooseFontStruct.hDC            = (HDC) NULL;
                    233:     ChooseFontStruct.lpLogFont      = &LogFont;
                    234:     ChooseFontStruct.iPointSize     = (int) NULL;
                    235:     ChooseFontStruct.Flags          = CF_INITTOLOGFONTSTRUCT |
                    236:                                       CF_SCREENFONTS | CF_EFFECTS;
                    237:     ChooseFontStruct.rgbColors      = rgbColor;
                    238:     ChooseFontStruct.lCustData      = (DWORD) NULL;
                    239:     ChooseFontStruct.lpfnHook       = (LPCFHOOKPROC) NULL;
                    240:     ChooseFontStruct.lpTemplateName = (LPSTR) NULL;
                    241:     ChooseFontStruct.hInstance      = (HANDLE) NULL;
                    242:     ChooseFontStruct.lpszStyle      = (LPSTR) NULL;
                    243:     ChooseFontStruct.nFontType      = SCREEN_FONTTYPE;
                    244:     ChooseFontStruct.nSizeMin       = (int) NULL;
                    245:     ChooseFontStruct.nSizeMax       = (int) NULL;
                    246:   }
                    247: 
                    248:   if( ChooseFont( &ChooseFontStruct ) ) {
                    249:     HDC    hDC;
                    250: 
                    251:     hFont = CreateFontIndirect( &LogFont );
                    252:     hDC = GetDC( hWndOwner );
                    253:     SelectObject( hDC, hFont );
                    254:     rgbColor = ChooseFontStruct.rgbColors;
                    255:     InvalidateRect( hWndOwner, NULL, TRUE );
                    256:     SendMessage( hWndOwner, WM_CTLCOLORLISTBOX, (DWORD) hDC,
                    257:       (LONG) hWndOwner );
                    258:     SendMessage( hWndOwner, WM_SETFONT, (DWORD) hFont, TRUE );
                    259:     ReleaseDC( hWndOwner, hDC );
                    260:   }
                    261: 
                    262:   return( TRUE );
                    263: }
                    264: 
                    265: 
                    266: // ************************************************************************
                    267: // FUNCTION : ChooseNewBkColor( HWND )
                    268: // PURPOSE  : Choose the background color of the debug event listbox
                    269: // COMMENTS : Return TRUE on success else FALSE
                    270: // ************************************************************************
                    271: BOOL
                    272: ChooseNewBkColor( HWND hWndOwner )
                    273: {
                    274:   static BOOL        fFirstTime = TRUE;
                    275:   static CHOOSECOLOR ChooseColorStruct;
                    276:   static DWORD       dwCustColors[16];
                    277: 
                    278:   if( fFirstTime ) {
                    279:     int i;
                    280: 
                    281:     fFirstTime = FALSE;
                    282: 
                    283:     //-- set the custom colors to white
                    284:     for( i = 0; i < 16; i++ )
                    285:       dwCustColors[i] = RGB(255,255,255);
                    286: 
                    287:     ChooseColorStruct.lStructSize    = sizeof( CHOOSECOLOR );
                    288:     ChooseColorStruct.hwndOwner      = hWndOwner;
                    289:     ChooseColorStruct.hInstance      = (HANDLE) NULL;
                    290:     ChooseColorStruct.rgbResult      = rgbBkColor;
                    291:     ChooseColorStruct.lpCustColors   = (LPDWORD) dwCustColors;
                    292:     ChooseColorStruct.Flags          = CC_RGBINIT;
                    293:     ChooseColorStruct.lCustData      = 0L;
                    294:     ChooseColorStruct.lpfnHook       = (LPCCHOOKPROC) NULL;
                    295:     ChooseColorStruct.lpTemplateName = (LPSTR) NULL;
                    296:   }
                    297: 
                    298:   if( ChooseColor( &ChooseColorStruct ) ) {
                    299:     HDC    hDC;
                    300: 
                    301:     rgbBkColor = (COLORREF) ChooseColorStruct.rgbResult;
                    302:     hDC = GetDC( hWndOwner );
                    303:     SendMessage( hWndOwner, WM_CTLCOLORLISTBOX, (DWORD) hDC,
                    304:       (LONG) hWndOwner );
                    305:     ReleaseDC( hWndOwner, hDC );
                    306:     InvalidateRect( hWndOwner, NULL, TRUE );
                    307:   }
                    308: 
                    309:   return( TRUE );
                    310: }
                    311: 
                    312: 
                    313: // ************************************************************************
                    314: // FUNCTION : OutOfMemoryMessage( VOID )
                    315: // PURPOSE  : If called, displays an "Out of Memory" message box
                    316: // COMMENTS :
                    317: // ************************************************************************
                    318: VOID
                    319: OutOfMemoryMessage( VOID )
                    320: {
                    321:   MessageBox(
                    322:     GetFocus(),
                    323:     (LPCTSTR) "Out of Memory",
                    324:     (LPCTSTR) "Memory Error",
                    325:     MB_ICONSTOP | MB_APPLMODAL );
                    326: 
                    327:   return;
                    328: }
                    329: 
                    330: 
                    331: // ************************************************************************
                    332: // FUNCTION : CopyListBoxToClipboard( HWND, LONG )
                    333: // PURPOSE  : Copies the entire contents of a listbox into the clipboard.
                    334: // COMMENTS : Returns TRUE on success, FALSE otherwise
                    335: // ************************************************************************
                    336: BOOL
                    337: CopyListBoxToClipboard( HWND hWndListBox, LONG MaxStrLen )
                    338: {
                    339:   LPTSTR  lpDataBuffer;
                    340:   HGLOBAL hDataBuffer;
                    341: 
                    342:   TCHAR  TempBuffer[256];
                    343:   DWORD  dwItemCount;
                    344:   DWORD  Count;
                    345:   LONG   StrLen;
                    346:   DWORD  dwMemSize;
                    347: 
                    348:   dwItemCount = (DWORD) SendMessage( hWndListBox, LB_GETCOUNT, 0 , 0 );
                    349:   dwMemSize = dwItemCount * (DWORD) MaxStrLen;
                    350: 
                    351:   //-- limit the size copied to the clipboard
                    352:   if( dwMemSize > 0xFFFFF )
                    353:     dwMemSize = 0xFFFFF;
                    354: 
                    355:   if( !(hDataBuffer = GlobalAlloc( GMEM_DDESHARE, dwMemSize ) ) ) {
                    356:     OutOfMemoryMessage();
                    357:     return( FALSE );
                    358:   }
                    359:   if( !(lpDataBuffer = (LPTSTR) GlobalLock( hDataBuffer ) ) ) {
                    360:     GlobalFree( hDataBuffer );
                    361:     OutOfMemoryMessage();
                    362:     return( FALSE );
                    363:   }
                    364: 
                    365:   *lpDataBuffer = '\0';
                    366: 
                    367:   for( Count = 0; Count < dwItemCount; Count++ ) {
                    368:     StrLen = SendMessage( hWndListBox, LB_GETTEXTLEN, Count, 0L );
                    369:     if( StrLen > (sizeof(TempBuffer)-3) )
                    370:       continue;
                    371:     StrLen = SendMessage( hWndListBox, LB_GETTEXT, Count, (LPARAM) TempBuffer );
                    372:     TempBuffer[StrLen]   = '\r';
                    373:     TempBuffer[StrLen+1] = '\n';
                    374:     TempBuffer[StrLen+2] = '\0';
                    375:     lstrcat( lpDataBuffer, TempBuffer );
                    376:   }
                    377: 
                    378:   GlobalUnlock( hDataBuffer );
                    379: 
                    380:   if( !OpenClipboard( hWndListBox ) ) {
                    381:     Sleep( 250 );  // wait a quarter second and try again.
                    382:     if( !OpenClipboard( hWndListBox ) ) {
                    383:       MessageBox( GetFocus(),
                    384:         (LPCTSTR) "Could not open the Clipboard!",
                    385:         (LPCTSTR) "Cannot Open Clipboard",
                    386:         MB_ICONSTOP | MB_APPLMODAL );
                    387:       GlobalFree( hDataBuffer );
                    388:       return( FALSE );
                    389:     }
                    390:   }
                    391:   if( !EmptyClipboard() ) {
                    392:     MessageBox( GetFocus(),
                    393:       (LPCTSTR) "Could not empty the Clipboard!",
                    394:       (LPCTSTR) "Cannot Empty Clipboard",
                    395:       MB_ICONSTOP | MB_APPLMODAL );
                    396:     GlobalFree( hDataBuffer );
                    397:     return( FALSE );
                    398:   }
                    399:   if( !SetClipboardData( CF_TEXT, hDataBuffer ) ) {
                    400:     MessageBox( GetFocus(),
                    401:       (LPCTSTR) "Could not copy data to the Clipboard!",
                    402:       (LPCTSTR) "Cannot Set Clipboard Data",
                    403:       MB_ICONSTOP | MB_APPLMODAL );
                    404:     GlobalFree( hDataBuffer );
                    405:     return( FALSE );
                    406:   }
                    407:   CloseClipboard();
                    408: 
                    409:   return( TRUE );
                    410: }
                    411: 
                    412: // ************************************************************************
                    413: // FUNCTION : ListBoxInsert( HWND, LPLONG, LPCTSTR )
                    414: // PURPOSE  : Inserts the string into the listbox.
                    415: // COMMENTS : Returns the index of the string inserted
                    416: // ************************************************************************
                    417: LONG
                    418: ListBoxInsert( HWND hWndListBox, LPLONG lpMaxStrLen, LPCTSTR lpszString )
                    419: {
                    420:   static LONG MaxTextExtent = 0;
                    421: 
                    422:   LONG idx;
                    423: 
                    424:   if( lpszString == NULL ) {
                    425:     MaxTextExtent = 0;
                    426:     SendMessage( hWndListBox, LB_SETHORIZONTALEXTENT, 0, 0 );
                    427:     return( 0 );
                    428:   }
                    429: 
                    430:   if( hWndListBox != NULL ) {
                    431:     HDC  hDC;
                    432:     SIZE size;
                    433:     LONG StrLen;
                    434: 
                    435:     if( (StrLen = lstrlen( lpszString)) > *lpMaxStrLen )
                    436:       *lpMaxStrLen = StrLen;
                    437: 
                    438:     hDC = GetDC( hWndListBox );
                    439:     SelectObject( hDC, hFont );
                    440:     GetTextExtentPoint( hDC, lpszString, StrLen, &size );
                    441:     ReleaseDC( hWndListBox, hDC );
                    442: 
                    443:     if( size.cx > MaxTextExtent ) {
                    444:       MaxTextExtent = size.cx;
                    445:       SendMessage( hWndListBox, LB_SETHORIZONTALEXTENT, (WPARAM) (MaxTextExtent*1.1), 0 );
                    446:     }
                    447: 
                    448:     SendMessage( hWndListBox, WM_SETREDRAW, (WPARAM) FALSE, 0 );
                    449:     idx = SendMessage( hWndListBox, LB_ADDSTRING, 0, (LPARAM) lpszString );
                    450:     SendMessage( hWndListBox, WM_SETREDRAW, (WPARAM) TRUE, 0 );
                    451:     SendMessage( hWndListBox, LB_SETCURSEL, idx, 0 );
                    452:   }
                    453: 
                    454:   return( idx );
                    455: }
                    456: 
                    457: 
                    458: // ************************************************************************
                    459: // FUNCTION : ListBoxPrintF( LPCTSTR, ... )
                    460: // PURPOSE  : Inserts the string format into the Debug Event listbox.
                    461: // COMMENTS : Returns the index of the string inserted
                    462: // ************************************************************************
                    463: LONG
                    464: ListBoxPrintF( LPCTSTR szFormat, ... )
                    465: {
                    466:   va_list valist;
                    467:   static TCHAR szBuf[1024];
                    468:   int n;
                    469: 
                    470:   va_start(valist, szFormat);
                    471:   n = wvsprintf( szBuf, szFormat, valist );
                    472: 
                    473:   return ( ListBoxInsert( hWndDebugList, &MaxStrLen, szBuf ) );
                    474: }
                    475: 
                    476: 
                    477: // ************************************************************************
                    478: // FUNCTION : MakeDebugEventString( LPCTSTR, LPCTSTR, LPDEBUG_EVENT )
                    479: // PURPOSE  : Fill in the Debug Event information into a string buffer
                    480: // COMMENTS : The string buffer contains the information common to all
                    481: //            debug events (PID, TID, Event).
                    482: // ************************************************************************
                    483: BOOL
                    484: MakeDebugEventString(LPTSTR lpszDebugEventBuffer, LPCTSTR lpszDebugEventName,
                    485:   LPDEBUG_EVENT lpDebugEvent)
                    486: {
                    487:   TCHAR szTempBuf[9];
                    488:   TCHAR szTempBuf2[9];
                    489: 
                    490:   wsprintf( lpszDebugEventBuffer, (LPCTSTR) "Pid:%s \tTid:%s \t%s",
                    491:     (LPTSTR) LongToCharUpper( (LONG) lpDebugEvent->dwProcessId, szTempBuf, 16),
                    492:     (LPTSTR) LongToCharUpper( (LONG) lpDebugEvent->dwThreadId, szTempBuf2, 16),
                    493:     lpszDebugEventName );
                    494: 
                    495:   return( TRUE );
                    496: }
                    497: 
                    498: 
                    499: // ************************************************************************
                    500: // FUNCTION : OrderFunc( PNODE, PNODE );
                    501: // PURPOSE  : Provides the sorting/search logic for the double linked
                    502: //            list package
                    503: // COMMENTS : Sorted by thread ID value
                    504: // ************************************************************************
                    505: int
                    506: OrderFunc( PNODE NodeOne, PNODE NodeTwo )
                    507: {
                    508:   if( (NodeOne->NodeData).dwThreadId < (NodeTwo->NodeData).dwThreadId )
                    509:     return( LEFT_OF );
                    510: 
                    511:   if( (NodeOne->NodeData).dwThreadId > (NodeTwo->NodeData).dwThreadId )
                    512:     return( RIGHT_OF );
                    513: 
                    514:   return( MATCH );
                    515: }
                    516: 
                    517: 
                    518: // ************************************************************************
                    519: // FUNCTION : EnumProcessListFunc( HWND, LPARAM )
                    520: // PURPOSE  : Callback function for EnumWindows
                    521: // COMMENTS : Inserts found window title strings into the listbox.
                    522: //            Return !NULL to continue enumeration.
                    523: // ************************************************************************
                    524: BOOL CALLBACK
                    525: EnumProcessListFunc( HWND hWnd, LPARAM lParam )
                    526: {
                    527:   static DWORD dwCurrentProcessId;
                    528:   static BOOL  fFirstTime = TRUE;
                    529:   static LONG  MaxStrLen  = 0;
                    530: 
                    531:   HWND   hWndListBox  = (HWND) lParam;
                    532:   TCHAR  TextBuf[256];
                    533:   DWORD  dwProcessId;
                    534:   LONG   idx;
                    535: 
                    536:   if( fFirstTime ) {
                    537:     fFirstTime = FALSE;
                    538:     dwCurrentProcessId = GetCurrentProcessId();
                    539:   }
                    540: 
                    541:   if( hWnd ) {
                    542:     GetWindowText( hWnd, (LPTSTR) &TextBuf, 256 );
                    543:     if( *TextBuf ) {
                    544:       GetWindowThreadProcessId( hWnd, &dwProcessId );
                    545:       if( dwProcessId != dwCurrentProcessId ) {
                    546:         idx = ListBoxInsert( hWndListBox, &MaxStrLen, TextBuf );
                    547:         SendMessage( hWndListBox, LB_SETITEMDATA, (UINT) idx,
                    548:           (LONG) dwProcessId );
                    549:       }
                    550:     }
                    551:   }
                    552: 
1.1.1.2 ! root      553:   return( TRUE );
1.1       root      554: }
                    555: 
                    556: 
                    557: // ========================================================================
                    558: // helper functions (use global variables)
                    559: // ========================================================================
                    560: 
                    561: 
                    562: // ************************************************************************
                    563: // FUNCTION : GetPrivateProfileSettings( LPCTSTR, LPCTSTR )
                    564: // PURPOSE  : Retrieves the stored preferences and options from the
                    565: //            profile (registry)
                    566: // COMMENTS :
                    567: // ************************************************************************
                    568: BOOL
                    569: GetPrivateProfileSettings( LPCTSTR lpszAppTitle, LPCTSTR lpszIniPathName )
                    570: {
                    571:   xPos    = (int) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "xPos",    (DWORD) CW_USEDEFAULT, lpszIniPathName );
                    572:   yPos    = (int) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "yPos",    (DWORD) CW_USEDEFAULT, lpszIniPathName );
                    573:   nWidth  = (int) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "nWidth",  (DWORD) CW_USEDEFAULT, lpszIniPathName );
                    574:   nHeight = (int) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "nHeight", (DWORD) CW_USEDEFAULT, lpszIniPathName );
                    575: 
                    576:   fMaximized       = (BOOL) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "fMaximized",       FALSE, lpszIniPathName );
                    577:   fToolBar         = (BOOL) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "fToolBar",         TRUE,  lpszIniPathName );
                    578:   fSavedDirectory  = (BOOL) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "fSavedDirectory",  TRUE,  lpszIniPathName );
                    579:   fSavePreferences = (BOOL) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "fSavePreferences", FALSE, lpszIniPathName );
                    580:   fSaveOnExit      = (BOOL) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "fSaveOnExit",      TRUE,  lpszIniPathName );
                    581:   fClearOnNew      = (BOOL) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "fClearOnNew",      TRUE,  lpszIniPathName );
                    582:   fVerbose         = (BOOL) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "fVerbose",         FALSE, lpszIniPathName );
                    583:   fShowSymbols     = (BOOL) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "fShowSymbols",     FALSE, lpszIniPathName );
                    584: 
                    585:   DebugMode        = (LONG) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "DebugMode",       DEBUG_PROCESS        , lpszIniPathName );
                    586:   DebugeePriority  = (LONG) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "DebugeePriority", NORMAL_PRIORITY_CLASS, lpszIniPathName );
                    587: 
                    588:   GetPrivateProfileString( lpszAppTitle, (LPCTSTR) "InitialDir", NULL, szInitialDir,
                    589:     sizeof( szInitialDir ), lpszIniPathName );
                    590: 
                    591:   LogFont.lfHeight         = (LONG) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "lfHeight",         13   ,       lpszIniPathName ) * -1L;
                    592:   LogFont.lfWidth          = (LONG) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "lfWidth",          0    ,       lpszIniPathName );
                    593:   LogFont.lfWeight         = (LONG) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "lfWeight",         400  ,       lpszIniPathName );
                    594:   LogFont.lfItalic         = (BYTE) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "lfItalic",         FALSE,       lpszIniPathName );
                    595:   LogFont.lfUnderline      = (BYTE) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "lfUnderline",      FALSE,       lpszIniPathName );
                    596:   LogFont.lfStrikeOut      = (BYTE) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "lfStrikeOut",      FALSE,       lpszIniPathName );
                    597:   LogFont.lfPitchAndFamily = (BYTE) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "lfPitchAndFamily", FF_DONTCARE, lpszIniPathName );
                    598: 
                    599:   GetPrivateProfileString( lpszAppTitle, (LPCTSTR) "lfFaceName", (LPCTSTR) "Arial", LogFont.lfFaceName,
                    600:     LF_FACESIZE, lpszIniPathName );
                    601: 
                    602:   rgbColor   = (COLORREF) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "rgbColor",
                    603:                             GetSysColor(COLOR_WINDOWTEXT), lpszIniPathName );
                    604:   rgbBkColor = (COLORREF) GetPrivateProfileInt( lpszAppTitle, (LPCTSTR) "rgbBkColor",
                    605:                             GetSysColor(COLOR_WINDOW), lpszIniPathName );
                    606:   return( TRUE );
                    607: }
                    608: 
                    609: 
                    610: // ************************************************************************
                    611: // FUNCTION : WritePrivateProfileSettings( LPCTSTR, LPCTSTR )
                    612: // PURPOSE  : Saves the preferences and options to the profile (registry)
                    613: // COMMENTS :
                    614: // ************************************************************************
                    615: BOOL
                    616: WritePrivateProfileSettings( LPCTSTR lpszAppTitle, LPCTSTR lpszIniPathName )
                    617: {
                    618:   if( fSaveOnExit ) {
                    619:     WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "xPos",    xPos,    lpszIniPathName );
                    620:     WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "yPos",    yPos,    lpszIniPathName );
                    621:     WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "nWidth",  nWidth,  lpszIniPathName );
                    622:     WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "nHeight", nHeight, lpszIniPathName );
                    623: 
                    624:     WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "fMaximized",       fMaximized,       lpszIniPathName );
                    625:     WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "fToolBar",         fToolBar,         lpszIniPathName );
                    626:     WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "fSavedDirectory",  fSavedDirectory,  lpszIniPathName );
                    627:     WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "fSavePreferences", fSavePreferences, lpszIniPathName );
                    628: 
                    629:     if( fSavePreferences ) {
                    630:       WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "fClearOnNew",  fClearOnNew,  lpszIniPathName );
                    631:       WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "fVerbose",     fVerbose,     lpszIniPathName );
                    632:       WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "fShowSymbols", fShowSymbols, lpszIniPathName );
                    633: 
                    634:       WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "DebugMode",       DebugMode,       lpszIniPathName );
                    635:       WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "DebugeePriority", DebugeePriority, lpszIniPathName );
                    636:     }
                    637: 
                    638:     WritePrivateProfileString( lpszAppTitle, (LPCTSTR) "InitialDir", szInitialDir, lpszIniPathName );
                    639: 
                    640:     WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "lfHeight",         (INT) abs(LogFont.lfHeight),    lpszIniPathName );
                    641:     WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "lfWidth",          (INT) LogFont.lfWidth,          lpszIniPathName );
                    642:     WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "lfWeight",         (INT) LogFont.lfWeight,         lpszIniPathName );
                    643:     WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "lfItalic",         (INT) LogFont.lfItalic,         lpszIniPathName );
                    644:     WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "lfUnderline",      (INT) LogFont.lfUnderline,      lpszIniPathName );
                    645:     WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "lfStrikeOut",      (INT) LogFont.lfStrikeOut,      lpszIniPathName );
                    646:     WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "lfPitchAndFamily", (INT) LogFont.lfPitchAndFamily, lpszIniPathName );
                    647: 
                    648:     WritePrivateProfileString( lpszAppTitle, (LPCTSTR) "lfFaceName", LogFont.lfFaceName, lpszIniPathName );
                    649: 
                    650:     WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "rgbColor",   rgbColor  , lpszIniPathName );
                    651:     WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "rgbBkColor", rgbBkColor, lpszIniPathName );
                    652:   }
                    653:   WritePrivateProfileInt( lpszAppTitle, (LPCTSTR) "fSaveOnExit", fSaveOnExit, lpszIniPathName );
                    654: 
                    655:   return( TRUE );
                    656: }
                    657: 
                    658: 
                    659: // ************************************************************************
                    660: // FUNCTION : UpdateMenuSettings( VOID )
                    661: // PURPOSE  : Adds check marks to active menu items
                    662: // COMMENTS :
                    663: // ************************************************************************
                    664: BOOL
                    665: UpdateMenuSettings( VOID )
                    666: {
                    667:   if( fToolBar )
                    668:     CheckMenuItem( GetMenu( hWndMain), IDM_OPTIONS_TOOLBAR, MF_CHECKED );
                    669:   if( fSavedDirectory )
                    670:     CheckMenuItem( GetMenu( hWndMain), IDM_OPTIONS_SAVEDDIR, MF_CHECKED );
                    671:   if( fSaveOnExit )
                    672:     CheckMenuItem( GetMenu( hWndMain), IDM_OPTIONS_SAVEONEXIT, MF_CHECKED );
                    673: 
                    674:   return( TRUE );
                    675: }
                    676: 
                    677: 
                    678: // ************************************************************************
                    679: // FUNCTION : SubclassWindow( HWND, WNDPROC )
                    680: // PURPOSE  : Subclasses a window procedure
                    681: // COMMENTS : Returns the old window procedure
                    682: // ************************************************************************
                    683: WNDPROC
                    684: SubclassWindow( HWND hWnd, WNDPROC NewWndProc)
                    685: {
                    686:   WNDPROC OldWndProc;
                    687: 
                    688:   OldWndProc = (WNDPROC) GetWindowLong( hWnd, GWL_WNDPROC );
                    689:   SetWindowLong( hWnd, GWL_WNDPROC, (LONG) NewWndProc );
                    690: 
                    691:   return OldWndProc;
                    692: }
                    693: 
                    694: 
                    695: // ************************************************************************
                    696: // FUNCTION: WritePrivateProfileInt( LPCTSTR, LPCTSTR, INT, LPCTSTR )
                    697: // PURPOSE : Writes the value of an integer from a specified keyname within
                    698: //           a specified section of the Private Profile
                    699: // COMMENTS: Matched pair to GetPrivateProfileInt
                    700: // ************************************************************************
                    701: BOOL
                    702: WritePrivateProfileInt( LPCTSTR lpAppName, LPCTSTR lpKeyName, INT Value, LPCTSTR lpFileName )
                    703: {
                    704:   TCHAR ValBuf[16];
                    705: 
                    706:   wsprintf( ValBuf, (LPCSTR) "%i", Value);
                    707: 
                    708:   return( WritePrivateProfileString( lpAppName, lpKeyName, ValBuf, lpFileName ) );
                    709: }
                    710: 
                    711: 
                    712: // ************************************************************************
                    713: // FUNCTION : SendWmSizeMessage( HWND )
                    714: // PURPOSE  : Sends a WM_SIZE message containing the current size
                    715: // COMMENTS : Forces a WM_SIZE message without actually changing the size
                    716: // ************************************************************************
                    717: BOOL
                    718: SendWmSizeMessage( HWND hWnd )
                    719: {
                    720:   RECT rect;
                    721: 
                    722:   if( !GetClientRect( hWnd, &rect ) )
                    723:     return( FALSE );
                    724: 
                    725:   return( SendMessage( hWndMain, WM_SIZE, SIZENORMAL,
                    726:             MAKELONG( rect.right - rect.left, rect.bottom - rect.top) ) );
                    727: }
                    728: 
                    729: 
                    730: // ************************************************************************
                    731: // FUNCTION : GetPathFromFullPathName( LPCTSTR, LPTSTR, UINT )
                    732: // PURPOSE  : Extracts the path given a full pathname
                    733: // COMMENTS :
                    734: // ************************************************************************
                    735: UINT
                    736: GetPathFromFullPathName( LPCTSTR lpFullPathName, LPTSTR lpPathBuffer,
                    737:   UINT nPathBufferLength )
                    738: {
                    739:   UINT nLength;
                    740:   int i;
                    741: 
                    742:   if( (nLength = (UINT) lstrlen( lpFullPathName ) ) > nPathBufferLength )
                    743:     return( nLength );
                    744: 
                    745:   lstrcpy( lpPathBuffer, lpFullPathName );
                    746: 
                    747:   for( i = lstrlen( lpPathBuffer );
                    748:        (lpPathBuffer[i] != '\\') && (lpPathBuffer[i] != ':');
                    749:        i-- )
                    750:   ;
                    751:   if( lpPathBuffer[i] == ':' )
                    752:     lpPathBuffer[i+1] = '\0';
                    753:   else
                    754:     lpPathBuffer[i] = '\0';
                    755: 
                    756:   return( (UINT) i );
                    757: }
                    758: 
                    759: 
                    760: // ************************************************************************
                    761: // FUNCTION : LongToCharUpper( long, LPTSTR, int )
                    762: // PURPOSE  : Converts a long to an upper-case string
                    763: // COMMENTS :
                    764: // ************************************************************************
                    765: LPTSTR
                    766: LongToCharUpper( long Value, LPTSTR String, int Radix )
                    767: {
                    768:   if( Radix > 10 )
                    769:     return( CharUpper( (LPTSTR) ltoa( Value, (LPSTR) String, Radix ) ) );
                    770: 
                    771:   return( (LPTSTR) ltoa( Value, (LPSTR) String, Radix ) );
                    772: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.