Leaked source code of windows server 2003
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.

507 lines
14 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft OLE
  4. // Copyright (C) Microsoft Corporation, 1994 - 1995.
  5. //
  6. // File: cdbgdlg.cxx
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 4-10-95 kennethm Created
  15. //
  16. //--------------------------------------------------------------------------
  17. #include <dfheader.hxx>
  18. #pragma hdrstop
  19. #include <debdlg.h>
  20. // BUGBUG:KILL this ARRAYSIZE DEF when its becomes globally available.
  21. #ifndef ARRAYSIZE
  22. #define ARRAYSIZE(a) (sizeof (a)/sizeof (a[0]))
  23. #endif
  24. //+-------------------------------------------------------------------------
  25. //
  26. // Function: UpdateTraceLevels
  27. //
  28. // Synopsis:
  29. //
  30. // Arguments: [hwndDlg] --
  31. // [fTraceLvl] --
  32. //
  33. // Returns:
  34. //
  35. // History: 4-29-95 kennethm Created
  36. //
  37. // Notes:
  38. //
  39. //--------------------------------------------------------------------------
  40. void CDebugHelp::UpdateTraceLevels(HWND hwndDlg, DWORD fTraceLvl)
  41. {
  42. TCHAR szTraceLvl[MAX_PATH];
  43. //
  44. // Trace Level flags
  45. //
  46. CheckDlgButton(hwndDlg, IDC_ADDREL, (fTraceLvl & DH_LVL_ADDREL) ? 1 : 0);
  47. CheckDlgButton(hwndDlg, IDC_QI, (fTraceLvl & DH_LVL_QI) ? 1 : 0);
  48. CheckDlgButton(hwndDlg, IDC_INTERF, (fTraceLvl & DH_LVL_INTERF) ? 1 : 0);
  49. CheckDlgButton(hwndDlg, IDC_LEVEL1, (fTraceLvl & DH_LVL_TRACE1) ? 1 : 0);
  50. CheckDlgButton(hwndDlg, IDC_LEVEL2, (fTraceLvl & DH_LVL_TRACE2) ? 1 : 0);
  51. CheckDlgButton(hwndDlg, IDC_LEVEL3, (fTraceLvl & DH_LVL_TRACE3) ? 1 : 0);
  52. CheckDlgButton(hwndDlg, IDC_LEVEL4, (fTraceLvl & DH_LVL_TRACE4) ? 1 : 0);
  53. CheckDlgButton(hwndDlg, IDC_FUNCIN, (fTraceLvl & DH_LVL_ENTRY) ? 1 : 0);
  54. CheckDlgButton(hwndDlg, IDC_FUNCOUT,(fTraceLvl & DH_LVL_EXIT) ? 1 : 0);
  55. //
  56. // Set trace level text
  57. //
  58. wsprintf(szTraceLvl, TEXT("%#08lx"), fTraceLvl);
  59. SetDlgItemText(hwndDlg, IDC_TRACELEVEL, szTraceLvl);
  60. }
  61. //+-------------------------------------------------------------------------
  62. //
  63. // Function: UpdateLogLocations
  64. //
  65. // Synopsis:
  66. //
  67. // Arguments: [hwndDlg] --
  68. // [fLogLoc] --
  69. //
  70. // Returns:
  71. //
  72. // History: 4-29-95 kennethm Created
  73. //
  74. // Notes:
  75. //
  76. //--------------------------------------------------------------------------
  77. void CDebugHelp::UpdateLogLocations(HWND hwndDlg, DWORD fLogLoc)
  78. {
  79. CheckDlgButton(hwndDlg, IDC_LLDEBUGTERM, (fLogLoc & DH_LOC_TERM) ? 1 : 0);
  80. CheckDlgButton(hwndDlg, IDC_LLLOGFILE, (fLogLoc & DH_LOC_LOG) ? 1 : 0);
  81. CheckDlgButton(hwndDlg, IDC_LLCONSOLE, (fLogLoc & DH_LOC_STDOUT) ? 1 : 0);
  82. CheckDlgButton(hwndDlg, IDC_LLSPYWIN, (fLogLoc & DH_LOC_SPYWIN) ? 1 : 0);
  83. }
  84. //+-------------------------------------------------------------------------
  85. //
  86. // Function: UpdateTraceLocations
  87. //
  88. // Synopsis:
  89. //
  90. // Arguments: [hwndDlg] --
  91. // [fTraceLoc] --
  92. //
  93. // Returns:
  94. //
  95. // History: 4-29-95 kennethm Created
  96. //
  97. // Notes:
  98. //
  99. //--------------------------------------------------------------------------
  100. void CDebugHelp::UpdateTraceLocations(HWND hwndDlg, DWORD fTraceLoc)
  101. {
  102. CheckDlgButton(hwndDlg, IDC_TLDEBUGTERM, (fTraceLoc & DH_LOC_TERM) ? 1 : 0);
  103. CheckDlgButton(hwndDlg, IDC_TLLOGFILE, (fTraceLoc & DH_LOC_LOG) ? 1 : 0);
  104. CheckDlgButton(hwndDlg, IDC_TLCONSOLE, (fTraceLoc & DH_LOC_STDOUT) ? 1 : 0);
  105. CheckDlgButton(hwndDlg, IDC_TLSPYWIN, (fTraceLoc & DH_LOC_SPYWIN) ? 1 : 0);
  106. }
  107. //+-------------------------------------------------------------------------
  108. //
  109. // Function: UpdateTraceLevelFromText
  110. //
  111. // Synopsis:
  112. //
  113. // Arguments: [hwndDlg] --
  114. // [pfTraceLvl] --
  115. //
  116. // Returns:
  117. //
  118. // History: 4-29-95 kennethm Created
  119. //
  120. // Notes:
  121. //
  122. //--------------------------------------------------------------------------
  123. void CDebugHelp::UpdateTraceLevelFromText(HWND hwndDlg, DWORD *pfTraceLvl)
  124. {
  125. CHAR szTraceLvl[MAX_PATH];
  126. GetDlgItemTextA(hwndDlg, IDC_TRACELEVEL, szTraceLvl, MAX_PATH);
  127. sscanf(szTraceLvl, "%lx", pfTraceLvl);
  128. *pfTraceLvl &= DH_LVL_OUTMASK;
  129. UpdateTraceLevels(hwndDlg, *pfTraceLvl);
  130. }
  131. //+-------------------------------------------------------------------------
  132. //
  133. // Function: DebugDialogProc
  134. //
  135. // Synopsis:
  136. //
  137. // Arguments: [hwndDlg] --
  138. // [uMsg] --
  139. // [wParam] --
  140. // [lParam] --
  141. //
  142. // Returns:
  143. //
  144. // History: 4-29-95 kennethm Created
  145. //
  146. // Notes:
  147. //
  148. //--------------------------------------------------------------------------
  149. BOOL CALLBACK CDebugHelp::OptionsDialogProc(
  150. HWND hwndDlg, // handle of dialog box
  151. UINT uMsg, // message
  152. WPARAM wParam, // first message parameter
  153. LPARAM lParam) // second message parameter
  154. {
  155. static DWORD fLabMode;
  156. static DWORD fBreakMode;
  157. static DWORD fVerbose;
  158. static DWORD fTraceLoc;
  159. static DWORD fTraceLvl;
  160. static DWORD fLogLoc;
  161. DWORD fLevelMask = 0;
  162. DWORD fTraceLocMask = 0;
  163. DWORD fLogLocMask = 0;
  164. CDebugHelp *pdh = 0;
  165. // get or set the this pointer.
  166. if (WM_INITDIALOG == uMsg)
  167. {
  168. // this pointer comes in as lParam. Save it.
  169. SetWindowLong (hwndDlg, DWL_USER, lParam);
  170. pdh = (CDebugHelp*)lParam;
  171. }
  172. else
  173. {
  174. pdh = (CDebugHelp*)GetWindowLong (hwndDlg, DWL_USER);
  175. }
  176. // if we dont have one, bail.
  177. if (NULL == pdh)
  178. {
  179. return FALSE;
  180. }
  181. // message processor
  182. switch (uMsg)
  183. {
  184. case WM_INITDIALOG:
  185. //
  186. // Initialize the controls
  187. //
  188. fLabMode = pdh->_fMode&DH_LABMODE ? DH_LABMODE_ON : DH_LABMODE_OFF;
  189. fBreakMode= pdh->_fMode&DH_BREAKMODE ? DH_BREAKMODE_ON : DH_BREAKMODE_OFF;
  190. fVerbose = pdh->_fMode&DH_VERBOSE ? DH_VERBOSE_ON : DH_VERBOSE_OFF;
  191. fTraceLoc = pdh->_fTraceLoc;
  192. fTraceLvl = pdh->_fTraceLvl;
  193. fLogLoc = pdh->_fLogLoc;
  194. //
  195. // modes
  196. //
  197. if (DH_LABMODE_OFF == fLabMode)
  198. {
  199. CheckDlgButton(hwndDlg, IDC_POPUP, TRUE);
  200. }
  201. if (DH_BREAKMODE_ON == fBreakMode)
  202. {
  203. CheckDlgButton(hwndDlg, IDC_BREAK, TRUE);
  204. }
  205. if (DH_VERBOSE_ON == fVerbose)
  206. {
  207. CheckDlgButton(hwndDlg, IDC_VERBOSE, TRUE);
  208. }
  209. //
  210. // Trace location flags
  211. //
  212. pdh->UpdateTraceLocations(hwndDlg, fTraceLoc);
  213. //
  214. // Log Location flags
  215. //
  216. pdh->UpdateLogLocations(hwndDlg, fLogLoc);
  217. //
  218. // Trace level flags
  219. //
  220. pdh->UpdateTraceLevels(hwndDlg, fTraceLvl);
  221. // if no log object show the notification
  222. if (!pdh->_plog)
  223. {
  224. ShowWindow (GetDlgItem(hwndDlg, IDC_WARNING), SW_SHOW);
  225. }
  226. // display the spywindow class if there is one
  227. if (pdh->GetSpyWindowClass ())
  228. {
  229. SetDlgItemText (hwndDlg, IDC_SPYWINDOWLOC, pdh->GetSpyWindowClass ());
  230. }
  231. return TRUE;
  232. case WM_COMMAND:
  233. switch (LOWORD(wParam))
  234. {
  235. case IDOK:
  236. // if log to file is set and we have a log file
  237. // create a log object
  238. if (fTraceLoc & DH_LOC_LOG || fLogLoc & DH_LOC_LOG)
  239. {
  240. CHAR szLog[MAX_PATH] = {"/t:"};
  241. if (0 < GetDlgItemTextA (hwndDlg,
  242. IDC_LOGFILELOC,
  243. &szLog[3],
  244. sizeof (szLog) - 3))
  245. {
  246. pdh->CreateLog (szLog);
  247. }
  248. }
  249. // if spywindow is set and we have a spy window class
  250. // set spy window class in debug object
  251. if (fTraceLoc & DH_LOC_SPYWIN || fLogLoc & DH_LOC_SPYWIN)
  252. {
  253. TCHAR tszSpyWin[255] = {TEXT("")};
  254. if (0 < GetDlgItemText (hwndDlg,
  255. IDC_SPYWINDOWLOC,
  256. tszSpyWin,
  257. ARRAYSIZE (tszSpyWin)))
  258. {
  259. pdh->SetSpyWindowClass (tszSpyWin);
  260. }
  261. }
  262. //
  263. // The user pressed ok, save the settings
  264. //
  265. pdh->UpdateTraceLevelFromText(hwndDlg, &fTraceLvl);
  266. pdh->SetDebugInfo(
  267. fLogLoc,
  268. fTraceLoc,
  269. fTraceLvl,
  270. fLabMode | fBreakMode | fVerbose);
  271. if (IsDlgButtonChecked(hwndDlg, IDC_SAVE) == 1)
  272. {
  273. //
  274. // Save the settings to the registry
  275. //
  276. pdh->WriteRegDbgInfo (DEFAULT_REG_LOC);
  277. }
  278. //
  279. // Fall through
  280. //
  281. case IDCANCEL:
  282. EndDialog(hwndDlg, 0);
  283. return TRUE;
  284. // Popup and break are mutually exclusive.
  285. // If one is turned on, turn other off.
  286. case IDC_POPUP:
  287. if (IsDlgButtonChecked(hwndDlg, wParam) == 1)
  288. {
  289. fLabMode = DH_LABMODE_OFF;
  290. fBreakMode = DH_BREAKMODE_OFF;
  291. CheckDlgButton (hwndDlg, IDC_BREAK, FALSE); //turn off Break.
  292. }
  293. else
  294. {
  295. fLabMode = DH_LABMODE_ON;
  296. }
  297. break;
  298. case IDC_BREAK:
  299. if (IsDlgButtonChecked(hwndDlg, wParam) == 1)
  300. {
  301. fBreakMode = DH_BREAKMODE_ON;
  302. fLabMode = DH_LABMODE_ON;
  303. CheckDlgButton (hwndDlg, IDC_POPUP, FALSE); //turn off Popup.
  304. }
  305. else
  306. {
  307. fBreakMode = DH_BREAKMODE_OFF;
  308. }
  309. break;
  310. case IDC_VERBOSE:
  311. if (IsDlgButtonChecked(hwndDlg, wParam) == 1)
  312. {
  313. fVerbose = DH_VERBOSE_ON;
  314. }
  315. else
  316. {
  317. fVerbose = DH_VERBOSE_OFF;
  318. }
  319. break;
  320. case IDC_TRACELEVEL:
  321. if (HIWORD(wParam) == EN_KILLFOCUS)
  322. {
  323. pdh->UpdateTraceLevelFromText(hwndDlg, &fTraceLvl);
  324. }
  325. break;
  326. case IDC_TLDEBUGTERM:
  327. fTraceLocMask = DH_LOC_TERM;
  328. break;
  329. case IDC_TLSPYWIN:
  330. fTraceLocMask = DH_LOC_SPYWIN;
  331. break;
  332. case IDC_TLCONSOLE:
  333. fTraceLocMask = DH_LOC_STDOUT;
  334. break;
  335. case IDC_TLLOGFILE:
  336. fTraceLocMask = DH_LOC_LOG;
  337. break;
  338. case IDC_LLDEBUGTERM:
  339. fLogLocMask = DH_LOC_TERM;
  340. break;
  341. case IDC_LLSPYWIN:
  342. fLogLocMask = DH_LOC_SPYWIN;
  343. break;
  344. case IDC_LLCONSOLE:
  345. fLogLocMask = DH_LOC_STDOUT;
  346. break;
  347. case IDC_LLLOGFILE:
  348. fLogLocMask = DH_LOC_LOG;
  349. break;
  350. case IDC_LEVEL1:
  351. fLevelMask = DH_LVL_TRACE1;
  352. break;
  353. case IDC_LEVEL2:
  354. fLevelMask = DH_LVL_TRACE2;
  355. break;
  356. case IDC_LEVEL3:
  357. fLevelMask = DH_LVL_TRACE3;
  358. break;
  359. case IDC_LEVEL4:
  360. fLevelMask = DH_LVL_TRACE4;
  361. break;
  362. case IDC_FUNCOUT:
  363. fLevelMask = DH_LVL_EXIT;
  364. break;
  365. case IDC_FUNCIN:
  366. fLevelMask = DH_LVL_ENTRY;
  367. break;
  368. case IDC_QI:
  369. fLevelMask = DH_LVL_QI;
  370. break;
  371. case IDC_ADDREL:
  372. fLevelMask = DH_LVL_ADDREL;
  373. break;
  374. case IDC_INTERF:
  375. fLevelMask = DH_LVL_INTERF;
  376. break;
  377. }
  378. //
  379. // See if any of the mask have been changed.
  380. // If one has been then update our local flag
  381. //
  382. if (fLevelMask != 0)
  383. {
  384. if (IsDlgButtonChecked(hwndDlg, LOWORD(wParam)) == 0)
  385. {
  386. fTraceLvl &= ~fLevelMask;
  387. }
  388. else
  389. {
  390. fTraceLvl |= fLevelMask;
  391. }
  392. pdh->UpdateTraceLevels(hwndDlg, fTraceLvl);
  393. }
  394. if (fLogLocMask != 0)
  395. {
  396. if (IsDlgButtonChecked(hwndDlg, LOWORD(wParam)) == 0)
  397. {
  398. fLogLoc &= ~fLogLocMask;
  399. }
  400. else
  401. {
  402. fLogLoc |= fLogLocMask;
  403. }
  404. pdh->UpdateTraceLevels(hwndDlg, fTraceLvl);
  405. }
  406. if (fTraceLocMask != 0)
  407. {
  408. if (IsDlgButtonChecked(hwndDlg, LOWORD(wParam)) == 0)
  409. {
  410. fTraceLoc &= ~fTraceLocMask;
  411. }
  412. else
  413. {
  414. fTraceLoc |= fTraceLocMask;
  415. }
  416. pdh->UpdateTraceLevels(hwndDlg, fTraceLvl);
  417. }
  418. break;
  419. }
  420. return FALSE;
  421. }
  422. //+-------------------------------------------------------------------------
  423. //
  424. // Function: DebugOptionsDialog
  425. //
  426. // Synopsis:
  427. //
  428. // Arguments: [hinstance] --
  429. // [hWnd] --
  430. //
  431. // Returns:
  432. //
  433. // History: 4-29-95 kennethm Created
  434. //
  435. // Notes:
  436. //
  437. //--------------------------------------------------------------------------
  438. HRESULT CDebugHelp::OptionsDialog(HINSTANCE hinstance, HWND hWnd)
  439. {
  440. HRESULT hr = S_OK;
  441. int iRet;
  442. iRet = DialogBoxParam(
  443. hinstance,
  444. MAKEINTRESOURCE(IDD_DEBUGDIALOG),
  445. hWnd,
  446. OptionsDialogProc,
  447. (long)this);
  448. if (iRet == -1)
  449. {
  450. hr = HRESULT_FROM_WIN32(GetLastError());
  451. }
  452. return hr;
  453. }