Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

782 lines
21 KiB

  1. // wiadbgcfgDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "wiadbgcfg.h"
  5. #include "wiadbgcfgDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. #define DEBUG_REGKEY_ROOT TEXT("System\\CurrentControlSet\\Control\\StillImage\\Debug")
  12. #define DWORD_REGVALUE_DEBUGFLAGS TEXT("DebugFlags")
  13. #define WIADBGCFG_DATAFILE TEXT("wiadbgcfg.txt")
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CAboutDlg dialog used for App About
  16. class CAboutDlg : public CDialog {
  17. public:
  18. CAboutDlg();
  19. // Dialog Data
  20. //{{AFX_DATA(CAboutDlg)
  21. enum {
  22. IDD = IDD_ABOUTBOX
  23. };
  24. //}}AFX_DATA
  25. // ClassWizard generated virtual function overrides
  26. //{{AFX_VIRTUAL(CAboutDlg)
  27. protected:
  28. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  29. //}}AFX_VIRTUAL
  30. // Implementation
  31. protected:
  32. //{{AFX_MSG(CAboutDlg)
  33. //}}AFX_MSG
  34. DECLARE_MESSAGE_MAP()
  35. };
  36. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  37. {
  38. //{{AFX_DATA_INIT(CAboutDlg)
  39. //}}AFX_DATA_INIT
  40. }
  41. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  42. {
  43. CDialog::DoDataExchange(pDX);
  44. //{{AFX_DATA_MAP(CAboutDlg)
  45. //}}AFX_DATA_MAP
  46. }
  47. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  48. //{{AFX_MSG_MAP(CAboutDlg)
  49. // No message handlers
  50. //}}AFX_MSG_MAP
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CWiadbgcfgDlg dialog
  54. CWiadbgcfgDlg::CWiadbgcfgDlg(CWnd* pParent /*=NULL*/)
  55. : CDialog(CWiadbgcfgDlg::IDD, pParent)
  56. {
  57. //{{AFX_DATA_INIT(CWiadbgcfgDlg)
  58. m_szDebugFlags = _T("");
  59. //}}AFX_DATA_INIT
  60. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  61. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  62. m_dwNumEntrysInDataBase = 0;
  63. m_pFlagDataBase = NULL;
  64. }
  65. void CWiadbgcfgDlg::DoDataExchange(CDataExchange* pDX)
  66. {
  67. CDialog::DoDataExchange(pDX);
  68. //{{AFX_DATA_MAP(CWiadbgcfgDlg)
  69. DDX_Control(pDX, IDC_FLAGS_LIST, m_DefinedDebugFlagsListBox);
  70. DDX_Control(pDX, IDC_MODULES_COMBOBOX, m_ModuleSelectionComboBox);
  71. DDX_Text(pDX, IDC_DEBUG_FLAGS_EDITBOX, m_szDebugFlags);
  72. //}}AFX_DATA_MAP
  73. }
  74. BEGIN_MESSAGE_MAP(CWiadbgcfgDlg, CDialog)
  75. //{{AFX_MSG_MAP(CWiadbgcfgDlg)
  76. ON_WM_SYSCOMMAND()
  77. ON_WM_PAINT()
  78. ON_WM_QUERYDRAGICON()
  79. ON_CBN_SELCHANGE(IDC_MODULES_COMBOBOX, OnSelchangeModulesCombobox)
  80. ON_WM_CLOSE()
  81. ON_EN_CHANGE(IDC_DEBUG_FLAGS_EDITBOX, OnChangeDebugFlagsEditbox)
  82. ON_LBN_SELCHANGE(IDC_FLAGS_LIST, OnSelchangeFlagsList)
  83. //}}AFX_MSG_MAP
  84. END_MESSAGE_MAP()
  85. /////////////////////////////////////////////////////////////////////////////
  86. // CWiadbgcfgDlg message handlers
  87. BOOL CWiadbgcfgDlg::OnInitDialog()
  88. {
  89. CDialog::OnInitDialog();
  90. // Add "About..." menu item to system menu.
  91. // IDM_ABOUTBOX must be in the system command range.
  92. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  93. ASSERT(IDM_ABOUTBOX < 0xF000);
  94. CMenu* pSysMenu = GetSystemMenu(FALSE);
  95. if (pSysMenu != NULL) {
  96. CString strAboutMenu;
  97. strAboutMenu.LoadString(IDS_ABOUTBOX);
  98. if (!strAboutMenu.IsEmpty()) {
  99. pSysMenu->AppendMenu(MF_SEPARATOR);
  100. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  101. }
  102. }
  103. // Set the icon for this dialog. The framework does this automatically
  104. // when the application's main window is not a dialog
  105. SetIcon(m_hIcon, TRUE); // Set big icon
  106. SetIcon(m_hIcon, FALSE); // Set small icon
  107. m_lDebugFlags = 0;
  108. BuildFlagDataBaseFromFile();
  109. return AddModulesToComboBox();
  110. }
  111. void CWiadbgcfgDlg::OnSysCommand(UINT nID, LPARAM lParam)
  112. {
  113. if ((nID & 0xFFF0) == IDM_ABOUTBOX) {
  114. CAboutDlg dlgAbout;
  115. dlgAbout.DoModal();
  116. } else {
  117. CDialog::OnSysCommand(nID, lParam);
  118. }
  119. }
  120. // If you add a minimize button to your dialog, you will need the code below
  121. // to draw the icon. For MFC applications using the document/view model,
  122. // this is automatically done for you by the framework.
  123. void CWiadbgcfgDlg::OnPaint()
  124. {
  125. if (IsIconic()) {
  126. CPaintDC dc(this); // device context for painting
  127. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  128. // Center icon in client rectangle
  129. int cxIcon = GetSystemMetrics(SM_CXICON);
  130. int cyIcon = GetSystemMetrics(SM_CYICON);
  131. CRect rect;
  132. GetClientRect(&rect);
  133. int x = (rect.Width() - cxIcon + 1) / 2;
  134. int y = (rect.Height() - cyIcon + 1) / 2;
  135. // Draw the icon
  136. dc.DrawIcon(x, y, m_hIcon);
  137. } else {
  138. CDialog::OnPaint();
  139. }
  140. }
  141. // The system calls this to obtain the cursor to display while the user drags
  142. // the minimized window.
  143. HCURSOR CWiadbgcfgDlg::OnQueryDragIcon()
  144. {
  145. return(HCURSOR) m_hIcon;
  146. }
  147. BOOL CWiadbgcfgDlg::AddModulesToComboBox()
  148. {
  149. BOOL bSuccess = FALSE;
  150. HKEY hTargetKey = NULL;
  151. DWORD dwNumKeys = 0;
  152. LONG lResult = ERROR_NO_MORE_ITEMS;
  153. TCHAR szKeyName[MAX_PATH];
  154. //
  155. // open root Debug registry key
  156. //
  157. if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE,DEBUG_REGKEY_ROOT,&hTargetKey)) {
  158. //
  159. // enumerate sub keys
  160. //
  161. memset(szKeyName,0,sizeof(szKeyName));
  162. lResult = RegEnumKey(hTargetKey,dwNumKeys,szKeyName,sizeof(szKeyName));
  163. //
  164. // while there are no more keys...
  165. //
  166. while (lResult != ERROR_NO_MORE_ITEMS) {
  167. memset(szKeyName,0,sizeof(szKeyName));
  168. lResult = RegEnumKey(hTargetKey,dwNumKeys,szKeyName,sizeof(szKeyName));
  169. //
  170. // if the key name is longer than 0 characters...
  171. // add it to the combobox.
  172. //
  173. if (lstrlen(szKeyName) > 0) {
  174. m_ModuleSelectionComboBox.AddString(szKeyName);
  175. }
  176. //
  177. // increment the key index/counter
  178. //
  179. dwNumKeys++;
  180. }
  181. //
  182. // check to see if we recieved any valid keys...
  183. //
  184. if (dwNumKeys > 0) {
  185. bSuccess = TRUE;
  186. }
  187. //
  188. // close root Debug registry key
  189. //
  190. if (NULL != hTargetKey) {
  191. RegCloseKey(hTargetKey);
  192. hTargetKey = NULL;
  193. }
  194. }
  195. //
  196. // if the enumertation was a success...
  197. // populate the other controls..
  198. //
  199. if (bSuccess) {
  200. m_ModuleSelectionComboBox.SetCurSel(0);
  201. UpdateCurrentValueFromRegistry();
  202. OnChangeDebugFlagsEditbox();
  203. }
  204. //
  205. // return success value
  206. //
  207. return bSuccess;
  208. }
  209. VOID CWiadbgcfgDlg::UpdateCurrentValueFromRegistry()
  210. {
  211. HKEY hDebugKey = NULL;
  212. TCHAR szDebugKey[MAX_PATH];
  213. if (ConstructDebugRegKey(szDebugKey,sizeof(szDebugKey))) {
  214. //
  215. // open registry key
  216. //
  217. if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE,szDebugKey,&hDebugKey)) {
  218. //
  219. // initialize DWORD reading values
  220. //
  221. DWORD dwSize = sizeof(DWORD);
  222. DWORD dwType = REG_DWORD;
  223. //
  224. // read current registry value
  225. //
  226. RegQueryValueEx(hDebugKey,DWORD_REGVALUE_DEBUGFLAGS,0,&dwType,(LPBYTE)&m_lDebugFlags,&dwSize);
  227. //
  228. // update UI
  229. //
  230. UpdateEditBox();
  231. //
  232. // close registry key
  233. //
  234. RegCloseKey(hDebugKey);
  235. //
  236. // add flags for that module to list box
  237. //
  238. TCHAR szModuleName[MAX_PATH];
  239. memset(szModuleName,0,sizeof(szModuleName));
  240. GetSelectedModuleName(szModuleName,sizeof(szModuleName));
  241. AddFlagsToListBox(szModuleName);
  242. }
  243. }
  244. }
  245. VOID CWiadbgcfgDlg::UpdateCurrentValueToRegistry()
  246. {
  247. HKEY hDebugKey = NULL;
  248. TCHAR szDebugKey[MAX_PATH];
  249. if (ConstructDebugRegKey(szDebugKey,sizeof(szDebugKey))) {
  250. //
  251. // open registry key
  252. //
  253. if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE,szDebugKey,&hDebugKey)) {
  254. //
  255. // initialize DWORD reading values
  256. //
  257. DWORD dwSize = sizeof(DWORD);
  258. DWORD dwType = REG_DWORD;
  259. //
  260. // write current registry value
  261. //
  262. RegSetValueEx(hDebugKey,DWORD_REGVALUE_DEBUGFLAGS,0,dwType,(LPBYTE)&m_lDebugFlags,dwSize);
  263. //
  264. // close registry key
  265. //
  266. RegCloseKey(hDebugKey);
  267. }
  268. }
  269. }
  270. void CWiadbgcfgDlg::UpdateEditBox()
  271. {
  272. //
  273. // format display string, from saved current value
  274. //
  275. m_szDebugFlags.Format(TEXT("0x%08X"),m_lDebugFlags);
  276. //
  277. // update dialog control, with formatted current value
  278. //
  279. UpdateData(FALSE);
  280. UpdateListBoxSelectionFromEditBox();
  281. }
  282. BOOL CWiadbgcfgDlg::GetSelectedModuleName(TCHAR *szModuleName, DWORD dwSize)
  283. {
  284. memset(szModuleName,0,dwSize);
  285. //
  286. // get current selection index from combo box
  287. //
  288. INT iCurSel = m_ModuleSelectionComboBox.GetCurSel();
  289. //
  290. // check that we have a selection
  291. //
  292. if (iCurSel > -1) {
  293. //
  294. // get module name from combo box
  295. //
  296. m_ModuleSelectionComboBox.GetLBText(iCurSel, szModuleName);
  297. return TRUE;
  298. }
  299. return FALSE;
  300. }
  301. BOOL CWiadbgcfgDlg::ConstructDebugRegKey(TCHAR *pszDebugRegKey, DWORD dwSize)
  302. {
  303. memset(pszDebugRegKey,0,dwSize);
  304. //
  305. // copy root registry string, adding on "\"
  306. //
  307. lstrcpy(pszDebugRegKey,DEBUG_REGKEY_ROOT);
  308. lstrcat(pszDebugRegKey,TEXT("\\"));
  309. TCHAR szRegKey[MAX_PATH];
  310. if (GetSelectedModuleName(szRegKey,sizeof(szRegKey))) {
  311. //
  312. // concat module name to end of root registry key, to
  313. // form new debug key to open
  314. //
  315. lstrcat(pszDebugRegKey,szRegKey);
  316. return TRUE;
  317. }
  318. return FALSE;
  319. }
  320. void CWiadbgcfgDlg::OnSelchangeModulesCombobox()
  321. {
  322. //
  323. // update the dialog, when the user changes the selected module
  324. //
  325. UpdateCurrentValueFromRegistry();
  326. OnChangeDebugFlagsEditbox();
  327. }
  328. BOOL CWiadbgcfgDlg::BuildFlagDataBaseFromFile()
  329. {
  330. CFileIO DATA_FILE;
  331. HRESULT hr = S_OK;
  332. hr = DATA_FILE.Open(WIADBGCFG_DATAFILE);
  333. if (FAILED(hr)) {
  334. //
  335. // display warning to user..and attempt to generate the default data file
  336. // with wia service entries
  337. //
  338. TCHAR szWarningString[MAX_PATH];
  339. memset(szWarningString,0,sizeof(szWarningString));
  340. lstrcpy(szWarningString,WIADBGCFG_DATAFILE);
  341. lstrcat(szWarningString, TEXT(" could not be found..This Program will generate one for you.\nYou can add custom flags by editing this file."));
  342. MessageBox(szWarningString,TEXT("Configuration File Warning"),MB_ICONWARNING);
  343. CreateDefaultDataFile();
  344. //
  345. // attempt to reopen data file
  346. //
  347. hr = DATA_FILE.Open(WIADBGCFG_DATAFILE);
  348. }
  349. if (SUCCEEDED(hr)) {
  350. //
  351. // data file is open... count valid entries
  352. //
  353. TCHAR szString[MAX_PATH];
  354. memset(szString,0,sizeof(szString));
  355. LONG lNumCharactersRead = 0;
  356. while (DATA_FILE.ReadLine(szString,sizeof(szString),&lNumCharactersRead)) {
  357. if ((szString[0] == '/') && (szString[1] == '/')) {
  358. //
  359. // skip the comment lines
  360. //
  361. } else if ((szString[0] == 13)) {
  362. //
  363. // skip the empty carriage returns..and line feeds
  364. //
  365. } else {
  366. DWORD dwError = ValidateEntry(szString);
  367. m_dwNumEntrysInDataBase++;
  368. }
  369. }
  370. DATA_FILE.Close();
  371. } else {
  372. MessageBox(TEXT("flags data file could not be opened.."),TEXT("Configuration File Error"),MB_ICONERROR);
  373. return FALSE;
  374. }
  375. //
  376. // allocate flag data base
  377. //
  378. LONG lEntryNumber = 0;
  379. m_pFlagDataBase = new PREDEFINED_FLAGS[m_dwNumEntrysInDataBase];
  380. if (m_pFlagDataBase) {
  381. hr = DATA_FILE.Open(WIADBGCFG_DATAFILE);
  382. } else {
  383. hr = E_OUTOFMEMORY;
  384. }
  385. if (SUCCEEDED(hr)) {
  386. TCHAR szString[MAX_PATH];
  387. memset(szString,0,sizeof(szString));
  388. LONG lNumCharactersRead = 0;
  389. while (DATA_FILE.ReadLine(szString,sizeof(szString),&lNumCharactersRead)) {
  390. if ((szString[0] == '/') && (szString[1] == '/')) {
  391. //
  392. // skip the comment lines
  393. //
  394. } else if ((szString[0] == 13)) {
  395. //
  396. // skip the empty carriage returns..and line feeds
  397. //
  398. } else {
  399. DWORD dwError = ValidateEntry(szString);
  400. ParseEntry(szString,&m_pFlagDataBase[lEntryNumber]);
  401. lEntryNumber++;
  402. }
  403. }
  404. DATA_FILE.Close();
  405. } else {
  406. MessageBox(TEXT("flags data file could not be opened.."),TEXT("Configuration File Error"),MB_ICONERROR);
  407. return FALSE;
  408. }
  409. return TRUE;
  410. }
  411. void CWiadbgcfgDlg::OnClose()
  412. {
  413. CDialog::OnClose();
  414. }
  415. VOID CWiadbgcfgDlg::AddFlagsToListBox(TCHAR *szModuleName)
  416. {
  417. m_DefinedDebugFlagsListBox.ResetContent();
  418. for (DWORD dwindex = 0; dwindex < m_dwNumEntrysInDataBase; dwindex++) {
  419. if ((lstrcmpi(TEXT("global"),m_pFlagDataBase[dwindex].szModule) == 0) || (lstrcmpi(szModuleName, m_pFlagDataBase[dwindex].szModule) == 0)) {
  420. TCHAR szListBoxString[MAX_PATH];
  421. memset(szListBoxString,0,sizeof(szListBoxString));
  422. lstrcpy(szListBoxString,m_pFlagDataBase[dwindex].szName);
  423. m_DefinedDebugFlagsListBox.AddString(szListBoxString);
  424. }
  425. }
  426. }
  427. VOID CWiadbgcfgDlg::FreeDataBaseMemory()
  428. {
  429. if (m_pFlagDataBase) {
  430. delete [] m_pFlagDataBase;
  431. m_pFlagDataBase = NULL;
  432. }
  433. }
  434. DWORD CWiadbgcfgDlg::ValidateEntry(TCHAR *szEntry)
  435. {
  436. DWORD dwError = VALID_ENTRY;
  437. // VALID_ENTRY
  438. // MISSING_QUOTE
  439. // MISSING_FIELD
  440. // INVALID_FLAG
  441. // INVALID_NAME
  442. // INVALID_DESCRIPTION
  443. return dwError;
  444. }
  445. VOID CWiadbgcfgDlg::CreateDefaultDataFile()
  446. {
  447. CFileIO DATA_FILE;
  448. /*
  449. const DWORD WIAUDBG_ERRORS = 0x00000001;
  450. const DWORD WIAUDBG_WARNINGS = 0x00000002;
  451. const DWORD WIAUDBG_TRACES = 0x00000004;
  452. const DWORD WIAUDBG_FNS = 0x00000008; // Function entry and exit
  453. const DWORD WIAUDBG_DUMP = 0x00000010; // Dump data
  454. const DWORD WIAUDBG_PRINT_TIME = 0x08000000; // Prints time for each message
  455. const DWORD WIAUDBG_PRINT_INFO = 0x10000000; // Turns on thread, file, line info
  456. const DWORD WIAUDBG_DONT_LOG_TO_DEBUGGER = 0x20000000;
  457. const DWORD WIAUDBG_DONT_LOG_TO_FILE = 0x40000000;
  458. const DWORD WIAUDBG_BREAK_ON_ERRORS = 0x80000000; // Do DebugBreak on errors
  459. */
  460. if (SUCCEEDED(DATA_FILE.Open(WIADBGCFG_DATAFILE,TRUE))) {
  461. DATA_FILE.WriteLine(TEXT("//"));
  462. DATA_FILE.WriteLine(TEXT("// Module Name Flag Description Flag Value"));
  463. DATA_FILE.WriteLine(TEXT("//"));
  464. DATA_FILE.WriteLine(TEXT(""));
  465. DATA_FILE.WriteLine(TEXT("\"global\", \"Log Errors\", \"0x00000001\""));
  466. DATA_FILE.WriteLine(TEXT("\"global\", \"Log Warnings\", \"0x00000002\""));
  467. DATA_FILE.WriteLine(TEXT("\"global\", \"Log Traces\", \"0x00000004\""));
  468. DATA_FILE.WriteLine(TEXT("\"global\", \"Log Function Entry/Exits\", \"0x00000008\""));
  469. DATA_FILE.WriteLine(TEXT("\"global\", \"Don't Log to Debugger\", \"0x20000000\""));
  470. DATA_FILE.WriteLine(TEXT("\"global\", \"Don't Log To File\", \"0x40000000\""));
  471. DATA_FILE.WriteLine(TEXT("\"global\", \"Break on Errors\", \"0x80000000\""));
  472. DATA_FILE.WriteLine(TEXT(""));
  473. DATA_FILE.WriteLine(TEXT(""));
  474. DATA_FILE.WriteLine(TEXT(""));
  475. DATA_FILE.WriteLine(TEXT("//"));
  476. DATA_FILE.WriteLine(TEXT("// Add your custom flags here, follow same format as above."));
  477. DATA_FILE.WriteLine(TEXT("//"));
  478. DATA_FILE.WriteLine(TEXT("\"module.dll\", \"Text String Description\", \" flag value\""));
  479. DATA_FILE.Close();
  480. } else {
  481. MessageBox(TEXT("Default data file could not be created."),TEXT("Configuration File Error"),MB_ICONERROR);
  482. }
  483. }
  484. VOID CWiadbgcfgDlg::ParseEntry(TCHAR *pszString, PPREDEFINED_FLAGS pFlagInfo)
  485. {
  486. TCHAR *pch = pszString;
  487. LONG lLen = lstrlen(pszString);
  488. BOOL bModuleName = FALSE;
  489. BOOL bFlagName = FALSE;
  490. BOOL bFlagValue = FALSE;
  491. BOOL bFirstQuote = FALSE;
  492. BOOL bLastQuote = FALSE;
  493. LONG lCopyIndex = 0;
  494. TCHAR szFlagValue[MAX_PATH];
  495. memset(szFlagValue,0,sizeof(szFlagValue));
  496. memset(pFlagInfo,0,sizeof(PREDEFINED_FLAGS));
  497. for (LONG i = 0; i < lLen; i++) {
  498. if (!bModuleName) {
  499. //
  500. // strip off module name
  501. //
  502. if (!bFirstQuote) {
  503. if (pch[i] == '"') {
  504. bFirstQuote = TRUE;
  505. lCopyIndex = 0;
  506. }
  507. } else {
  508. if (pch[i] != '"') {
  509. pFlagInfo->szModule[lCopyIndex] = pch[i];
  510. lCopyIndex++;
  511. } else {
  512. bModuleName = TRUE;
  513. bFirstQuote = FALSE;
  514. }
  515. }
  516. } else if (!bFlagName) {
  517. //
  518. // strip off flag name
  519. //
  520. if (!bFirstQuote) {
  521. if (pch[i] == '"') {
  522. bFirstQuote = TRUE;
  523. lCopyIndex = 0;
  524. }
  525. } else {
  526. if (pch[i] != '"') {
  527. pFlagInfo->szName[lCopyIndex] = pch[i];
  528. lCopyIndex++;
  529. } else {
  530. bFlagName = TRUE;
  531. bFirstQuote = FALSE;
  532. }
  533. }
  534. } else if (!bFlagValue) {
  535. //
  536. // strip off flag value
  537. //
  538. if (!bFirstQuote) {
  539. if (pch[i] == '"') {
  540. bFirstQuote = TRUE;
  541. lCopyIndex = 0;
  542. }
  543. } else {
  544. if (pch[i] != '"') {
  545. szFlagValue[lCopyIndex] = pch[i];
  546. lCopyIndex++;
  547. } else {
  548. bFlagValue = TRUE;
  549. bFirstQuote = FALSE;
  550. #ifdef UNICODE
  551. swscanf(szFlagValue,TEXT("0x%08X"),&pFlagInfo->dwFlagValue);
  552. #else
  553. sscanf(szFlagValue,TEXT("0x%08X"),&pFlagInfo->dwFlagValue);
  554. #endif
  555. }
  556. }
  557. }
  558. }
  559. }
  560. void CWiadbgcfgDlg::OnChangeDebugFlagsEditbox()
  561. {
  562. UpdateData(TRUE);
  563. #ifdef UNICODE
  564. swscanf(m_szDebugFlags,TEXT("0x%08X"),&m_lDebugFlags);
  565. #else
  566. sscanf(m_szDebugFlags,TEXT("0x%08X"),&m_lDebugFlags);
  567. #endif
  568. INT iNumItems = 0;
  569. iNumItems = m_DefinedDebugFlagsListBox.GetCount();
  570. for(INT i = 0; i < iNumItems; i++){
  571. m_DefinedDebugFlagsListBox.SetSel(i,FALSE);
  572. }
  573. UpdateListBoxSelectionFromEditBox();
  574. UpdateCurrentValueToRegistry();
  575. }
  576. BOOL CWiadbgcfgDlg::GetDebugFlagFromDataBase(TCHAR *szModuleName, TCHAR *szFlagName, LONG *pFlagValue)
  577. {
  578. BOOL bFound = FALSE;
  579. for (DWORD dwindex = 0; dwindex < m_dwNumEntrysInDataBase; dwindex++) {
  580. if ((lstrcmpi(TEXT("global"),m_pFlagDataBase[dwindex].szModule) == 0) || lstrcmpi(szModuleName, m_pFlagDataBase[dwindex].szModule) == 0) {
  581. TCHAR szListBoxString[MAX_PATH];
  582. memset(szListBoxString,0,sizeof(szListBoxString));
  583. if (lstrcmpi(szFlagName, m_pFlagDataBase[dwindex].szName) == 0) {
  584. *pFlagValue = m_pFlagDataBase[dwindex].dwFlagValue;
  585. bFound = TRUE;
  586. dwindex = m_dwNumEntrysInDataBase;
  587. }
  588. }
  589. }
  590. return bFound;
  591. }
  592. void CWiadbgcfgDlg::OnSelchangeFlagsList()
  593. {
  594. TCHAR szModuleName[MAX_PATH];
  595. if(GetSelectedModuleName(szModuleName,sizeof(szModuleName))){
  596. TCHAR szListBoxValue[MAX_PATH];
  597. m_lDebugFlags = 0;
  598. LONG lListBoxValue = 0;
  599. int indexArray[100];
  600. memset(indexArray,0,sizeof(indexArray));
  601. int iNumItemsSelected = m_DefinedDebugFlagsListBox.GetSelItems(100,indexArray);
  602. for (int i = 0; i < iNumItemsSelected; i++) {
  603. memset(szListBoxValue,0,sizeof(szListBoxValue));
  604. m_DefinedDebugFlagsListBox.GetText(indexArray[i],szListBoxValue);
  605. if (GetDebugFlagFromDataBase(szModuleName,szListBoxValue,&lListBoxValue)) {
  606. m_lDebugFlags |= lListBoxValue;
  607. } else {
  608. }
  609. }
  610. m_szDebugFlags.Format(TEXT("0x%08X"),m_lDebugFlags);
  611. //
  612. // update dialog control, with formatted current value
  613. //
  614. UpdateData(FALSE);
  615. UpdateCurrentValueToRegistry();
  616. }
  617. }
  618. void CWiadbgcfgDlg::UpdateListBoxSelectionFromEditBox()
  619. {
  620. INT iNumItems = 0;
  621. iNumItems = m_DefinedDebugFlagsListBox.GetCount();
  622. if(iNumItems > 0){
  623. TCHAR szModuleName[MAX_PATH];
  624. GetSelectedModuleName(szModuleName,sizeof(szModuleName));
  625. for(INT i = 0; i < iNumItems; i++){
  626. TCHAR szListBoxString[MAX_PATH];
  627. memset(szListBoxString,0,sizeof(szListBoxString));
  628. m_DefinedDebugFlagsListBox.GetText(i,szListBoxString);
  629. LONG lFlagValue = 0;
  630. if(GetDebugFlagFromDataBase(szModuleName,szListBoxString,&lFlagValue)){
  631. if(m_lDebugFlags & lFlagValue){
  632. m_DefinedDebugFlagsListBox.SetSel(i);
  633. }
  634. }
  635. }
  636. }
  637. }