Author: wyoung
Date: Wed Apr 11 23:21:52 2007
New Revision: 1499
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1499&view=rev
Log:
Improved loading of default values from registry in new MFC example.
Made it work more like Windows Forms version, for easy comparison.
Modified:
trunk/examples/vstudio/mfc/mfc_dlg.cpp
trunk/examples/vstudio/mfc/mfc_dlg.h
Modified: trunk/examples/vstudio/mfc/mfc_dlg.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/vstudio/mfc/mfc_dlg.cpp?rev=1499&r1=1498&r2=1499&view=diff
==============================================================================
--- trunk/examples/vstudio/mfc/mfc_dlg.cpp (original)
+++ trunk/examples/vstudio/mfc/mfc_dlg.cpp Wed Apr 11 23:21:52 2007
@@ -39,28 +39,7 @@
CExampleDlg::CExampleDlg(CWnd* pParent) :
CDialog(IDD_MFC_DIALOG, pParent)
{
- // Load default input values from registry, if we can
- HKEY key = OpenSettingsRegistryKey();
- if (key) {
- // There are pre-existing defaults we can use, so copy them in
- TCHAR acSetting[100];
- LoadSetting(key, _T("user"), acSetting, sizeof(acSetting));
- sUserName = acSetting;
- LoadSetting(key, _T("server"), acSetting, sizeof(acSetting));
- sServerAddress = acSetting;
- RegCloseKey(key);
- }
- if ((sUserName.GetLength() == 0) ||
- (sServerAddress.GetLength() == 0)) {
- // Didn't find anything we can use, so have to make something
- // plausible up instead.
- sServerAddress = _T("localhost");
- TCHAR acUserName[100];
- DWORD nBufferSize = sizeof(acUserName);
- if (GetUserName(acUserName, &nBufferSize)) {
- sUserName = acUserName;
- }
- }
+ LoadDefaults();
}
@@ -78,13 +57,45 @@
//// DoDataExchange ////////////////////////////////////////////////////
// Transfer data from the controls into our member variables
-void CExampleDlg::DoDataExchange(CDataExchange* pDX)
+void
+CExampleDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_SERVER_EDIT, sServerAddress);
DDX_Text(pDX, IDC_USER_EDIT, sUserName);
DDX_Text(pDX, IDC_PASSWORD_EDIT, sPassword);
DDX_Control(pDX, IDC_RESULTS_LIST, ResultsList);
+}
+
+
+//// LoadDefaults //////////////////////////////////////////////////////
+// Load default input values from registry, if they exist.
+
+void
+CExampleDlg::LoadDefaults()
+{
+ HKEY key = OpenSettingsRegistryKey();
+ if (key) {
+ TCHAR acSetting[100];
+ if (LoadSetting(key, _T("user"), acSetting, sizeof(acSetting)))
{
+ sUserName = acSetting;
+ }
+ if (LoadSetting(key, _T("server"), acSetting,
sizeof(acSetting))) {
+ sServerAddress = acSetting;
+ }
+ RegCloseKey(key);
+ }
+
+ if (sUserName.IsEmpty()) {
+ TCHAR acUserName[100];
+ DWORD nBufferSize = sizeof(acUserName);
+ if (GetUserName(acUserName, &nBufferSize)) {
+ sUserName = acUserName;
+ }
+ }
+ if (sServerAddress.IsEmpty()) {
+ sServerAddress = _T("localhost");
+ }
}
Modified: trunk/examples/vstudio/mfc/mfc_dlg.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/examples/vstudio/mfc/mfc_dlg.h?rev=1499&r1=1498&r2=1499&view=diff
==============================================================================
--- trunk/examples/vstudio/mfc/mfc_dlg.h (original)
+++ trunk/examples/vstudio/mfc/mfc_dlg.h Wed Apr 11 23:21:52 2007
@@ -43,13 +43,14 @@
//// Internal support functions
void AddMessage(LPCTSTR pcMessage);
void DoDataExchange(CDataExchange* pDX);
- bool LoadSetting(HKEY key, LPCTSTR pcName, LPTSTR pcValue,
- DWORD nValueSize);
- HKEY OpenSettingsRegistryKey();
- bool SaveInputs(LPCTSTR pcServerAddress, LPCTSTR pcUserName);
- bool SaveSetting(HKEY key, LPCTSTR pcName, LPCTSTR pcValue);
- bool ToUCS2(LPTSTR pcOut, int nOutLen, const char* kpcIn);
- bool ToUTF8(char* pcOut, int nOutLen, LPCWSTR kpcIn);
+ void LoadDefaults();
+ bool LoadSetting(HKEY key, LPCTSTR pcName, LPTSTR pcValue,
+ DWORD nValueSize);
+ HKEY OpenSettingsRegistryKey();
+ bool SaveInputs(LPCTSTR pcServerAddress, LPCTSTR pcUserName);
+ bool SaveSetting(HKEY key, LPCTSTR pcName, LPCTSTR pcValue);
+ bool ToUCS2(LPTSTR pcOut, int nOutLen, const char* kpcIn);
+ bool ToUTF8(char* pcOut, int nOutLen, LPCWSTR kpcIn);
//// Message map
afx_msg void OnBnClickedConnectButton();
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits