在网上看到对MessageBoxIndirect的介绍,自己试了试,可以正常运行但无论如何也显示不了图标代码比较简单,就是显示一个带图标的消息框:#include "stdafx.h"int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
char szCaption[] = "MsgBox with an icon";
char szText[] = "Who stole my icon?";
MSGBOXPARAMS msgbox;
msgbox.cbSize = sizeof(MSGBOXPARAMS);
msgbox.dwContextHelpId = 0;
//msgbox.dwLanguageId = LANG_CHINESE; //msgbox.dwLanguageId 可以不用设置
msgbox.dwStyle = MB_USERICON;
msgbox.hInstance = hInstance;
msgbox.hwndOwner = NULL;
msgbox.lpfnMsgBoxCallback = NULL;
msgbox.lpszCaption = szCaption;
msgbox.lpszIcon = "1.ico";
msgbox.lpszText = szText;
::MessageBoxIndirect(&msgbox); return 0;
}1.ico 我已加到程序的资源中,msdn中关于lpszCaption的解释为"Identifies an icon resource. This parameter can be either a null-terminated string or an integer resource identifier passed to the MAKEINTRESOURCE macro. "
还特别说到如果想额外制定显示的图标,dwStyle需设置为MB_USERICON,我都照办了,不知道为什么还是无法显示图标,请教各位了。
运行效果是在图标的位置处是空白的......
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
char szCaption[] = "MsgBox with an icon";
char szText[] = "Who stole my icon?";
MSGBOXPARAMS msgbox;
msgbox.cbSize = sizeof(MSGBOXPARAMS);
msgbox.dwContextHelpId = 0;
//msgbox.dwLanguageId = LANG_CHINESE; //msgbox.dwLanguageId 可以不用设置
msgbox.dwStyle = MB_USERICON;
msgbox.hInstance = hInstance;
msgbox.hwndOwner = NULL;
msgbox.lpfnMsgBoxCallback = NULL;
msgbox.lpszCaption = szCaption;
msgbox.lpszIcon = "1.ico";
msgbox.lpszText = szText;
::MessageBoxIndirect(&msgbox); return 0;
}1.ico 我已加到程序的资源中,msdn中关于lpszCaption的解释为"Identifies an icon resource. This parameter can be either a null-terminated string or an integer resource identifier passed to the MAKEINTRESOURCE macro. "
还特别说到如果想额外制定显示的图标,dwStyle需设置为MB_USERICON,我都照办了,不知道为什么还是无法显示图标,请教各位了。
运行效果是在图标的位置处是空白的......
msgbox.lpszCaption = MAKEINTRESOURCE(ID_ICON1);