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