/************************************************************************
* registry.cpp *
* - functions for saving and loading Borgs settings in the registry *
************************************************************************/
#include <windows.h>
#include "dasm.h"
char reg_borg[]="Software\\Borg";
/************************************************************************
* save_reg_entries *
* - Saves Borgs settings to the registry :) *
* - these are just colours, fonts, version, directory and window status *
************************************************************************/
void save_reg_entries(void) {
HKEY regkey;
DWORD disposition;
DWORD rver,dsize;
COLORREF cl;
char cdir[MAX_PATH];
if (RegCreateKeyEx(HKEY_CURRENT_USER,reg_borg,0,"",REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,NULL,®key,&disposition)!=ERROR_SUCCESS) return;
// now write values out.......
dsize=sizeof(rver);
rver=BORG_VER;
RegSetValueEx(regkey,"Version",0,REG_DWORD,(LPBYTE)&rver,dsize);
GetCurrentDirectory(MAX_PATH,cdir);
dsize=lstrlen(cdir)+1;
RegSetValueEx(regkey,"Curdir",0,REG_SZ,(LPBYTE)cdir,dsize);
dsize=sizeof(COLORREF);
cl=options.bgcolor;
RegSetValueEx(regkey,"BackgroundColor",0,REG_DWORD,(LPBYTE)&cl,dsize);
cl=options.highcolor;
RegSetValueEx(regkey,"HighlightColor",0,REG_DWORD,(LPBYTE)&cl,dsize);
cl=options.textcolor;
RegSetValueEx(regkey,"TextColor",0,REG_DWORD,(LPBYTE)&cl,dsize);
cl=options.font;
RegSetValueEx(regkey,"Font",0,REG_DWORD,(LPBYTE)&cl,dsize);
RegSetValueEx(regkey,"UserFont",0,REG_BINARY,(LPBYTE)&UserFont,sizeof(UserFont));
WINDOWPLACEMENT wp;
wp.length=sizeof(wp);
GetWindowPlacement(MainWnd,&wp);
RegSetValueEx(regkey,"Winmax",0,REG_DWORD,(LPBYTE)&wp.showCmd,
sizeof(wp.showCmd));
RegSetValueEx(regkey,"Winpos",0,REG_BINARY,(LPBYTE)&wp.rcNormalPosition,
sizeof(wp.rcNormalPosition));
RegCloseKey(regkey);
}
/************************************************************************
* load_reg_entries *
* - Loads Borgs saved settings from the registry :) *
* - these are just colours, fonts, version, directory and window status *
* - settings are then restored *
************************************************************************/
void load_reg_entries(void) {
HKEY regkey;
DWORD disposition;
DWORD rver,dsize;
COLORREF cl;
char cdir[MAX_PATH];
if (RegCreateKeyEx(HKEY_CURRENT_USER,reg_borg,0,"",
REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,
NULL,®key,&disposition)!=ERROR_SUCCESS)
return;
if (disposition==REG_CREATED_NEW_KEY) {
RegCloseKey(regkey);
return;
}
dsize=sizeof(rver);
rver=0;
RegQueryValueEx(regkey,"Version",NULL,NULL,(LPBYTE)&rver,&dsize);
// now read values in.......
cdir[0]=0;
dsize=MAX_PATH;
RegQueryValueEx(regkey,"Curdir",NULL,NULL,(LPBYTE)cdir,&dsize);
if (cdir[0]) SetCurrentDirectory(cdir);
dsize=sizeof(cl);
if (RegQueryValueEx(regkey,"BackgroundColor",NULL,NULL,(LPBYTE)&cl,&dsize)==ERROR_SUCCESS)
options.bgcolor=cl;
if (RegQueryValueEx(regkey,"HighlightColor",NULL,NULL,(LPBYTE)&cl,&dsize)==ERROR_SUCCESS)
options.highcolor=cl;
if (RegQueryValueEx(regkey,"TextColor",NULL,NULL,(LPBYTE)&cl,&dsize)==ERROR_SUCCESS)
options.textcolor=cl;
if (RegQueryValueEx(regkey,"Font",NULL,NULL,(LPBYTE)&cl,&dsize)==ERROR_SUCCESS) {
options.font=(fontselection)cl;
}
dsize=sizeof(UserFont);
RegQueryValueEx(regkey,"UserFont",NULL,NULL,(LPBYTE)&UserFont,&dsize);
if (rver!=BORG_VER) {
RegCloseKey(regkey);
RegDeleteKey(HKEY_CURRENT_USER,reg_borg);
save_reg_entries();
return;
}
WINDOWPLACEMENT wp;
wp.length=sizeof(wp);
GetWindowPlacement(MainWnd,&wp);
dsize=sizeof(wp.showCmd); //=4
RegQueryValueEx(regkey,"Winmax",NULL,NULL,(LPBYTE)&wp.showCmd,&dsize);
if (wp.showCmd==SW_HIDE) wp.showCmd=SW_SHOWDEFAULT;
dsize=sizeof(wp.rcNormalPosition); //=16
RegQueryValueEx(regkey,"WinPos",NULL,NULL,(LPBYTE)&wp.rcNormalPosition,&dsize);
// BUG: Should not be done if another copy of BORG is running
SetWindowPlacement(MainWnd,&wp);
ShowWindow(MainWnd,wp.showCmd);
RegCloseKey(regkey);
}
Vorgefundene Kodierung: ASCII (7 bit) | 2
|