home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / SAMPLES / DBWIN / SETDB.C_ / SETDB.C
Encoding:
C/C++ Source or Header  |  1993-02-08  |  6.6 KB  |  233 lines

  1. #include "dbwin.h"
  2.  
  3. // DbgOptDlg functions
  4.  
  5. int     DbgOptDlg_Do(HWND hwndOwner);
  6.  
  7. BOOL CALLBACK _export DbgOptDlg_OldDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  8. LRESULT DbgOptDlg_DefProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  9.  
  10. LRESULT DbgOptDlg_DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  11.  
  12. BOOL    DbgOptDlg_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam);
  13. VOID    DbgOptDlg_OnCommand(HWND hwnd, UINT id, HWND hwndCtl, UINT codeNotify);
  14.  
  15. void    DbgOptDlg_OutputOptions(HWND hwndDlg, UINT option, UINT filter, LPCSTR lpszTaskFilter);
  16. void    DbgOptDlg_InputOptions(HWND hwndDlg, UINT FAR* poptions, UINT FAR* pfilter, LPSTR lpszTaskFilter);
  17.  
  18. //---------------------------------------------------------------------------
  19.  
  20. BOOL fOptionsSaved = FALSE;
  21. UINT DebugOptionsSave = 0;
  22. UINT DebugFilterSave = 0;
  23. char szTaskFilter[MAX_MODULE_NAME];
  24.  
  25. static WINDEBUGINFO wdi;
  26.  
  27. typedef struct
  28. {
  29.     UINT idCtl;
  30.     UINT options;
  31.     UINT filter;
  32. } DBOITEM;
  33.  
  34. //---------------------------------------------------------------------------
  35.  
  36. void DoDebugOptions(HWND hwndOwner)
  37. {
  38.     DLGPROC pfndp;
  39.     extern HINSTANCE hinstDBWin;
  40.  
  41.     pfndp = (DLGPROC)MakeProcInstance((FARPROC)DbgOptDlg_OldDlgProc, hinstDBWin);
  42.  
  43.     DialogBoxParam(hinstDBWin, MAKEINTRESOURCE(IDR_SETDBDLG), hwndOwner, pfndp, 0L);
  44.  
  45.     FreeProcInstance((FARPROC)pfndp);
  46. }
  47.  
  48. void DoSaveOptions(HWND hwndOwner)
  49. {
  50.     char ach[10];
  51.  
  52.     wsprintf(ach, "0x%04x", (UINT)wdi.dwOptions);
  53.     WriteProfileString("Windows", "DebugOptions", (LPSTR)ach);
  54.  
  55.     wsprintf(ach, "0x%04x", (UINT)wdi.dwFilter);
  56.     WriteProfileString("Windows", "DebugFilter", (LPSTR)ach);
  57.  
  58.     // Save out the task filter now (even though the system doesn't
  59.     // read this option)
  60.     //
  61.     WriteProfileString("Windows", "DebugTaskFilter", (LPSTR)szTaskFilter);
  62. }
  63.  
  64. static BOOL fDefDlgEx = FALSE;
  65.  
  66. BOOL CALLBACK _export DbgOptDlg_OldDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  67. {
  68.     CheckDefDlgRecursion(&fDefDlgEx);
  69.  
  70.     return SetDlgMsgResult(hwndDlg, msg, DbgOptDlg_DlgProc(hwndDlg, msg, wParam, lParam));
  71. }
  72.  
  73. LRESULT DbgOptDlg_DefProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  74. {
  75.     return DefDlgProcEx(hwndDlg, msg, wParam, lParam, &fDefDlgEx);
  76. }
  77.  
  78. LRESULT DbgOptDlg_DlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  79. {
  80.     switch (msg)
  81.     {
  82.         HANDLE_MSG(hwndDlg, WM_INITDIALOG, DbgOptDlg_OnInitDialog);
  83.         HANDLE_MSG(hwndDlg, WM_COMMAND, DbgOptDlg_OnCommand);
  84.     default:
  85.         return DbgOptDlg_DefProc(hwndDlg, msg, wParam, lParam);
  86.     }
  87. }
  88.  
  89. BOOL DbgOptDlg_OnInitDialog(HWND hwndDlg, HWND hwndFocus, LPARAM lParam)
  90. {
  91.     if (!GetWinDebugInfo(&wdi, WDI_OPTIONS | WDI_FILTER))
  92.         return FALSE;
  93.  
  94.     if (wdi.flags != (WDI_OPTIONS | WDI_FILTER))
  95.         return FALSE;
  96.  
  97.     // Initialize the saved options/filter the first time the dialog
  98.     // is brought up: these are used for restore later.
  99.     //
  100.     if (!fOptionsSaved)
  101.     {
  102.         fOptionsSaved = TRUE;
  103.         DebugOptionsSave = (UINT)wdi.dwOptions;
  104.         DebugFilterSave = (UINT)wdi.dwFilter;
  105.  
  106.         // Read the DebugTaskFilter() from win.ini
  107.         // NOTE: Windows doesn't pay attention to this key -- only dbwin does.
  108.         //
  109.         GetProfileString("Windows", "DebugTaskFilter", "", szTaskFilter, sizeof(szTaskFilter));
  110.         SetTaskFilter(szTaskFilter);
  111.     }
  112.  
  113.     GetTaskFilter(szTaskFilter, sizeof(szTaskFilter));
  114.  
  115.     // Set up dialog to reflect current options
  116.     //
  117.     DbgOptDlg_OutputOptions(hwndDlg, (UINT)wdi.dwOptions, (UINT)wdi.dwFilter, szTaskFilter);
  118.  
  119.     return TRUE;
  120. }
  121.  
  122. VOID DbgOptDlg_OnCommand(HWND hwndDlg, UINT id, HWND hwndCtl, UINT code)
  123. {
  124.     switch (id)
  125.     {
  126.     case IDOK:    // CTL_OK
  127.         {
  128.             UINT options;
  129.             UINT filter;
  130.  
  131.             DbgOptDlg_InputOptions(hwndDlg, &options, &filter, szTaskFilter);
  132.  
  133.             SetTaskFilter(szTaskFilter);
  134.  
  135.             wdi.dwOptions = options;
  136.             wdi.dwFilter = filter;
  137.             wdi.flags = WDI_OPTIONS | WDI_FILTER;
  138.             SetWinDebugInfo(&wdi);
  139.         }
  140.  
  141.     // fall through...
  142.  
  143.     case IDCANCEL:    // CTL_CANCEL
  144.         EndDialog(hwndDlg, id);
  145.     break;
  146.  
  147.     case CTL_DEFAULTS:
  148.         if (code == BN_CLICKED)
  149.         {
  150.             wdi.dwOptions = DebugOptionsSave;
  151.             wdi.dwFilter = DebugFilterSave;
  152.             wdi.flags = WDI_OPTIONS | WDI_FILTER;
  153.             SetWinDebugInfo(&wdi);
  154.  
  155.             SetTaskFilter("");
  156.  
  157.             DbgOptDlg_OutputOptions(hwndDlg, (UINT)wdi.dwOptions, (UINT)wdi.dwFilter, szTaskFilter);
  158.     }
  159.     break;
  160.     }
  161. }
  162.  
  163. DBOITEM adbo[] =
  164. {
  165.     { CTL_CHECKHEAP, DBO_CHECKHEAP, 0 },
  166.     { CTL_CHECKFREE, DBO_CHECKFREE, 0 },
  167.     { CTL_FILLBUFFER, DBO_BUFFERFILL, 0 },
  168.     { CTL_DISABLEGPTRAPPING, DBO_DISABLEGPTRAPPING, 0 },
  169.  
  170.     { CTL_SILENT, DBO_SILENT, 0 },
  171.  
  172.     { CTL_TRACEBREAK, DBO_TRACEBREAK, 0 },
  173.     { CTL_WARNINGBREAK, DBO_WARNINGBREAK, 0 },
  174.     { CTL_NOERRORBREAK, DBO_NOERRORBREAK, 0 },
  175.     { CTL_NOFATALBREAK, DBO_NOFATALBREAK, 0 },
  176.     { CTL_INT3, DBO_INT3BREAK, 0 },
  177.  
  178.     { CTL_KERNEL, 0, DBF_KERNEL },
  179.     { CTL_MEMMAN, 0, DBF_KRN_MEMMAN },
  180.     { CTL_LOADMODULE, 0, DBF_KRN_LOADMODULE },
  181.     { CTL_LOADSEGMENT, 0, DBF_KRN_SEGMENTLOAD },
  182.     { CTL_USER, 0, DBF_USER },
  183.     { CTL_GDI, 0, DBF_GDI },
  184.     { CTL_MMSYSTEM, 0, DBF_MMSYSTEM },
  185.     { CTL_PENWIN, 0, DBF_PENWIN },
  186.     { CTL_DRIVER, 0, DBF_DRIVER },
  187.     { CTL_APPLICATION, 0, DBF_APPLICATION }
  188. };
  189.  
  190. void DbgOptDlg_InputOptions(HWND hwndDlg, UINT FAR* poptions, UINT FAR* pfilter, LPSTR lpszFilter)
  191. {
  192.     DBOITEM* pdbo;
  193.     UINT options = 0;
  194.     UINT filter = 0;
  195.  
  196.     // Get task filter
  197.     //
  198.     Edit_GetText(GetDlgItem(hwndDlg, CTL_APPNAME), lpszFilter, MAX_MODULE_NAME);
  199.  
  200.     for (pdbo = adbo; pdbo != &adbo[sizeof(adbo) / sizeof(DBOITEM)]; pdbo++)
  201.     {
  202.         HWND hwndButton = GetDlgItem(hwndDlg, pdbo->idCtl);
  203.  
  204.         if (Button_GetCheck(hwndButton))
  205.         {
  206.             options |= pdbo->options;
  207.             filter |= pdbo->filter;
  208.         }
  209.         else
  210.         {
  211.             options &= ~pdbo->options;
  212.             filter &= ~pdbo->filter;
  213.         }
  214.     }
  215.     *poptions = options;
  216.     *pfilter = filter;
  217. }
  218.  
  219. void DbgOptDlg_OutputOptions(HWND hwndDlg, UINT option, UINT filter, LPCSTR lpszFilter)
  220. {
  221.     DBOITEM* pdbo;
  222.  
  223.     Edit_SetText(GetDlgItem(hwndDlg, CTL_APPNAME), lpszFilter);
  224.  
  225.     for (pdbo = adbo; pdbo != &adbo[sizeof(adbo) / sizeof(DBOITEM)]; pdbo++)
  226.     {
  227.         HWND hwndButton = GetDlgItem(hwndDlg, pdbo->idCtl);
  228.  
  229.         Button_SetCheck(hwndButton,
  230.                 ((pdbo->options & option) || (pdbo->filter & filter)) );
  231.     }
  232. }
  233.