|
![](/i/fill.gif) |
Here's the code I wrote to save the Enabled status of my GUIEXT.
There are two methods SavePrefs(InstanceStruct) and
LoadPrefs(InstanceStruct).
You need to define REGKEY_ROOT near the top of your guiext.c file.
I put mine near the #define AUTHOR, and #define EMAIL.
Something like:
#define REGKEY_ROOT "Software\\MyCompany\\MyGUIEXT\\"
This is the key under HKCU where the registry keys will be placed.
I catch the error codes, but right now nothing is done with them.
What should I do if an error occurs during this process? Just ignore it?
Set Enabled false? Popup a error dialog to the user? What's the desired
POV error handling approach for GUIEXTs?
void SavePrefs(InstanceStruct *Instance) {
LONG error;
DWORD dispositionValue;
HKEY guiextHKey;
DWORD value;
error = RegCreateKeyEx( HKEY_CURRENT_USER, // Parent hKey.
REGKEY_ROOT, // Path to child.
0, // reserved
"", // Type of node to create,
ignored if entry already exists..
1, // Behavior options
(volatile/non-volatile).
KEY_ALL_ACCESS, // Requested access to key.
NULL, // Security structure that we
don't have.
&guiextHKey, // The child's hKey.
&dispositionValue // Whether the entry was
create or simply opened.
);
value = Instance->Enabled ? 1 : 0;
error = RegSetValueEx( guiextHKey, // HKey to set the value on.
"Enabled", // The name of the value under the
hkey to set the value on.
0, // reserved.
REG_DWORD,
(BYTE*)&value,
4
);
if(error != 0) {
error = RegCloseKey(guiextHKey);
Instance->Enabled = TRUE;
SavePrefs(Instance);
} else {
error = RegCloseKey(guiextHKey);
Instance->Enabled = (DWORD)*data;
}
}
void LoadPrefs(InstanceStruct *Instance) {
LONG error;
DWORD dispositionValue;
HKEY guiextHKey;
DWORD type;
DWORD length;
char data[4];
error = RegCreateKeyEx( HKEY_CURRENT_USER, // Parent hKey.
REGKEY_ROOT, // Path to child.
0, // reserved
"", // Type of node to create,
ignored if entry already exists..
1, // Behavior options
(volatile/non-volatile).
KEY_ALL_ACCESS, // Requested access to key.
NULL, // Security structure that we
don't have.
&guiextHKey, // The child's hKey.
&dispositionValue
);
error = RegQueryValueEx( guiextHKey, // HKey to set the value on.
"Enabled", // The name of the value under the
hkey to set the value on.
0, // reserved.
&type,
data,
&length
);
error = RegCloseKey(guiextHKey);
Instance->Enabled = (DWORD)*data;
}
DWORD WINAPI MenuSelect (IDataStruct *InstanceData, WPARAM Code)
{
InstanceStruct *Instance = (InstanceStruct *)
InstanceData->InstanceID ;
ExternalVarStruct ExternalVars;
switch(Code) {
case CM_ENABLED :
Instance->Enabled = !Instance->Enabled ;
CheckMenuItem (InstanceData->hMenu, CM_ENABLED +
InstanceData->FirstMenuItem, Instance->Enabled ? MF_CHECKED : MF_UNCHECKED)
;
SavePrefs(Instance); // *** Here's where SavePrefs goes.
return(0) ;
...
...
// READ THIS FROM AN INI FILE ! it should be persistent.
//Instance->Enabled = TRUE ;
LoadPrefs(Instance); // *** Here's where LoadPrefs goes.
--
#macro Q(A,E,W)box{-A/2,A/2pigment{rgb 9*W}translate E*A+W/1000}#end#macro
M(D,E)#local A=1/pow(3,D);#if(D<3)#local C=D+1;union{M(C,1)M(C,x+y)M(C,x+z)
M(C,y+z)M(C,x+y-z)M(C,x+z-y)M(C,y+z-x)M(C,x-y)M(C,z-x)M(C,y-z)M(C,y-x)M(C,
x-z)M(C,z-y)M(C,x-y-z)M(C,y-x-z)M(C,z-x-y)translate A*E}#else Q(A,E,x)Q(A,E
,y)Q(A,E,z)#end#end union{M(0,0)rotate<45,145,0>translate z*2}//Andrew
Post a reply to this message
|
![](/i/fill.gif) |