diff --git a/HookMsg/MISC.Cpp b/HookMsg/MISC.Cpp new file mode 100644 index 0000000..9a84358 --- /dev/null +++ b/HookMsg/MISC.Cpp @@ -0,0 +1,174 @@ +/*****************************************************************************\ +* +* Module: misc.c +* +* Contains miscellaneous routines for the Windows debugging Spy SDK applet. +* +* Functions: +* +* ReadRegistry() +* WriteRegistry() +* +* Comments: +* +\*****************************************************************************/ + +#include "stdafx.h" +#include "spy.h" +#include + + +HKEY ghkeySpy = NULL; +CHAR gszSpyAppKey[] = "Software\\Yourisoft\\HookMsg"; +CHAR gszKeyPosition[] = "Position"; + +//LPSTR StripExtension(LPSTR pszFileName); + + + + +/*****************************************************************************\ +* ReadRegistry +* +* Opens (creates if necessary) the registry key for spy preferences and then +* reads the last saved values. +* +* Arguments: +* none +* +* Returns: +* VOID +\*****************************************************************************/ + +VOID +ReadRegistry( + VOID + ) +{ + DWORD dwType; + DWORD cbData; + + RegCreateKey(HKEY_CURRENT_USER, gszSpyAppKey, &ghkeySpy); + + cbData = gwndpl.length = sizeof(gwndpl); + if (!ghkeySpy || RegQueryValueEx(ghkeySpy, gszKeyPosition, NULL, &dwType, + (LPBYTE)&gwndpl, &cbData) != ERROR_SUCCESS) + { + gwndpl.length = 0; + } + + if (gwndpl.length != sizeof(gwndpl)) + { +/* gwndpl.length = sizeof(gwndpl); + gwndpl.flags = 0; + gwndpl.showCmd = SW_SHOWNORMAL; + gwndpl.ptMinPosition.x = 0; + gwndpl.ptMinPosition.y = 0; + gwndpl.ptMaxPosition.x = 0; + gwndpl.ptMaxPosition.y = 0; + gwndpl.rcNormalPosition.left = 10; + gwndpl.rcNormalPosition.top = 10; + gwndpl.rcNormalPosition.right = + 10 + (GetSystemMetrics(SM_CXSCREEN) / 3); + gwndpl.rcNormalPosition.bottom = + 10 + (GetSystemMetrics(SM_CYSCREEN) / 3); +*/ } +/* + for( int i=0; i< MAX_FIND; i++ ) + { + cbData = sizeof(HWND); + TCHAR szKeyName[100] = {0,}; + wsprintf( szKeyName, "HWND_%d", i ); + if (!ghkeySpy || RegQueryValueEx(ghkeySpy, szKeyName, NULL, &dwType, + (LPBYTE)&g_theApp.m_hFindWindow[i], &cbData) != ERROR_SUCCESS) + { + g_theApp.m_hFindWindow[i] = NULL; + } + } +*/ +} + + + +/*****************************************************************************\ +* WriteRegistry +* +* Writes out preference data to the registry when the app exits, then +* closes the registry key. +* +* Arguments: +* none +* +* Returns: +* VOID +\*****************************************************************************/ + +VOID +WriteRegistry( + VOID + ) +{ + if (ghkeySpy) + { + WINDOWPLACEMENT wndpl; + wndpl.length = sizeof(WINDOWPLACEMENT); + ::GetWindowPlacement( AfxGetApp()->GetMainWnd()->m_hWnd, &wndpl); + RegSetValueEx(ghkeySpy, gszKeyPosition, 0, REG_BINARY, + (LPBYTE)&wndpl, sizeof(wndpl)); +/* + for( int i=0; i< MAX_FIND; i++ ) + { + TCHAR szKeyName[100] = {0,}; + wsprintf( szKeyName, "HWND_%d", i ); + RegSetValueEx(ghkeySpy, szKeyName, 0, REG_DWORD, + (LPBYTE)&g_theApp.m_hFindWindow[i], sizeof(DWORD)); + } +*/ + + // RegSetValueEx(ghkeySpy, gszKeyHWND1, 0, REG_BINARY, + // (LPBYTE)g_theApp.m_hFindWindow[0], sizeof(HWND)); + // RegSetValueEx(ghkeySpy, gszKeyFileName, 0, REG_SZ, + // (LPBYTE)gszFile, (lstrlen(gszFile) + 1) * sizeof(TCHAR)); + + RegCloseKey(ghkeySpy); + } +} + + + +/*****************************************************************************\ +* StripExtension +* +* Strips the extension off of a filename. +* +* Arguments: +* LPSTR pszFileName - File name to process. +* +* Returns: +* Returns a pointer to the beginning of the filename. The extension +* will have been stripped off. +* +\*****************************************************************************/ +/* +PRIVATE LPSTR +StripExtension( + LPSTR pszFileName + ) +{ + LPSTR p = pszFileName; + + while (*p) + p++; + + while (p > pszFileName && *p != '\\' && *p != ':') { + p = CharPrev(pszFileName, p); + if (*p == '.') { + *p = 0; + } + } + if (*p == '\\' || *p == ':') { + p++; + } + return p; +} +*/