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.

125 lines
2.8 KiB

  1. #include "precomp.hxx"
  2. #include "dialog.h"
  3. INT_PTR Dialog::DialogStaticDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  4. {
  5. Dialog *pThis;
  6. pThis = (Dialog*) GetWindowLongPtr(hDlg, DWLP_USER);
  7. if (msg == WM_INITDIALOG) {
  8. pThis = (Dialog *) lParam;
  9. pThis->hDlg = hDlg;
  10. SetWindowLongPtr(hDlg, DWLP_USER, (ULONG_PTR) pThis);
  11. return pThis->OnInitDialog(hDlg);
  12. }
  13. if (pThis) {
  14. return pThis->MainDlgProc(msg, wParam, lParam);
  15. }
  16. return FALSE;
  17. }
  18. INT_PTR Dialog::MainDlgProc(UINT msg, WPARAM wParam, LPARAM lParam)
  19. {
  20. switch (msg) {
  21. case WM_COMMAND:
  22. HandleCommand((UINT) LOWORD(wParam), (HWND)lParam, (UINT)HIWORD(wParam));
  23. return FALSE;
  24. case WM_HELP:
  25. return OnHelp((LPHELPINFO) lParam);
  26. case WM_CONTEXTMENU:
  27. return OnContextMenu(wParam, lParam);
  28. case WM_NOTIFY:
  29. return OnNotify((NMHDR *)lParam);
  30. }
  31. return DlgProc(msg, wParam, lParam);
  32. }
  33. void Dialog::HandleCommand(UINT ctrlId, HWND hwndCtrl, UINT cNotify)
  34. {
  35. switch (ctrlId) {
  36. case IDOK:
  37. OnOK();
  38. break;
  39. case IDCANCEL:
  40. OnCancel();
  41. break;
  42. default:
  43. OnCommand(ctrlId, hwndCtrl, cNotify);
  44. break;
  45. }
  46. }
  47. UINT Dialog::ShowModal(HWND hwndParent)
  48. {
  49. DialogBoxParam(hInstance,
  50. MAKEINTRESOURCE(resID),
  51. hwndParent,
  52. DialogStaticDlgProc,
  53. (DWORD_PTR) this);
  54. return result;
  55. }
  56. HICON Dialog::SetIcon(UINT iconID, BOOL bLarge)
  57. {
  58. HICON hIcon;
  59. int size;
  60. size = bLarge ? 32 : 16;
  61. hIcon = (HICON) LoadImage(hInstance,
  62. MAKEINTRESOURCE(iconID),
  63. IMAGE_ICON,
  64. size,
  65. size,
  66. 0);
  67. return (HICON)
  68. ::SendMessage(hDlg,
  69. WM_SETICON,
  70. bLarge ? ICON_BIG : ICON_SMALL,
  71. (LPARAM) hIcon);
  72. }
  73. void Dialog::CenterWindow(HWND hwnd)
  74. {
  75. RECT me;
  76. RECT parent;
  77. if (hwnd == NULL) {
  78. hwnd = GetDesktopWindow();
  79. }
  80. GetWindowRect(hDlg, &me);
  81. GetWindowRect(hwnd, &parent);
  82. int meWidth = me.right - me.left,
  83. meHeight = me.bottom - me.top;
  84. int parentWidth = parent.right - parent.left,
  85. parentHeight = parent.bottom - parent.top;
  86. int widthOffset = (parentWidth - meWidth)/2,
  87. heightOffset = (parentHeight - meHeight)/2;
  88. me.left = parent.left + widthOffset;
  89. me.top = parent.top + heightOffset;
  90. SetWindowPos(hDlg,
  91. NULL,
  92. me.left,
  93. me.top,
  94. 0,
  95. 0,
  96. SWP_NOSIZE | SWP_NOZORDER);
  97. }