Windows核心编程学习一:使用DialogBoxParam显示模式对话框
生活随笔
收集整理的這篇文章主要介紹了
Windows核心编程学习一:使用DialogBoxParam显示模式对话框
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
注:源碼為學習《Windows核心編程》的一些嘗試,非原創。若能有助于一二訪客,幸甚。
1.DialogBoxParam
This function creates a modal dialog box from a dialog box template resource. Before displaying the dialog box, the function passes an application-defined value to the dialog box procedure as thelParam?parameter of the WM_INITDIALOG message. An application can use this value to initialize dialog box controls.
int DialogBoxParam( HINSTANCE hInstance, LPCTSTR lpTemplateName, HWND hWndParent, DLGPROC lpDialogFunc, PARAM dwInitParam );2.最簡單的嘗試
/******************************************************************************** File: FirstTry.cpp* Author: guzhoudiaoke@126.com* Time: 2013-04-14* 描述: 主要嘗試使用DialogBoxParam函數顯式一個對話框*******************************************************************************/#include <Windows.h> #include <Windowsx.h> #include <tchar.h> #include "Resource.h"// 對話框過程函數 INT_PTR WINAPI Dlg_Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {return FALSE; }int WINAPI _tWinMain(HINSTANCE hinstExe, HINSTANCE, PTSTR pszCmdLine, int) {DialogBoxParam(hinstExe, MAKEINTRESOURCE(IDD_FIRSTTRY), NULL, Dlg_Proc, _ttoi(pszCmdLine));return 0; } 運行結果:但會發現,對話框不能被關閉。
3.對話框過程函數
/******************************************************************************** File: FirstTry.cpp* Author: guzhoudiaoke@126.com* Time: 2013-04-14* 描述: 主要嘗試使用DialogBoxParam函數顯式一個對話框*******************************************************************************/#include <Windows.h> #include <Windowsx.h> #include <tchar.h> #include "Resource.h"/* SetDlgMsgResult This macro maps to the SetWindowLong function.* SetWindowLong changes an attribute of the specified window, also sets a 32-bit (LONG) * value at the specified offset into the extra window memory of a window.* The normal HANDLE_MSG macro in WindowsX.h does not work properly for dialog* boxes because DlgProc returns a BOOL instead of an LRESULT (likeWndProcs). * This chHANDLE_DLGMSG macro corrects the problem.*/ #define chHANDLE_DLGMSG(hWnd, message, fn) \case (message): return (SetDlgMsgResult(hWnd, uMsg, \HANDLE_##message((hWnd), (wParam), (lParam), (fn))))void Dlg_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) {switch (id) {case IDCANCEL:EndDialog(hwnd, id);break;} }// 對話框過程函數 INT_PTR WINAPI Dlg_Proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {switch (uMsg) {chHANDLE_DLGMSG(hwnd, WM_COMMAND, Dlg_OnCommand);}return FALSE; }int WINAPI _tWinMain(HINSTANCE hinstExe, HINSTANCE, PTSTR pszCmdLine, int) {DialogBoxParam(hinstExe, MAKEINTRESOURCE(IDD_FIRSTTRY), NULL, Dlg_Proc, _ttoi(pszCmdLine));return 0; }其中chHANDLE_DLGMSG是原書作者對HANDLE_MSG的改進。
總結
以上是生活随笔為你收集整理的Windows核心编程学习一:使用DialogBoxParam显示模式对话框的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微型计算机控制技术小论文,微型计算机控制
- 下一篇: Java实现人力资源管理系统