This is usually done using the application's "Profile" storage, which used to be in an .INI file, but is now in the registry, under the application's Software key.
In an MFC app's InitInstance()
, there is usually an auto-generated call to SetRegistryKey
. This takes an identifying string and sets up the app's profile storage. So, if your app is missing this, you need to add something like SetRegistryKey(_T("MyCompanyGroupOrAppName"));
.
Then there is an API for storing and retrieving information. For Edit control text, you probably want to save it with CWinApp::WriteProfileString
. So in your handler, you would get the text from the edit control into a CString
, then save it with
AfxGetApp()->WriteProfileString(_T("SectionName"), _T("MacAddress"), MyMacAddressString);
To get the string back later, use something like:
CString MyMacBeforeTheCrash = pApp->GetProfileString(_T("SectionName"), _T("MacAddress"));
Here are some links to the documentation:
It seems like you might not be sure how to access text from an edit control. There are several ways to do this, but it depends on how your dialog is set up.
If your edit control has a CString
variable associated with it, with DDX (Dialog Data Exchange), then you call your dialog class' member function: UpdatData(TRUE);
and after that, its CString
variable will contain the current text. To save a value, you assign the new text value to the variable, then call UpdateData(FALSE);
.
If you have access to a class variable for the edit control (a CEdit
object), you can copy the edit control's text to a CString
with MyEditControl.GetWindowText(MyString);
. To copy a string's text into an edit control, do: MyEditControl.SetWindowText(MyString);
.
If there isn't any kind of variable for your edit control, you might want to add one by going into your dialog's Resource Editor, right clicking on the edit control, then choosing "Add Variable" from the menu. You will get to choose whether you want to add a control object (a CEdit
), or something like a CString
.
You can also access an edit control's text using the non-MFC Win32 API -- this involves first somehow obtaining the control's window handle, then using ::SendMessage
to send WM_GETTEXT
and WM_SETTEXT
messages to the control.
Good luck.