MFC定义了一个应用程序基类CWinApp,所有基于MFC的应用程序都会继承这个类。
class CmfctestApp : public CWinApp
{
public:
CmfctestApp();
// 重写
public:
virtual BOOL InitInstance();
// 实现
DECLARE_MESSAGE_MAP()
};
添加基于CDialogEx类的CMyModalDialog和CMyNoModalDialog类。
MFC实现模态对话框
CMyModalDialog dl;
dl.DoModal();
MFC实现非模态对话框
CMyNoModalDialog* pDlg = new CMyNoModalDialog;
pDlg->Create(IDD_NOMODAL_DIALOG,this);
pDlg->ShowWindow(SW_SHOW);
win32API实现模态对话框
int DialogBox(
HINSTANCE hInstance, // handle to application instance
LPCTSTR lpTemplate, // identifies dialog box template
HWND hWndParent, // handle to owner window
DLGPROC lpDialogFunc // pointer to dialog box procedure
);
int DialogBoxParam(
HINSTANCE hInstance, // handle to application instance
LPCTSTR lpTemplateName, // identifies dialog box template
HWND hWndParent, // handle to owner window
DLGPROC lpDialogFunc, // pointer to dialog box procedure
LPARAM dwInitParam // initialization value
);
HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);
DialogBox(hInstance,MAKEINTRESOURCE(IDD_API_DIALOG),this->m_hWnd,ApiDialog);
win32API实现非模态对话框
HWND CreateDialog(
HINSTANCE hInstance, // handle to application instance
LPCTSTR lpTemplate, // identifies dialog box template name
HWND hWndParent, // handle to owner window
DLGPROC lpDialogFunc // pointer to dialog box procedure
);
HWND CreateDialogParam(
HINSTANCE hInstance, // handle to application instance
LPCTSTR lpTemplateName, // identifies dialog box template
HWND hWndParent, // handle to owner window
DLGPROC lpDialogFunc, // pointer to dialog box procedure
LPARAM dwInitParam // initialization value
);
HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);
HWND hDlg = CreateDialog(hInstance,MAKEINTRESOURCE(IDD_NOMODAL_DIALOG),NULL,ApiDialog);
::ShowWindow(hDlg,SW_SHOW);
窗口回调函数:ApiDialog
BOOL CALLBACK ApiDialog (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_INITDIALOG:
{
}
return (TRUE);
case WM_CLOSE:
{
EndDialog(hDlg,0);
}
return (TRUE);
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDCANCEL:
{
SendMessage(hDlg, WM_CLOSE, 0, 0);
}
return (TRUE);
case IDOK:
{
}
return (TRUE);
}
return (FALSE);
}
return (FALSE);
}
已经有(0)位网友发表了评论,你也评一评吧!
原创文章如转载,请注明:转载自Eddy Blog
原文地址:http://www.rrgod.com/program/434.html 欢迎订阅Eddy Blog。