CDialog類是MFC對話框基類
對話框有兩類:模態對話框和非模態對話框。模態對話框在應用繼續進行之前必須關閉,非模態則不需要
CDialog重載了三個構造函數
CDialog();//缺省構造函數
CDialog(UINT nlDTemplate,CWnd*pParentWnd=NULL);//從指定的對話模板資源ID創建
CDialog(LPCTSTR lpszTemplateName,CWnd*pParentWnd=NULL);//從指定的對話框模板資源名稱創建
成員方法:
消息響應函數:
CDialogEx是CDialog的擴展類,具備基類全部功能,並根據新系統需要增加了一些界面美化功能,例如修改對話框背景顏色,標題欄顏色等。
成員方法:
class CDialog : public CWnd { DECLARE_DYNAMIC(CDialog) // Modeless construct
public: CDialog(); void Initialize(); virtual BOOL Create(LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL); virtual BOOL Create(UINT nIDTemplate, CWnd* pParentWnd = NULL); virtual BOOL CreateIndirect(LPCDLGTEMPLATE lpDialogTemplate, CWnd* pParentWnd = NULL, void* lpDialogInit = NULL); virtual BOOL CreateIndirect(HGLOBAL hDialogTemplate, CWnd* pParentWnd = NULL); // Modal construct
public: explicit CDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL); explicit CDialog(UINT nIDTemplate, CWnd* pParentWnd = NULL); BOOL InitModalIndirect(LPCDLGTEMPLATE lpDialogTemplate, CWnd* pParentWnd = NULL, void* lpDialogInit = NULL); BOOL InitModalIndirect(HGLOBAL hDialogTemplate, CWnd* pParentWnd = NULL); // Attributes
public: void MapDialogRect(LPRECT lpRect) const; void SetHelpID(UINT nIDR); // Operations
public: // modal processing
virtual INT_PTR DoModal(); // support for passing on tab control - use 'PostMessage' if needed
void NextDlgCtrl() const; void PrevDlgCtrl() const; void GotoDlgCtrl(CWnd* pWndCtrl); // default button access
void SetDefID(UINT nID); DWORD GetDefID() const; // termination
void EndDialog(int nResult); // Overridables (special message map entries)
virtual BOOL OnInitDialog(); virtual void OnSetFont(CFont* pFont); protected: virtual void OnOK(); virtual void OnCancel(); // Implementation
public: virtual ~CDialog(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif
virtual BOOL PreTranslateMessage(MSG* pMsg); virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo); virtual BOOL CheckAutoCenter(); protected: UINT m_nIDHelp; // Help ID (0 for none, see HID_BASE_RESOURCE) // parameters for 'DoModal'
LPCTSTR m_lpszTemplateName; // name or MAKEINTRESOURCE
HGLOBAL m_hDialogTemplate; // indirect (m_lpDialogTemplate == NULL)
LPCDLGTEMPLATE m_lpDialogTemplate; // indirect if (m_lpszTemplateName == NULL)
void* m_lpDialogInit; // DLGINIT resource data
CWnd* m_pParentWnd; // parent/owner window
HWND m_hWndTop; // top level parent window (may be disabled)
BOOL m_bClosedByEndDialog; // indicates that the dialog was closed by calling EndDialog method
_AFX_OCC_DIALOG_INFO* m_pOccDialogInfo; virtual BOOL SetOccDialogInfo(_AFX_OCC_DIALOG_INFO* pOccDialogInfo); virtual _AFX_OCC_DIALOG_INFO* GetOccDialogInfo(); virtual void PreInitDialog(); // implementation helpers
HWND PreModal(); void PostModal(); BOOL CreateIndirect(LPCDLGTEMPLATE lpDialogTemplate, CWnd* pParentWnd, void* lpDialogInit, HINSTANCE hInst); BOOL CreateIndirect(HGLOBAL hDialogTemplate, CWnd* pParentWnd, HINSTANCE hInst); protected: afx_msg LRESULT OnCommandHelp(WPARAM wParam, LPARAM lParam); afx_msg LRESULT OnHelpHitTest(WPARAM wParam, LPARAM lParam); afx_msg LRESULT HandleInitDialog(WPARAM, LPARAM); afx_msg void OnSetFont(CFont* pFont, BOOL bRedraw); afx_msg void OnPaint(); afx_msg BOOL OnQueryEndSession(); afx_msg void OnEndSession(BOOL bEnding); DECLARE_MESSAGE_MAP() };
BEGIN_MESSAGE_MAP(CDialog, CWnd) ON_COMMAND(IDOK, &CDialog::OnOK) ON_COMMAND(IDCANCEL, &CDialog::OnCancel) ON_MESSAGE(WM_COMMANDHELP, &CDialog::OnCommandHelp) ON_MESSAGE(WM_HELPHITTEST, &CDialog::OnHelpHitTest) ON_MESSAGE(WM_INITDIALOG, &CDialog::HandleInitDialog) ON_WM_SETFONT() ON_WM_PAINT() ON_WM_QUERYENDSESSION() ON_WM_ENDSESSION() END_MESSAGE_MAP()