wxRegKey Problem on wxMSW

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
rsaccon
Earned a small fee
Earned a small fee
Posts: 10
Joined: Tue Aug 31, 2004 12:57 am

wxRegKey Problem on wxMSW

Post 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
cg
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 201
Joined: Sun Aug 29, 2004 12:33 am
Location: Canada
Contact:

Post 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
rsaccon
Earned a small fee
Earned a small fee
Posts: 10
Joined: Tue Aug 31, 2004 12:57 am

Post 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);
rsaccon
Earned a small fee
Earned a small fee
Posts: 10
Joined: Tue Aug 31, 2004 12:57 am

Post 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.
cg
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 201
Joined: Sun Aug 29, 2004 12:33 am
Location: Canada
Contact:

Post by cg »

highlight your block of code and click the Code button above the text box.

CG
upCASE
Moderator
Moderator
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE »

Hi!
Edited for readability :D
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda
Post Reply