Windows核心编程学习一:使用DialogBoxParam显示模式对话框
2013-04-14 23:13
501 查看
注:源码为学习《Windows核心编程》的一些尝试,非原创。若能有助于一二访客,幸甚。
application can use this value to initialize dialog box controls.
但会发现,对话框不能被关闭。
其中chHANDLE_DLGMSG是原书作者对HANDLE_MSG的改进。
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. Anapplication 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()在动态库调用中创建模式对话框
- android—DatePicker 和TimePicker显示日期以及使用TimePickerDialog,DatePickerDialog来专门实现时间选择对话框
- Windows核心编程学习笔记--进程和线程的优先级
- Windows 核心编程学习笔记-第一章
- Windows窗体编程基础学习:使用 NotifyIcon 组件向任务栏添加应用程序图标
- ASP.NET 3.5核心编程学习笔记(48):ASP.NET的安全性之Windows身份验证与Passport身份验证
- Windows核心编程学习六:进程优先级组和线程优先级
- 从零开始,学习windows编程(7)--不使用CRT库的程序
- 向对话框传递数据DialogBoxParam;获取对话框返回的数据DialogBox;EndDialog;强制转换;
- windows 核心编程之 错误处理 -----学习笔记
- Windows编程 C++ DLL编程 学习笔记(一)静态链接库的创建和使用
- Windows核心编程学习笔记--第17章
- [引]Windows窗体编程基础学习: 对话框组件
- Windows核心编程学习笔记-------20章
- windows编程学习笔记(5)定时器的使用
- 一步步学习java并发编程模式之Active Object模式(五) 使用JDK的内置实现
- Socket编程创建对话框模式的项目时忘记选择 windows”套接字”的解决办法!
- 使用CImageList在Dialog对话框上显示一副位图
- Windows核心编程学习笔记--第15章