|
发表于 2020-4-7 17:30:01
|
显示全部楼层
1 添加对话框资源
2 在WinMain函数里调用DialogBox函数
3 定义对话框的消息处理函数,格式参照MSDN
4 消息映射
<<Windows核心编程>>一书里面有具体的实例
INT_PTR CALLBACK MyDlgProc( HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);//窗口函数原型声明
BOOL Dlg_OnInitDialog(HWND hwnd,HWND hwndFocus,LPARAM lParam)//消息处理(必须)
{
}
VOID Dlg_OnCommand(HWND hwnd,int id,HWND hwndCtl,UINT codeNotify)//命令消息处理
{
}
INT_PTR CALLBACK MyDlgProc( HWND hwndDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch(uMsg)
{
case WM_INITDIALOG:
return SetDlgMsgResult(hwndDlg,uMsg,HANDLE_WM_INITDIALOG( ( hwndDlg ) ,( wParam ),( lParam ),( Dlg_OnInitDialog )));
break; ////消息映射
case WM_COMMAND:
return SetDlgMsgResult(hwndDlg,uMsg,HANDLE_WM_COMMAND( ( hwndDlg ),( wParam ),( lParam ),( Dlg_OnCommand )));
break;
}
return FALSE;
}
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
DialogBox( hInstance,MAKEINTRESOURCE( IDD_DLG ) , NULL , MyDlgProc);
}
|
|