registry config function modifications, prepping for future error handling
This commit is contained in:
@@ -115,19 +115,17 @@ BOOL IsProgMgrDefaultShell()
|
|||||||
Finds and collapses all settings
|
Finds and collapses all settings
|
||||||
and saves them to the registry.
|
and saves them to the registry.
|
||||||
RETURNS -
|
RETURNS -
|
||||||
TRUE if successful, FALSE if unsuccessful.
|
RCE_* configuration error value
|
||||||
\* * * */
|
\* * * */
|
||||||
BOOL SaveConfig(BOOL bPos, BOOL bSettings, BOOL bGroups)
|
DWORD SaveConfig(BOOL bSettings, BOOL bPos, BOOL bGroups)
|
||||||
{
|
{
|
||||||
BOOL bConfigStatus = TRUE;
|
DWORD bConfigStatus = RCE_SUCCESS;
|
||||||
WINDOWPLACEMENT wpProgMgr;
|
|
||||||
RECT rcWindow;
|
|
||||||
|
|
||||||
if (bSettings)
|
if (bSettings)
|
||||||
{
|
{
|
||||||
// Shrink the settings into the bitmask and save it
|
// Shrink the settings into the bitmask and save it
|
||||||
// There's definitely a better way to do this but...
|
// There's definitely a better way to do this but...
|
||||||
// I'll get to it later :)
|
// TODO: do this more efficiently
|
||||||
dwSettingsMask =
|
dwSettingsMask =
|
||||||
(bAutoArrange && PMS_AUTOARRANGE) * PMS_AUTOARRANGE |
|
(bAutoArrange && PMS_AUTOARRANGE) * PMS_AUTOARRANGE |
|
||||||
(bMinOnRun && PMS_MINONRUN) * PMS_MINONRUN |
|
(bMinOnRun && PMS_MINONRUN) * PMS_MINONRUN |
|
||||||
@@ -137,11 +135,14 @@ BOOL SaveConfig(BOOL bPos, BOOL bSettings, BOOL bGroups)
|
|||||||
|
|
||||||
if (!RegSetValueEx(hKeySettings, pszSettingsMask, 0, REG_DWORD,
|
if (!RegSetValueEx(hKeySettings, pszSettingsMask, 0, REG_DWORD,
|
||||||
(const BYTE*)&dwSettingsMask, sizeof(dwSettingsMask)) == ERROR_SUCCESS)
|
(const BYTE*)&dwSettingsMask, sizeof(dwSettingsMask)) == ERROR_SUCCESS)
|
||||||
bConfigStatus = FALSE;
|
bConfigStatus = bConfigStatus && RCE_SETTINGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bPos)
|
if (bPos)
|
||||||
{
|
{
|
||||||
|
WINDOWPLACEMENT wpProgMgr;
|
||||||
|
RECT rcWindow;
|
||||||
|
|
||||||
// Get and save window position
|
// Get and save window position
|
||||||
wpProgMgr.length = sizeof(WINDOWPLACEMENT);
|
wpProgMgr.length = sizeof(WINDOWPLACEMENT);
|
||||||
GetWindowPlacement(hWndProgMgr, &wpProgMgr);
|
GetWindowPlacement(hWndProgMgr, &wpProgMgr);
|
||||||
@@ -149,42 +150,64 @@ BOOL SaveConfig(BOOL bPos, BOOL bSettings, BOOL bGroups)
|
|||||||
|
|
||||||
if (!RegSetValueEx(hKeySettings, pszSettingsWindow, 0, REG_BINARY,
|
if (!RegSetValueEx(hKeySettings, pszSettingsWindow, 0, REG_BINARY,
|
||||||
(const BYTE*)&rcWindow, sizeof(rcWindow)) == ERROR_SUCCESS)
|
(const BYTE*)&rcWindow, sizeof(rcWindow)) == ERROR_SUCCESS)
|
||||||
bConfigStatus = FALSE;
|
bConfigStatus = bConfigStatus && RCE_POSITION;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bGroups)
|
||||||
|
{
|
||||||
|
// TODO: Get list of groups, iterate through,
|
||||||
|
// save each one as an individual subkey based
|
||||||
|
// on the name of the group
|
||||||
|
bConfigStatus = bConfigStatus && RCE_GROUPS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return bConfigStatus;
|
return bConfigStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* * * *\
|
/* * * *\
|
||||||
BOOL LoadConfig() -
|
LoadConfig() -
|
||||||
Finds all settings and retrieves them
|
Finds all settings and retrieves them
|
||||||
from the registry.
|
from the registry.
|
||||||
RETURNS -
|
RETURNS -
|
||||||
TRUE if successful, FALSE if unsuccessful.
|
RCE_* configuration error value
|
||||||
\* * * */
|
\* * * */
|
||||||
BOOL LoadConfig()
|
DWORD LoadConfig(BOOL bSettings, BOOL bPos, BOOL bGroups)
|
||||||
{
|
{
|
||||||
BOOL bConfigStatus = TRUE;
|
DWORD bConfigStatus = RCE_SUCCESS;
|
||||||
DWORD dwType;
|
DWORD dwType;
|
||||||
DWORD dwBufferSize = sizeof(dwSettingsMask);
|
|
||||||
DWORD dwRectBufferSize = sizeof(rcMainWindow);
|
|
||||||
|
|
||||||
// Load settings bitmask
|
if (bSettings)
|
||||||
if (!RegQueryValueEx(hKeySettings, pszSettingsMask, 0, &dwType,
|
{
|
||||||
(LPBYTE)&dwSettingsMask, &dwBufferSize) == ERROR_SUCCESS)
|
DWORD dwBufferSize = sizeof(dwSettingsMask);
|
||||||
bConfigStatus = FALSE;
|
|
||||||
|
|
||||||
// Apply bitmask to booleans
|
// Load settings bitmask
|
||||||
bAutoArrange = (dwSettingsMask & PMS_AUTOARRANGE);
|
if (!RegQueryValueEx(hKeySettings, pszSettingsMask, 0, &dwType,
|
||||||
bMinOnRun = (dwSettingsMask & PMS_MINONRUN);
|
(LPBYTE)&dwSettingsMask, &dwBufferSize) == ERROR_SUCCESS)
|
||||||
bTopMost = (dwSettingsMask & PMS_TOPMOST);
|
bConfigStatus = bConfigStatus && RCE_SETTINGS;
|
||||||
bSaveSettings = (dwSettingsMask & PMS_SAVESETTINGS);
|
|
||||||
bShowUsername = (dwSettingsMask & PMS_SHOWUSERNAME);
|
|
||||||
|
|
||||||
// Load window position... and apply it!
|
// Apply bitmask to booleans
|
||||||
if (!RegQueryValueEx(hKeySettings, pszSettingsWindow, 0, &dwType,
|
bAutoArrange = (dwSettingsMask & PMS_AUTOARRANGE);
|
||||||
(LPBYTE)&rcMainWindow, &dwRectBufferSize) == ERROR_SUCCESS)
|
bMinOnRun = (dwSettingsMask & PMS_MINONRUN);
|
||||||
bConfigStatus = FALSE;
|
bTopMost = (dwSettingsMask & PMS_TOPMOST);
|
||||||
|
bSaveSettings = (dwSettingsMask & PMS_SAVESETTINGS);
|
||||||
|
bShowUsername = (dwSettingsMask & PMS_SHOWUSERNAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bPos)
|
||||||
|
{
|
||||||
|
DWORD dwRectBufferSize = sizeof(rcMainWindow);
|
||||||
|
|
||||||
|
// Load window position
|
||||||
|
if (!RegQueryValueEx(hKeySettings, pszSettingsWindow, 0, &dwType,
|
||||||
|
(LPBYTE)&rcMainWindow, &dwRectBufferSize) == ERROR_SUCCESS)
|
||||||
|
bConfigStatus = bConfigStatus && RCE_POSITION;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bGroups)
|
||||||
|
{
|
||||||
|
// TODO: this is unbearable
|
||||||
|
bConfigStatus = bConfigStatus && RCE_GROUPS;
|
||||||
|
}
|
||||||
|
|
||||||
return bConfigStatus;
|
return bConfigStatus;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,12 @@
|
|||||||
// #define PROGMAN_KEY L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Program Manager"
|
// #define PROGMAN_KEY L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Program Manager"
|
||||||
// #define WINDOWS_KEY L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows"
|
// #define WINDOWS_KEY L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Windows"
|
||||||
#define PROGMGR_KEY L"Software\\Vortesys\\Program Manager II"
|
#define PROGMGR_KEY L"Software\\Vortesys\\Program Manager II"
|
||||||
// Settings Bitmask Values (DWORD)
|
// Registry configuration error values (DWORD)
|
||||||
|
#define RCE_SUCCESS 0x0000000
|
||||||
|
#define RCE_SETTINGS 0x0000001
|
||||||
|
#define RCE_POSITION 0x0000002
|
||||||
|
#define RCE_GROUPS 0x0000004
|
||||||
|
// Settings values (DWORD)
|
||||||
#define PMS_AUTOARRANGE 0x00000001
|
#define PMS_AUTOARRANGE 0x00000001
|
||||||
#define PMS_MINONRUN 0x00000002
|
#define PMS_MINONRUN 0x00000002
|
||||||
#define PMS_TOPMOST 0x00000004
|
#define PMS_TOPMOST 0x00000004
|
||||||
@@ -43,5 +48,5 @@ extern RECT rcMainWindow;
|
|||||||
/* Function Prototypes */
|
/* Function Prototypes */
|
||||||
BOOL InitializeRegistryKeys(VOID);
|
BOOL InitializeRegistryKeys(VOID);
|
||||||
BOOL IsProgMgrDefaultShell(VOID);
|
BOOL IsProgMgrDefaultShell(VOID);
|
||||||
BOOL LoadConfig(VOID);
|
DWORD LoadConfig(BOOL bSettings, BOOL bPos, BOOL bGroups);
|
||||||
BOOL SaveConfig(BOOL bPos, BOOL bSettings, BOOL bGroups);
|
DWORD SaveConfig(BOOL bSettings, BOOL bPos, BOOL bGroups);
|
||||||
|
|||||||
Reference in New Issue
Block a user