added some development tools
[windows-sources.git] / developer / VC / WTL80 / Samples / Wizard97Test / Wizard / TestWizard.cpp
blobf04f0ef24dd6bf9dc8156491f274787214284826
2 #include "stdafx.h"
3 #include "TestWizard.h"
4 #include "TestWizardSheet.h"
6 LPCTSTR g_lpcstrPrefRegKey = _T("Software\\Microsoft\\WTL Samples\\Wizard97Test");
8 CTestWizard::CTestWizard()
12 bool CTestWizard::ExecuteWizard()
14 // You could also pass in parameters here
15 // (or something generic like a name/value map).
17 bool success = false;
19 this->InitializeDefaultValues();
21 CTestWizardSheet wizard(&m_testWizardInfo);
22 INT_PTR result = wizard.DoModal();
23 if(result == IDOK)
25 // You could either do the work here, or in
26 // OnWizardFinish in the completion page class.
27 success = true;
29 this->StoreDefaultValues();
32 return success;
35 void CTestWizard::InitializeDefaultValues()
37 bool showWelcome = true;
38 CString defaultPath;
39 bool defaultRecurse = true;
40 CString defaultFilter;
41 TestWizardOutputType outputType = eOutput_Clipboard;
42 CString outputFileName;
43 TestWizardOutputFileEncoding outputFileEncoding = eEncoding_ASCII;
45 ATL::CRegKey regKey;
46 LONG result = regKey.Open(HKEY_CURRENT_USER, g_lpcstrPrefRegKey);
47 if(result == ERROR_SUCCESS)
49 this->GetBoolValue(regKey, _T("showWelcome"), showWelcome);
50 this->GetStringValue(regKey, _T("path"), defaultPath);
51 this->GetBoolValue(regKey, _T("recurse"), defaultRecurse);
52 this->GetStringValue(regKey, _T("filter"), defaultFilter);
54 CString outputTypeDisplayName;
55 if(this->GetStringValue(regKey, _T("outputType"), outputTypeDisplayName))
57 CTestWizardInfo::GetOutputTypeForDisplayName(outputTypeDisplayName, outputType);
59 // NOTE: We could have it so that "outputFileName" and "outputFileEncoding"
60 // were only looked for if the last output type were eOutput_SaveToFile.
61 // However, in case a previous run had done eOutput_SaveToFile, we'll
62 // load up what's there.
64 //if(outputType == eOutput_SaveToFile)
66 this->GetStringValue(regKey, _T("outputFileName"), outputFileName);
68 CString outputFileEncodingDisplayName;
69 if(this->GetStringValue(regKey, _T("outputFileEncoding"), outputFileEncodingDisplayName))
71 CTestWizardInfo::GetOutputFileEncodingForDisplayName(outputFileEncodingDisplayName, outputFileEncoding);
75 regKey.Close();
77 if(defaultPath.IsEmpty())
79 ::GetCurrentDirectory(MAX_PATH, defaultPath.GetBuffer(MAX_PATH+1));
80 defaultPath.ReleaseBuffer();
82 if(defaultFilter.IsEmpty())
84 defaultFilter = _T("*.*");
87 m_testWizardInfo.SetShowWelcome(showWelcome);
88 m_testWizardInfo.SetPath(defaultPath);
89 m_testWizardInfo.SetRecurse(defaultRecurse);
90 m_testWizardInfo.SetFilter(defaultFilter);
92 m_testWizardInfo.SetOutputType(outputType);
94 m_testWizardInfo.SetOutputFileName(outputFileName);
95 m_testWizardInfo.SetOutputFileEncoding(outputFileEncoding);
98 void CTestWizard::StoreDefaultValues()
100 bool showWelcome = m_testWizardInfo.GetShowWelcome();
101 CString path = m_testWizardInfo.GetPath();
102 bool recurse = m_testWizardInfo.GetRecurse();
103 CString filter = m_testWizardInfo.GetFilter();
104 TestWizardOutputType outputType = m_testWizardInfo.GetOutputType();
105 CString outputTypeDisplayName = m_testWizardInfo.GetOutputTypeDisplayName();
107 ATL::CRegKey regKey;
108 LONG result = regKey.Open(HKEY_CURRENT_USER, g_lpcstrPrefRegKey);
109 if(result != ERROR_SUCCESS)
111 result = regKey.Create(HKEY_CURRENT_USER, g_lpcstrPrefRegKey);
113 if(result == ERROR_SUCCESS)
115 this->SetBoolValue(regKey, _T("showWelcome"), showWelcome);
116 this->SetStringValue(regKey, _T("path"), path);
117 this->SetBoolValue(regKey, _T("recurse"), recurse);
118 this->SetStringValue(regKey, _T("filter"), filter);
120 // NOTE: For enumerations, we could either store the display name
121 // or the enumeration value. Which ever one you choose to store,
122 // for future versions you either need to ensure that value
123 // never changes, or you need to do a conversion. To do a conversion,
124 // one way is to store a "schema version" number so that readers
125 // know what you're written.
127 // We'll choose to store the display name so that the enumeration
128 // values can change (to change their order perhaps).
129 this->SetStringValue(regKey, _T("outputType"), outputTypeDisplayName);
130 if(outputType == eOutput_SaveToFile)
132 CString outputFileName = m_testWizardInfo.GetOutputFileName();
133 CString outputFileEncodingDisplayName = m_testWizardInfo.GetOutputFileEncodingDisplayName();
135 this->SetStringValue(regKey, _T("outputFileName"), outputFileName);
136 this->SetStringValue(regKey, _T("outputFileEncoding"), outputFileEncodingDisplayName);
138 else
140 // Since "outputFileName" and "outputFileEncoding" are used with
141 // eOutput_SaveToFile, we could technically delete them if a previous
142 // run had stored them. But we'll leave them in as defaults
143 // for future runs in case they switch back.
144 //regKey.DeleteValue(_T("outputFileName"));
145 //regKey.DeleteValue(_T("outputFileEncoding"));
148 regKey.Close();
151 bool CTestWizard::GetStringValue(ATL::CRegKey& regKey, LPCTSTR valueName, CString& value)
153 bool success = false;
155 #if (_ATL_VER >= 0x0700)
156 DWORD cchValue = 0;
157 LONG result = regKey.QueryStringValue(valueName, NULL, &cchValue);
158 if((result == ERROR_SUCCESS) && (cchValue > 0))
160 regKey.QueryStringValue(valueName, value.GetBuffer(cchValue+1), &cchValue);
161 value.ReleaseBuffer();
162 success = true;
164 #else
165 DWORD cbValue = 0;
166 LONG result = regKey.QueryValue(NULL, valueName, &cbValue);
167 if((result == ERROR_SUCCESS) && (cbValue > 0))
169 regKey.QueryValue(value.GetBuffer((cbValue+1/sizeof(TCHAR))+1), valueName, &cbValue);
170 value.ReleaseBuffer();
171 success = true;
173 #endif
175 return success;
178 bool CTestWizard::GetBoolValue(ATL::CRegKey& regKey, LPCTSTR valueName, bool& value)
180 bool success = false;
182 DWORD dwValue = 0;
183 #if (_ATL_VER >= 0x0700)
184 LONG result = regKey.QueryDWORDValue(valueName, dwValue);
185 #else
186 LONG result = regKey.QueryValue(dwValue, valueName);
187 #endif
188 if(result == ERROR_SUCCESS)
190 value = (dwValue != 0);
191 success = true;
194 return success;
197 bool CTestWizard::SetStringValue(ATL::CRegKey& regKey, LPCTSTR valueName, LPCTSTR value)
199 #if (_ATL_VER >= 0x0700)
200 return (ERROR_SUCCESS == regKey.SetStringValue(valueName, value, REG_SZ));
201 #else
202 return (ERROR_SUCCESS == regKey.SetValue(value, valueName));
203 #endif
206 bool CTestWizard::SetBoolValue(ATL::CRegKey& regKey, LPCTSTR valueName, bool value)
208 #if (_ATL_VER >= 0x0700)
209 return (ERROR_SUCCESS == regKey.SetDWORDValue(valueName, (value ? 1 : 0)));
210 #else
211 return (ERROR_SUCCESS == regKey.SetValue((value ? 1 : 0), valueName));
212 #endif