11-04-2005 06:40 PM
11-05-2005 02:43 AM
11-05-2005 09:29 AM
Thanks. I was trying to use SetPanelAttribute or something like that.
Next, I've done this with VB (saving to the registry), but how is that done in CVI?
11-05-2005 11:13 AM - edited 11-05-2005 11:13 AM
There are functions to read and write the windows registry in the programmers toolbox library. You can also access it through the windows sdk functions if you have the cvi full package. There is also an instrument driver (.fp) to access ini files in \toolslib\toolbox\ if that is your preferred method of saving configuration information.
If you are not using a close button on your panel, adding a callback function to your panel and catching the close or move events would give you a way to determine the panel coordinate prior to closing.
Message Edited by mvr on 11-05-2005 11:16 AM
11-14-2005 03:01 PM
OK, I've tried this Registry read / write without success. Searching the Registry, I cannot find the key I set up and I get a error with a negative number for both when called. Is there some kind of other call first to create a key entry? Why am I getting these errors?
PC
11-14-2005 05:06 PM
Which functions have you used for wirting to the registry? SDK or Programmer's Toolbox? If you don't find in the registry editor the keys you should have created the writing function is in error: try examining the return code for writing function to see if it's success or not and which type of error does it warns.
As a general rule, I usually put registry values for an application into HKLM\Software\MyFirm\Myprogram key. I never tried to organize the environment variables in a per-user basis (using the HKCU keys) so I cannot help you in this respect.
As usual, depending on the system you are using you may have privilege problems accessing the registry if your user is not an administrator.
11-15-2005 02:04 AM
Just as an examples, this is the code I use for reading / writing to the Registry with Toolbox functions:
char subKey[256]; // The key in the registry
strcpy (subKey, "Software\\MyFirm\\MyApp"); // The key in the registry
// Retrieving values from the registry:
error = RegQueryInfoOnKey (REGKEY_HKLM, subKey, NULL, &nv, NULL, NULL, NULL); // Retrievs number of values in the key
error = RegReadString (REGKEY_HKLM, subKey, "Name", msg, 512, &cnt); // Retrieves a string
errChk (RegReadULong (REGKEY_HKLM, subKey, "Value", &val, 0)); // Retrieves a value
// Storing values in the registry:
errChk (RegWriteString (REGKEY_HKLM, subKey, "Name", msg));
errChk (RegWriteULong (REGKEY_HKLM, subKey, "Value", val, 0));
A sample code for reading / writing using SDK functions can be found in menudemo.prj (<cvidir>\samples\toolbox directory), file menuutil.c, functions IniEx_ReadFromRegistry and IniEx_WriteToRegistry.
11-18-2005 03:33 PM
11-19-2005 05:17 PM
11-22-2005 01:58 PM
Part I
OK, for those who are interested, here's the final scoop (this crappy editor not withstanding): The following code snip shows how to collect the attribute values, massage them into acceptable form, and write to registry. The code after that shows how to retrieve it and apply it to the panel position. Sorry, comments removed because of 5000 char limit.
Save Position Code
int TopPos, LeftPos;
char PanelToClose;
char PanelNamePtr[10] = "MAINPANEL";
char *ErrMsg;
int LastPos[1];
PanelToClose = mpanelHandle;
// Save Left
GetPanelAttribute (PanelToClose, ATTR_LEFT, (void *)LastPos);
LeftPos = LastPos[0];
// Save top
GetPanelAttribute (PanelToClose, ATTR_TOP, (void *)LastPos);
TopPos = LastPos[0];
// Do it
SavePanelPos (PanelToClose, TopPos, LeftPos, PanelNamePtr);
Other code here...
Used to save position from any panel
void SavePanelPos (int PanelToClose, int TopPos, int LeftPos, char *PanelName)
{
char KeyStringFirst[13] = "SOFTWARE\\\\";
char KeyStringLastLeft[10] = "_LeftPos";
char KeyStringLastTop[10] = "_TopPos";
int *p;
int LastPos[1]; // Temporary, before storing it in registry
char PanelLeft[10];
char PanelTop[10];
char buff[50]; // Be sure to allocate enough
int Status;
char *ErrMsg;
// Save panel positions
// Save Left
sprintf(PanelLeft,"%d",LeftPos);
sprintf(buff,"%s%s%s", KeyStringFirst, PanelName, KeyStringLastLeft);
Status = RegWriteString (REGKEY_HKLM, buff, NULL, PanelLeft);
if (Status != 0)
{
ErrMsg = GetGeneralErrorString(Status);
sprintf(buff,"Error saving the %s panel's Left position: %s", PanelName, ErrMsg);
}
// Save top
sprintf(PanelTop,"%d",TopPos);
sprintf(buff,"%s%s%s", KeyStringFirst, PanelName, KeyStringLastTop);
Status = RegWriteString (REGKEY_HKLM, buff, NULL, PanelTop);
if (Status != 0)
{
ErrMsg = GetGeneralErrorString(Status);
sprintf(buff,"Error saving the %s panel's Top position: %s", PanelName, ErrMsg);
}
}