CreateDialog()函数
函数功能:CreateDialog宏从一个对话框模板资源创建一个无模式的对话框,CreateDiaog宏使用CreateDialogParam函数。
函数原型:HWND CreateDialog(HINSTANCE hlnstance,LPCTSTR lpTemplate,HWND hWndParent,DLGPROC IpDialogFunc);
- 新建一个windows空项目
- 添加一个main.cpp
- 添加一个dialog资源文件
#include#include "resource.h" INT_PTR CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CLOSE: PostQuitMessage(0); break; case WM_COMMAND: { if (LOWORD(wParam) == IDOK) { TCHAR szUser[256] = { 0 }; GetDlgItemText(hwnd, IDC_EDIT_USER, szUser, 256); TCHAR szPwd[256] = { 0 }; GetDlgItemText(hwnd, IDC_EDIT_PWD, szPwd, 256); if (wcscmp(szUser, szPwd) == 0) { MessageBox(GetParent(hwnd), L"登录成功", L"提示", MB_OK); } else { MessageBox(GetParent(hwnd), L"帐号或密码错误", L"提示", MB_OK); } } } break; default: return FALSE; //消息未处理交给windows默认处理程序处理 } return TRUE; //消息已经被处理 } int __stdcall WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nShowCmd) { HWND hwnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DIALOG), NULL, dlgProc); ShowWindow(hwnd, SW_SHOW); MSG msg; while (GetMessage(&msg, 0, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return 0; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)