概述
文章目录
- 模态对话框
- WM_INITDIALOG 对话框初始化消息
- WM_SETICON 设置窗口图标
模态对话框
DialogBox 函数(阻塞函数) 对应关闭函数 EndDialog(关闭一个模态对话框)
The DialogBox macro creates a modal dialog box from a dialog box template resource. DialogBox does not return control until the specified callback function terminates the modal dialog box by calling the EndDialog
function. The DialogBox macro uses the DialogBoxParam
function.
int DialogBox(
HINSTANCE hInstance, // handle to application instance 窗口实例
LPCTSTR lpTemplate, // identifies dialog box template 窗口ID模板
HWND hWndParent, // handle to owner window 父窗口句柄
DLGPROC lpDialogFunc // pointer to dialog box procedure 窗口处理函数
);
返回值如果函数成功,则返回值是用于终止对话框的Enddialog函数调用中的nresult参数。如果函数失败,返回值为获取扩展错误信息,请调用Getlasterror
BOOL CALLBACK DialogProc(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
The EndDialog function destroys a modal dialog box, causing the system to end any processing for the dialog box.
BOOL EndDialog(
HWND hDlg, // handle to dialog box
int nResult // value to return
);
hDlg标识要销毁的对话框。
nResult指定要从创建对话框的函数返回给应用程序的值。
添加资源
修改窗口名字
注意:
在属性中设置居中:
更改标题
将图标复制进去
在初始化消息中设置图标
case WM_INITDIALOG://对话框初始消息 对话框还没有显示出来但是对话框已经创建好了
{
//设置窗口图标
HICON hIcon1= LoadIcon(g_hIstance, MAKEINTRESOURCE(IDI_ICON1));
HICON hIcon2= LoadIcon(g_hIstance, MAKEINTRESOURCE(IDI_ICON2));
//设置图标
SendMessage(hwndDlg, WM_SETICON,ICON_BIG, (LPARAM)hIcon1);//设置大图标
SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon2);//设置小图标
SetWindowText(hwndDlg, L"这是对话框初始话消息");
break;
}
#include <Windows.h>
#include "resource.h"
HINSTANCE g_hIstance;//定义全局变量 应用程序 实例句柄
//对话框 窗口处理函数
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow )
{
g_hIstance = hInstance;
//模态对话框
//DialogBox函数 对应 :EndDialog
DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN_DLG), NULL, DialogProc);
return 0;
}
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG://对话框初始消息 对话框还没有显示出来但是对话框已经创建好了
{
//设置窗口图标
HICON hIcon= LoadIcon(g_hIstance, MAKEINTRESOURCE(IDI_ICON1));
//设置图标
SendMessage(hwndDlg, WM_SETICON,ICON_BIG, (LPARAM)hIcon);
SendMessage(hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM)hIcon);
SetWindowText(hwndDlg, L"这是对话框初始话消息");
break;
}
case WM_CLOSE://窗口关闭消息
{
if (IDNO == MessageBox(hwndDlg, L"去定要关闭嘛", L"提示", MB_YESNO))
return true;
else
EndDialog(hwndDlg, 0);
break;
}
case WM_DESTROY://窗口销毁消息
MessageBox(hwndDlg, L"WM_DESTROY消息", L"提示", MB_OK);
break;
}
return FALSE;//返回假 表示系统给我处理
//return TRUE;//返回真 表示所有 消息我们自己处理,操作系统不会给我们处理
}
WM_INITDIALOG 对话框初始化消息
WM_INITDIALOG 对话框初始化消息 对话框还没有显示出来但是对话框已经创建好了
The WM_INITDIALOG message is sent to the dialog box procedure immediately before a dialog box is displayed. Dialog box procedures typically use this message to initialize controls and carry out any other initialization tasks that affect the appearance of the dialog box.
WM_INITDIALOG
hwndFocus = (HWND) wParam; // handle of control to receive focus
lInitParam = lParam; // initialization parameter
WM_SETICON 设置窗口图标
An application sends the WM_SETICON message to associate a new large or small icon with a window. The system displays the large icon in the ALT+TAB dialog, and the small icon in the window caption.
WM_SETICON
wParam = (WPARAM) fType; // icon type
lParam = (LPARAM) (HICON) hicon; // handle to icon
最后
以上就是开朗毛巾为你收集整理的4 模态对话框和非模态对话框模态对话框WM_INITDIALOG 对话框初始化消息WM_SETICON 设置窗口图标的全部内容,希望文章能够帮你解决4 模态对话框和非模态对话框模态对话框WM_INITDIALOG 对话框初始化消息WM_SETICON 设置窗口图标所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复