1
0

DlgBase.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #include <windows.h>
  2. #include "main.h"
  3. static void SetWindowRect(HWND w, RECT * r)
  4. {
  5. SetWindowPos(w, 0, r->left, r->top, r->right - r->left, r->bottom - r->top, SWP_NOZORDER | SWP_NOCOPYBITS);
  6. }
  7. class DlgBase
  8. {
  9. public:
  10. BOOL isDialogMessage(MSG * m)
  11. {
  12. return wnd ? IsDialogMessage(wnd, m) : 0;
  13. }
  14. protected:
  15. void endDialog(int x)
  16. {
  17. EndDialog(wnd, x);
  18. }
  19. void _do_size_x(RECT * r, UINT id, UINT wx, UINT min_x)
  20. {
  21. RECT r1 = {r->left, r->top, wx - min_x + r->right, r->bottom};
  22. SetWindowRect(GetDlgItem(wnd, id), &r1);
  23. }
  24. void _do_size_xy(RECT * r, UINT id, UINT wx, UINT wy, UINT min_x, UINT min_y)
  25. {
  26. RECT r1 = {r->left, r->top, wx - min_x + r->right, wy - min_y + r->bottom};
  27. SetWindowRect(GetDlgItem(wnd, id), &r1);
  28. }
  29. void _do_align_x_size_y(RECT * r, UINT id, UINT wx, UINT wy, UINT min_x, UINT min_y)
  30. {
  31. RECT r1 = {wx - min_x + r->left, r->top, wx - min_x + r->right, wy - min_y + r->bottom};
  32. SetWindowRect(GetDlgItem(wnd, id), &r1);
  33. }
  34. void _do_align_x(RECT * r, UINT id, UINT wx, UINT min_x)
  35. {
  36. RECT r1 = {wx - min_x + r->left, r->top, wx - min_x + r->right, r->bottom};
  37. SetWindowRect(GetDlgItem(wnd, id), &r1);
  38. }
  39. void _do_align_xy(RECT * r, UINT id, UINT wx, UINT wy, UINT min_x, UINT min_y)
  40. {
  41. RECT r1 = {wx - min_x + r->left, wy - min_y + r->top, wx - min_x + r->right, wy - min_y + r->bottom};
  42. SetWindowRect(GetDlgItem(wnd, id), &r1);
  43. }
  44. #define do_size_x(id,r) _do_size_x(r,id,sx,min_size_x)
  45. #define do_size_xy(id,r) _do_size_xy(r,id,sx,sy,min_size_x,min_size_y)
  46. #define do_align_x_size_y(id,r) _do_align_x_size_y(r,id,sx,sy,min_size_x,min_size_y)
  47. #define do_align_xy(id,r) _do_align_xy(r,id,sx,sy,min_size_x,min_size_y)
  48. #define do_align_x(id,r) _do_align_x(r,id,sx,min_size_x)
  49. HWND wnd;
  50. UINT min_size_x, min_size_y;
  51. UINT min_size_x_w, min_size_y_w;
  52. void do_sizing(UINT wp, RECT * r);
  53. void MakeComboEdit(UINT id, DWORD s);
  54. void GetChildRect(UINT id, RECT& child);
  55. virtual BOOL DlgProc(UINT msg, WPARAM wp, LPARAM lp) { return 0;};
  56. static BOOL CALLBACK TheDialogProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp)
  57. {
  58. DlgBase * p;
  59. if (msg == WM_INITDIALOG)
  60. {
  61. p = (DlgBase*)lp;
  62. SetWindowLong(wnd, DWL_USER, lp);
  63. p->wnd = wnd;
  64. RECT r;
  65. GetClientRect(wnd, &r);
  66. p->min_size_x = r.right;
  67. p->min_size_y = r.bottom;
  68. GetWindowRect(wnd, &r);
  69. p->min_size_x_w = r.right - r.left;
  70. p->min_size_y_w = r.bottom - r.top;
  71. }
  72. else p = (DlgBase*)GetWindowLong(wnd, DWL_USER);
  73. BOOL rv = 0;
  74. if (p)
  75. {
  76. rv = p->DlgProc(msg, wp, lp);
  77. if (msg == WM_DESTROY)
  78. {
  79. p->wnd = 0;
  80. SetWindowLong(wnd, DWL_USER, 0);
  81. }
  82. }
  83. return rv;
  84. }
  85. HWND myCreateDialog(UINT id, HWND parent)
  86. {
  87. return CreateDialogParamT(hIns, (char*)id, parent, TheDialogProc, (long)this);
  88. }
  89. virtual void myProcessMessage(MSG * msg)
  90. {
  91. if (!IsDialogMessage(wnd, msg))
  92. {
  93. TranslateMessage(msg);
  94. DispatchMessage(msg);
  95. }
  96. }
  97. int myDialogBox(UINT id, HWND parent)
  98. {
  99. return DialogBoxParamT(hIns, (char*)id, parent, TheDialogProc, (long)this);
  100. }
  101. DlgBase() {
  102. wnd = 0;
  103. min_size_x = min_size_y = min_size_x_w = min_size_y_w = 0;
  104. }
  105. virtual ~DlgBase() {}
  106. };