LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to open panel in previous position?

It gets pretty annoying to have all the panels pop up on top of each other time after time.  How do I save the location the user previously moved it to when it was closed?
0 Kudos
Message 1 of 12
(4,813 Views)
The only possibility to obtain this is to get panel position when it is open (ATTR_LEFT and ATTR_TOP) and save in the registry or an external file. Next, every time you open a panel read informations from there and use SetPanelPos to set the panel position before DisplayPanel or InstallPopup.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 12
(4,805 Views)

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?

0 Kudos
Message 3 of 12
(4,797 Views)

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

Message 4 of 12
(4,795 Views)

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

0 Kudos
Message 5 of 12
(4,725 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 6 of 12
(4,721 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 7 of 12
(4,710 Views)
It seems the problem is that the registry entries do not exist unless I create them manually.  Is there a function to create registry entries?
0 Kudos
Message 8 of 12
(4,675 Views)
Strange indeed: RegWriteXxx functions automatically provide creation of keys if they do not exist...


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 9 of 12
(4,675 Views)

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); 
 }
}

Message 10 of 12
(4,621 Views)