|
-
September 27th, 2006, 05:29 AM
#1
Save data for next session
Hi, i just switched from VC6 to .NET 2 (2005 edition). Besides a lot of other things i have problems to get used to the all new techniques. I want to store a value in a dialog for the next session with my app.
Befor i used WriteProfileInt from the Windows SDK i.e. and in the OnInitDialog i loaded the value with GetProfileInt from the SDK.
What do i have to do in .NET?
I read something about configuration .config XML files etc. but did not find a easy way to store the data when exiting the app.
Please help
Last edited by gintonic42; September 27th, 2006 at 05:32 AM.
-
September 27th, 2006, 04:27 PM
#2
Re: Save data for next session
As a first simple solution you could use Microsoft::Win32::Registry and Microsoft::Win32::RegistryKey :
http://msdn2.microsoft.com/en-us/lib...y_members.aspx
http://msdn2.microsoft.com/en-us/lib...y_members.aspx
It might be an idea to create your own settings class, where each setting is represented externally as a property. Internally it could use the registry but later on could be changed to use XML config files instead.
Last edited by Zaccheus; September 27th, 2006 at 04:33 PM.
-
September 28th, 2006, 01:31 AM
#3
Re: Save data for next session
Hy Zaccheus,
is there an easy example to approach my own settings class?
-
September 28th, 2006, 01:32 PM
#4
Re: Save data for next session
Here's a simplified version of what I use:
Code:
// .h
public ref class ApplicationConfiguration
{
public:
static System::String^ ReadString
(
System::String^ inKeyName,
System::String^ inValueName,
System::String^ inDefault
);
static void WriteString
(
System::String^ inKeyName,
System::String^ inValueName,
System::String^ inValue
);
private:
/////////////////////////////////////////////////////////////////
// Choose your own company name and application name.
/////////////////////////////////////////////////////////////////
static System::String^ baseName = L"HKEY_CURRENT_USER\\Software\\MYCOMPANYNAME\\MYAPPNAME\\";
};
// .cpp
System::String^ ApplicationConfiguration::ReadString
(
System::String^ inKeyName,
System::String^ inValueName,
System::String^ inDefault
)
{
System::Object^ result = Microsoft::Win32::Registry::GetValue(baseName + inKeyName, inValueName, inDefault);
return dynamic_cast<System::String^>(result);
}
void ApplicationConfiguration::WriteString
(
System::String^ inKeyName,
System::String^ inValueName,
System::String^ inValue
)
{
Microsoft::Win32::Registry::SetValue(baseName + inKeyName, inValueName, inValue, Microsoft::Win32::RegistryValueKind::String);
}
Obviously you would replace MYCOMPANYNAME and MYAPPNAME with something meaningful.
-
September 29th, 2006, 01:38 AM
#5
Re: Save data for next session
Thanks for that, but this is not exactly, what i am looking for. I dont want a workaround for that, i would like to use the "normal" mechanism.
I have found out something new.
In VS opening a dialog in design mode, an edit box has a property called ApplicationSettings->PropertyBinding, where you can setup application settings. This seems to be the mechanism, that uses these .config xml files for the properties. But this does not work on my system. If i try to add a new setting, i get an error message:
In my german system:
"Im Projekt wurden keine Einstellungsdateien gefunden. Fügen Sie eine Einstellungdatei hinzu, und wiederholen Sie den Vorgang." which says:
There is no settings file in the project. Add one and try again.
In the help it is said, to use the Project-Designer for that, but i have no project designer and the method in the helpfile seems to talk of a different compiler. My VS has no project designer.
Does anybody know this problem?
-
September 29th, 2006, 07:16 AM
#6
Re: Save data for next session
Ok, I thought you just want a simple replacement for INI files.

I have not yet investigated the technique you are talking about, but it sounds like I should.
-
September 29th, 2006, 06:19 PM
#7
Re: Save data for next session
Throw on form TextBox, click on it further in a window of properties open ApplicationSettings, and for property Text set create new adjustment. Thus property Text will be connected with My. Settings.
Not having written a uniform line of a code, the data from this text field will be stored in adjustments.
Probably something is done not so?
-
October 17th, 2006, 09:05 AM
#8
Re: Save data for next session
Hy, i was a little on holiday.
If i try to do so, i get an error message like described above. I do not have a design manager. What is that? There is nothing with that name in my environment. I am using VS 2005 with VC++ 2005. Are you talking about the same version?
Your technique seems to be, what i am searching for, but it does not work on my computer.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|