michael@0: // Windows/Control/Dialog.cpp michael@0: michael@0: #include "StdAfx.h" michael@0: michael@0: #ifndef _UNICODE michael@0: #include "Common/StringConvert.h" michael@0: #endif michael@0: #include "Windows/Control/Dialog.h" michael@0: michael@0: extern HINSTANCE g_hInstance; michael@0: #ifndef _UNICODE michael@0: extern bool g_IsNT; michael@0: #endif michael@0: michael@0: namespace NWindows { michael@0: namespace NControl { michael@0: michael@0: static INT_PTR APIENTRY DialogProcedure(HWND dialogHWND, UINT message, michael@0: WPARAM wParam, LPARAM lParam) michael@0: { michael@0: CWindow dialogTmp(dialogHWND); michael@0: if (message == WM_INITDIALOG) michael@0: dialogTmp.SetUserDataLongPtr(lParam); michael@0: CDialog *dialog = (CDialog *)(dialogTmp.GetUserDataLongPtr()); michael@0: if (dialog == NULL) michael@0: return FALSE; michael@0: if (message == WM_INITDIALOG) michael@0: dialog->Attach(dialogHWND); michael@0: michael@0: return BoolToBOOL(dialog->OnMessage(message, wParam, lParam)); michael@0: } michael@0: michael@0: bool CDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam) michael@0: { michael@0: switch (message) michael@0: { michael@0: case WM_INITDIALOG: michael@0: return OnInit(); michael@0: case WM_COMMAND: michael@0: return OnCommand(wParam, lParam); michael@0: case WM_NOTIFY: michael@0: return OnNotify(wParam, (LPNMHDR) lParam); michael@0: case WM_HELP: michael@0: { michael@0: OnHelp((LPHELPINFO)lParam); michael@0: return true; michael@0: } michael@0: case WM_TIMER: michael@0: { michael@0: return OnTimer(wParam, lParam); michael@0: } michael@0: default: michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: bool CDialog::OnCommand(WPARAM wParam, LPARAM lParam) michael@0: { michael@0: return OnCommand(HIWORD(wParam), LOWORD(wParam), lParam); michael@0: } michael@0: michael@0: bool CDialog::OnCommand(int code, int itemID, LPARAM lParam) michael@0: { michael@0: if (code == BN_CLICKED) michael@0: return OnButtonClicked(itemID, (HWND)lParam); michael@0: return false; michael@0: } michael@0: michael@0: bool CDialog::OnButtonClicked(int buttonID, HWND buttonHWND) michael@0: { michael@0: switch(buttonID) michael@0: { michael@0: case IDOK: michael@0: OnOK(); michael@0: break; michael@0: case IDCANCEL: michael@0: OnCancel(); michael@0: break; michael@0: case IDHELP: michael@0: OnHelp(); michael@0: break; michael@0: default: michael@0: return false; michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: bool CModelessDialog::Create(LPCTSTR templateName, HWND parentWindow) michael@0: { michael@0: HWND aHWND = CreateDialogParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this); michael@0: if (aHWND == 0) michael@0: return false; michael@0: Attach(aHWND); michael@0: return true; michael@0: } michael@0: michael@0: INT_PTR CModalDialog::Create(LPCTSTR templateName, HWND parentWindow) michael@0: { michael@0: return DialogBoxParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this); michael@0: } michael@0: michael@0: #ifndef _UNICODE michael@0: michael@0: bool CModelessDialog::Create(LPCWSTR templateName, HWND parentWindow) michael@0: { michael@0: HWND aHWND; michael@0: if (g_IsNT) michael@0: aHWND = CreateDialogParamW(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this); michael@0: else michael@0: { michael@0: AString name; michael@0: LPCSTR templateNameA; michael@0: if (IS_INTRESOURCE(templateName)) michael@0: templateNameA = (LPCSTR)templateName; michael@0: else michael@0: { michael@0: name = GetSystemString(templateName); michael@0: templateNameA = name; michael@0: } michael@0: aHWND = CreateDialogParamA(g_hInstance, templateNameA, parentWindow, DialogProcedure, (LPARAM)this); michael@0: } michael@0: if (aHWND == 0) michael@0: return false; michael@0: Attach(aHWND); michael@0: return true; michael@0: } michael@0: michael@0: INT_PTR CModalDialog::Create(LPCWSTR templateName, HWND parentWindow) michael@0: { michael@0: if (g_IsNT) michael@0: return DialogBoxParamW(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this); michael@0: AString name; michael@0: LPCSTR templateNameA; michael@0: if (IS_INTRESOURCE(templateName)) michael@0: templateNameA = (LPCSTR)templateName; michael@0: else michael@0: { michael@0: name = GetSystemString(templateName); michael@0: templateNameA = name; michael@0: } michael@0: return DialogBoxParamA(g_hInstance, templateNameA, parentWindow, DialogProcedure, (LPARAM)this); michael@0: } michael@0: #endif michael@0: michael@0: }}