拿下Win32非模态对话框
标签:button ddl windows color false 指定 lse cmd com
1、点击不同按钮分别创建出模态与非模态对话框子窗口,分别指定每个窗口单独的对话框窗口函数。
#include
#include
#include
#include "resource.h"
INT_PTR WINAPI DialogFuncModal(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
{
UINT ControlID = LOWORD(wParam);
UINT ControlCode = HIWORD(wParam);
if (ControlCode == BN_CLICKED)
{
if (ControlID == IDCANCEL)
{
int iRet = MessageBox(hWndDlg, _T("是否关闭对话框"), _T("标题"), MB_OKCANCEL);
if (iRet == IDOK)
{
EndDialog(hWndDlg, 0);
}
}
}
}
break;
default:
break;
}
return FALSE;
}
INT_PTR WINAPI DialogFuncUnmodal(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
{
UINT ControlID = LOWORD(wParam);
UINT ControlCode = HIWORD(wParam);
if (ControlCode == BN_CLICKED)
{
if (ControlID == IDCANCEL)
{
int iRet = MessageBox(hWndDlg, _T("是否关闭对话框"), _T("标题"), MB_OKCANCEL);
if (iRet == IDOK)
{
DestroyWindow(hWndDlg);
}
}
}
}
break;
default:
break;
}
return FALSE;
}
INT_PTR WINAPI DialogFunc(HWND hWndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
//MessageBox(hWndDlg, _T("AA"), _T("A"), NULL);
break;
case WM_COMMAND:
{
UINT ControlID = LOWORD(wParam);
UINT ControlCode = HIWORD(wParam);
if (ControlCode == BN_CLICKED)
{
if (ControlID == IDC_BUTTON1)
{
DialogBox(NULL, MAKEINTRESOURCE(IDD_DIALOG2), hWndDlg, DialogFuncModal);
}
if (ControlID == IDC_BUTTON2)
{
HWND hWndUnmodal = CreateDialog(NULL, MAKEINTRESOURCE(IDD_DIALOG2), hWndDlg, DialogFuncUnmodal);
ShowWindow(hWndUnmodal,SW_SHOW);
}
if (ControlID == IDCANCEL)
{
int iRet = MessageBox(hWndDlg, _T("是否关闭对话框"), _T("标题"), MB_OKCANCEL);
if (iRet == IDOK)
{
DestroyWindow(hWndDlg);
PostQuitMessage(1);
}
}
}
}
break;
default:
break;
}
return FALSE;
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow)
{
HWND hWndDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), NULL, DialogFunc);
ShowWindow(hWndDlg, SW_SHOW);
MSG msg = { 0 };
while (GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
拿下Win32非模态对话框
标签:button ddl windows color false 指定 lse cmd com
原文地址:https://www.cnblogs.com/SakuraQAQ/p/14352905.html
评论