西部数码网站模板,wordpress采集发布,收录优美图片,工程平台公司是什么意思Win32 Application#xff0c;没有基于MFC的类库#xff0c;而是直接调用C接口来编程。 一、弹出消息窗口 #xff08;1#xff09;最简单的#xff0c;在当前窗口中弹出新窗口。新窗口只有“YES”按钮。 int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstan…Win32 Application没有基于MFC的类库而是直接调用C接口来编程。 一、弹出消息窗口 1最简单的在当前窗口中弹出新窗口。新窗口只有“YES”按钮。 int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{MessageBox(NULL, 我的Win32程序, HelloWorld, MB_OK);return 0;
} 2获取已经打开的窗口并在该窗口中弹出新窗口而且新窗口有“YES/NO/CANCEL”按钮可以捕获该返回值。 int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{// TODO: Place code here.HWND hWnd ::FindWindow(NULL, 无标题 - 记事本);int nRet MessageBox(hWnd, 我的Win32程序, HelloWorld, MB_YESNOCANCEL|MB_ICONQUESTION);if(IDYES nRet){MessageBox(hWnd, 你点击了\是\按钮, 返回值, 0); }else if(IDNO nRet){MessageBox(hWnd, 你点击了\否\按钮, 返回值, 0); }else{MessageBox(hWnd, 你点击了\取消\按钮, 返回值, 0); }return 0;
} 二、对话框 1通过DialogBox新增一个对话框并设置对话框的消息处理回调函数MainProc接收对话框的返回值并做相应处理 int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{int nRet;nRet DialogBox(hInstance, (LPCSTR)IDD_DIALOG1, NULL, MainProc);if(IDCANCEL nRet){MessageBox(NULL, CANCEL, 返回值, 0);return -1;}return 0;
} 回调函数中通过GetDlgItemInt获取对话框的输入整型值、通过SetDlgItemInt设置对话框的输出整型值如果是字符串Int改为Text通过EndDialog关闭对话框并返回不同的返回值 BOOL CALLBACK MainProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam
)
{OutputDebugString(测试运行状态\n);if(WM_COMMAND uMsg){if(LOWORD(wParam) IDCANCEL){EndDialog(hwndDlg, IDCANCEL);return IDCANCEL;}else if(LOWORD(wParam) IDOK){int nLeft GetDlgItemInt(hwndDlg, IDC_LEFT, NULL, TRUE);int nRight GetDlgItemInt(hwndDlg, IDC_RIGHT, NULL, TRUE);int nResult nLeft nRight;SetDlgItemInt(hwndDlg, IDC_RESULT, nResult, TRUE);}}return FALSE;
} 备注 对话框的资源属性可以编辑弹出位置、对其方式、显示效果、是否可编辑等等。 CtrlD可以编辑对话框的焦点顺序。转载于:https://www.cnblogs.com/ruanchao/p/8370540.html