Page 1 of 1

wxRegKey Problem on wxMSW

Posted: Thu Nov 18, 2004 2:11 am
by rsaccon
Hi all

I wanted in my wxMSW 2.5.2 based app to replace the ugly (but perfect working) win32 code with the elegant wxWidgets wrappings, but I can't make it work.

#ifdef __WIN32__
#include <wx/msw/registry.h>
#endif

wxRegKey RegkeyCurrentUser("HKCU\\Software\\Skype\\Phone\\SkypePath" );

wxString path;

if (RegkeyCurrentUser.Exists())
{
RegkeyCurrentUser.Open();
path = RegkeyCurrentUser;
wxLogMessage(path);
}


but this snippet does not work.
Anybody a clue how to query keys in the windows registries ?

regards
Roberto

Posted: Thu Nov 18, 2004 2:19 am
by cg
IIRC... (this is not tested, from just memory)

Code: Select all

if (RegkeyCurrentUser.Exists())
{
	RegkeyCurrentUser.Open();
	skypePath = RegkeyCurrentUser;
}
Should be more like:

Code: Select all

if (RegkeyCurrentUser.Exists())
{
	if( RegkeyCurrentUser.Open() )
	{
		RegkeyCurrentUser.QueryValue("keyname", stkypPath);	
	}
}
You can also can test if "keyname" exists before querying the value by:

Code: Select all

if (RegkeyCurrentUser.Exists())
{
	if( RegkeyCurrentUser.Open() )
	{
		if( RegkeyCurrentUser.HasValue("keyname") )
		{
			RegkeyCurrentUser.QueryValue("keyname", stkypPath);	
		}
	}
}
Hope that sheds some light.

CG

Posted: Thu Nov 18, 2004 3:04 am
by rsaccon
Now it seems to work. the folowing snippet checks whether Skype is installed and if it is, then skype gets started:

Code: Select all

bool res = false;
	wxString skypePath;
	wxString regPath(wxT("Software\\Skype\\Phone"));
    wxRegKey key(wxRegKey::HKCU, regPath);

    if (key.Exists()) 
	{
		res = key.QueryValue(wxT("SkypePath"), skypePath);
	}
	else
	{
		regPath = wxT("Software\\Skype\\Phone");
		wxRegKey key(wxRegKey::HKLM, regPath);

		if (key.Exists()) 
		{
			res = key.QueryValue(wxT("SkypePath"), skypePath);
		}
	}

	if (res) wxExecute(skypePath);

Posted: Thu Nov 18, 2004 3:08 am
by rsaccon
now I see that the next thing I have to learn is how to use the phpBB code utility (or whatever that is), to format snippets more readable on phpBB.

Posted: Thu Nov 18, 2004 3:55 am
by cg
highlight your block of code and click the Code button above the text box.

CG

Posted: Thu Nov 18, 2004 8:10 am
by upCASE
Hi!
Edited for readability :D