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

  1. #include "dbwin.h"
  2.  
  3. // AllocBrkDlg functions
  4.  
  5. int     AllocBrkDlg_Do(HWND hwndOwner);
  6.  
  7. BOOL CALLBACK _export AllocBrkDlg_OldDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  8. LRESULT AllocBrkDlg_DefProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  9.  
  10. LRESULT AllocBrkDlg_DlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
  11.  
  12. BOOL    AllocBrkDlg_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam);
  13. VOID    AllocBrkDlg_OnCommand(HWND hwnd, UINT id, HWND hwndCtl, UINT codeNotify);
  14.  
  15. void    AllocBrkDlg_WriteOptions(HWND hwndDlg, UINT option, UINT filter);
  16. void    AllocBrkDlg_ReadOptions(HWND hwndDlg, UINT FAR* poptions, UINT FAR* pfilter);
  17.  
  18. //---------------------------------------------------------------------------
  19.  
  20. static WINDEBUGINFO wdi;
  21.  
  22. //---------------------------------------------------------------------------
  23.  
  24. void DoAllocBrk(HWND hwndOwner)
  25. {
  26.     DLGPROC pfndp;
  27.     extern HINSTANCE hinstDBWin;
  28.  
  29.     pfndp = (DLGPROC)MakeProcInstance((FARPROC)AllocBrkDlg_OldDlgProc, hinstDBWin);
  30.  
  31.     DialogBoxParam(hinstDBWin, MAKEINTRESOURCE(IDR_ALLOCBRKDLG), hwndOwner, pfndp, 0L);
  32.  
  33.     FreeProcInstance((FARPROC)pfndp);
  34. }
  35.  
  36. static BOOL fDefDlgEx = FALSE;
  37.  
  38. BOOL CALLBACK _export AllocBrkDlg_OldDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  39. {
  40.     CheckDefDlgRecursion(&fDefDlgEx);
  41.  
  42.     return SetDlgMsgResult(hwndDlg, msg, AllocBrkDlg_DlgProc(hwndDlg, msg, wParam, lParam));
  43. }
  44.  
  45. LRESULT AllocBrkDlg_DefProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  46. {
  47.     return DefDlgProcEx(hwndDlg, msg, wParam, lParam, &fDefDlgEx);
  48. }
  49.  
  50. LRESULT AllocBrkDlg_DlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  51. {
  52.     switch (msg)
  53.     {
  54.         HANDLE_MSG(hwndDlg, WM_INITDIALOG, AllocBrkDlg_OnInitDialog);
  55.         HANDLE_MSG(hwndDlg, WM_COMMAND, AllocBrkDlg_OnCommand);
  56.     default:
  57.         return AllocBrkDlg_DefProc(hwndDlg, msg, wParam, lParam);
  58.     }
  59. }
  60.  
  61. BOOL AllocBrkDlg_OnInitDialog(HWND hwndDlg, HWND hwndFocus, LPARAM lParam)
  62. {
  63.     HWND hwndModule = GetDlgItem(hwndDlg, CTL_MODULE);
  64.     HWND hwndBrkCount = GetDlgItem(hwndDlg, CTL_BRKCOUNT);
  65.     HWND hwndAllocCount = GetDlgItem(hwndDlg, CTL_ALLOCCOUNT);
  66.     char ach[32];
  67.     int i;
  68.  
  69.     GetWinDebugInfo(&wdi, WDI_ALLOCBREAK);
  70.     for (i = 0; i != 8; i++)
  71.     {
  72.         ach[i] = wdi.achAllocModule[i];
  73.         if (ach[i] == 0)
  74.             break;
  75.     }
  76.     ach[8] = 0;
  77.     Edit_SetText(hwndModule, ach);
  78.  
  79.     wsprintf(ach, "%ld", wdi.dwAllocBreak);
  80.     Edit_SetText(hwndBrkCount, ach);
  81.  
  82.     wsprintf(ach, "%ld", wdi.dwAllocCount);
  83.     Edit_SetText(hwndAllocCount, ach);
  84.  
  85.     return TRUE;
  86. }
  87.  
  88. DWORD DwordFromString(LPSTR lpsz);
  89. void AllocBrkDlg_Set(HWND hwndDlg);
  90.  
  91. void AllocBrkDlg_OnCommand(HWND hwndDlg, UINT id, HWND hwndCtl, UINT code)
  92. {
  93.     HWND hwndModule = GetDlgItem(hwndDlg, CTL_MODULE);
  94.     HWND hwndBrkCount = GetDlgItem(hwndDlg, CTL_BRKCOUNT);
  95.     DWORD c;
  96.     char ach[32];
  97.  
  98.     switch (id)
  99.     {
  100.     case CTL_CLEAR:
  101.         Edit_SetText(hwndModule, NULL);
  102.         Edit_SetText(hwndBrkCount, NULL);
  103.         AllocBrkDlg_Set(hwndDlg);
  104.         break;
  105.  
  106.     case CTL_INCSET:
  107.         Edit_GetText(hwndBrkCount, ach, sizeof(ach));
  108.         c = DwordFromString(ach) + 1;
  109.         wsprintf(ach, "%ld", c);
  110.         Edit_SetText(hwndBrkCount, ach);
  111.         AllocBrkDlg_Set(hwndDlg);
  112.         break;
  113.  
  114.     case CTL_OK:
  115.         AllocBrkDlg_Set(hwndDlg);
  116.         break;
  117.  
  118.     case CTL_CANCEL:
  119.         EndDialog(hwndDlg, 0);
  120.     break;
  121.  
  122.     case CTL_SHOWCOUNT:
  123.         // Update the alloc break count
  124.         //
  125.         GetWinDebugInfo(&wdi, WDI_ALLOCBREAK);
  126.         wsprintf(ach, "%ld", wdi.dwAllocCount);
  127.         Edit_SetText(GetDlgItem(hwndDlg, CTL_ALLOCCOUNT), ach);
  128.         break;
  129.     }
  130. }
  131.  
  132. void AllocBrkDlg_Set(HWND hwndDlg)
  133. {
  134.     HWND hwndModule = GetDlgItem(hwndDlg, CTL_MODULE);
  135.     HWND hwndBrkCount = GetDlgItem(hwndDlg, CTL_BRKCOUNT);
  136.     HWND hwndAllocCount = GetDlgItem(hwndDlg, CTL_ALLOCCOUNT);
  137.     DWORD c;
  138.     int i;
  139.     char ach[32];
  140.  
  141.     Edit_GetText(hwndBrkCount, ach, sizeof(ach));
  142.     c = DwordFromString(ach);
  143.  
  144.     Edit_GetText(hwndModule, ach, sizeof(ach));
  145.  
  146.     for (i = 0; i != 8; i++)
  147.     {
  148.         wdi.achAllocModule[i] = ach[i];
  149.         if (ach[i] == 0)
  150.             break;
  151.     }
  152.  
  153.     wdi.flags = WDI_ALLOCBREAK;
  154.     wdi.dwAllocBreak = c;
  155.     wdi.dwAllocCount = 0;
  156.     SetWinDebugInfo(&wdi);
  157.  
  158.     Edit_SetText(hwndAllocCount, "0");
  159.  
  160.     Edit_SetSel(hwndBrkCount, 0, 32767);
  161.     SetFocus(hwndBrkCount);
  162. }
  163.  
  164. DWORD DwordFromString(LPSTR lpsz)
  165. {
  166.     DWORD l = 0;
  167.     char ch;
  168.  
  169.     while (ch = *lpsz++)
  170.     {
  171.         if (ch < '0' || ch > '9')
  172.             break;
  173.         l = (l * 10) + (ch - '0');
  174.     }
  175.     return l;
  176. }
  177.