关闭模式对话框 EndDialog

来源:互联网 发布:知乎 人工智能 编辑:程序博客网 时间:2024/05/18 00:02
模式对话框的关闭


BOOL EndDialog(
  HWND hDlg,
  INT_PTR nResult
)


该函数能销毁对话框,并且nResult指明DialogBox的返回值






#include <Windows.h>
#include "resource.h"


// 窗口处理函数
HINSTANCE g_hInstance = 0;
int CALLBACK DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_SYSCOMMAND:
if (wParam == SC_CLOSE)
EndDialog(hwnd, 1001);
break;
default:
break;
}


return false;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case ID_MODAL:
{
int ret = DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, DlgProc);
if (ret = 1001)
{
MessageBox(hwnd, L"关闭成功", L"infor", MB_OK);
}
}
break;
case ID_NOMODAL:
break;
}
}
break;
case WM_DESTROY:
PostQuitMessage(0);
default:
break;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
// 窗口注册函数
void Register(LPCWSTR lpClassName, WNDPROC wndproc)
{
WNDCLASSEX wcx = { 0 };


wcx.cbClsExtra = 0;
wcx.cbSize = sizeof(wcx);
wcx.cbWndExtra = 0;
wcx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcx.hCursor = LoadCursor(g_hInstance, IDC_ARROW);
wcx.hIcon = NULL;
wcx.hIconSm = NULL;
wcx.hInstance = g_hInstance;
wcx.lpfnWndProc = wndproc;
wcx.lpszClassName = lpClassName;
wcx.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
wcx.style = CS_HREDRAW | CS_VREDRAW;


RegisterClassEx(&wcx);
}


HWND CreateMain(LPCWSTR lpClassName)
{
HWND hwnd = CreateWindowEx(0, lpClassName, L"LEARN", WS_OVERLAPPEDWINDOW, 100, 100, 700, 500, NULL, NULL, g_hInstance, NULL);
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
return hwnd;
}


int exec()
{
MSG msg = { 0 };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
g_hInstance = hInstance;
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
TCHAR szAppName[] = L"MAIN";
Register(szAppName, WndProc);
CreateMain(szAppName);
return exec();
}
0 0
原创粉丝点击