![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
#include <windows.h>
/*--------------------按钮-----------------------------
#define MB_OK 0x00000000L
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
#define MB_OKCANCEL 0x00000001L
#define MB_ABORTRETRYIGNORE 0x00000002L
#define MB_YESNOCANCEL 0x00000003L
#define MB_YESNO 0x00000004L
#define MB_RETRYCANCEL 0x00000005L
------------------------------------------------------*/
/*---------------------默认按钮--------------------------------
#define MB_DEFBUTTON1 0x00000000L
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
#define MB_DEFBUTTON2 0x00000100L
#define MB_DEFBUTTON3 0x00000200L
#define MB_DEFBUTTON4 0x00000300L
-------------------------------------------------------------*/
/*-----------------------图标---------------------------------------
#define MB_ICONHAND 0x00000010L
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
#define MB_ICONQUESTION 0x00000020L
#define MB_ICONEXCLAMATION 0x00000030L
#define MB_ICONASTERISK 0x00000040L
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
or
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
#define MB_ICONWARNING MB_ICONEXCLAMATION
#define MB_ICONERROR MB_ICONHAND
#define MB_ICONINFORMATION MB_ICONASTERISK
#define MB_ICONSTOP MB_ICONHAND
------------------------------------------------------------------*/
/*-----------------------------------------------------------------
0x00000001 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000001
0x00000002 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000010
0x00000003 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000011
0x00000004 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000100
0x00000005 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000101
0x00000010 00000000 00000000 00000000 00000000 00000000 00000000 00000001 00000000
0x00000020 00000000 00000000 00000000 00000000 00000000 00000000 00000010 00000000
0x00000030 00000000 00000000 00000000 00000000 00000000 00000000 00000011 00000000
0x00000040 00000000 00000000 00000000 00000000 00000000 00000000 00000100 00000000
0x00000100 00000000 00000000 00000000 00000000 00000000 00000001 00000000 00000000
0x00000200 00000000 00000000 00000000 00000000 00000000 00000010 00000000 00000000
0x00000300 00000000 00000000 00000000 00000000 00000000 00000011 00000000 00000000
0x00000400 00000000 00000000 00000000 00000000 00000000 00000100 00000000 00000000
-------------------------------------------------------------------*/
#define MAX_MESSAGEBOX_BUTTON_NUM 6
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
#define MAX_MESSAGEBOX_DEFAULT_BUTTOM_NUM 4
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
#define MAX_MESSAGEBOX_ICON_NUM 4
UINT MessageBoxButton[] =
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
{
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
MB_OK,
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
MB_OKCANCEL,
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
MB_ABORTRETRYIGNORE,
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
MB_YESNOCANCEL,
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
MB_YESNO,
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
MB_RETRYCANCEL
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
};
UINT MessageBoxDefaultButton[] =
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
{
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
MB_DEFBUTTON1,
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
MB_DEFBUTTON2,
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
MB_DEFBUTTON3,
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
MB_DEFBUTTON4
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
};
UINT MessageBoxIcon[] =
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
{
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
MB_ICONHAND,
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
MB_ICONQUESTION,
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
MB_ICONEXCLAMATION,
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
MB_ICONASTERISK
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
};
/*共有的情况总数为6*4*4 = 96种*/
int MyMessageBox(HWND hWnd,LPCTSTR lpText,LPCTSTR lpCaption,UINT UType)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
{
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
UINT myType = 0;
for (
int i = 0; i < MAX_MESSAGEBOX_BUTTON_NUM; ++i)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
{
/*这里判断出来了按钮风格*/
if (MessageBoxButton[i] == (UType & 0xF))
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
{
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
myType = MessageBoxButton[i];
break;
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
}
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
}
for (
int j = 0; j < MAX_MESSAGEBOX_DEFAULT_BUTTOM_NUM; ++j)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
{
/*这里判断出来了默认按钮*/
if (MessageBoxDefaultButton[j] == (UType & 0xF00))
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
{
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
myType |= MessageBoxDefaultButton[j];
break;
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
}
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
}
for (
int k = 0; k < MAX_MESSAGEBOX_ICON_NUM; ++k)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
{
/*这里判断出来了显示图标*/
if (MessageBoxIcon[k] == (UType & 0xF0))
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
{
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
myType |= MessageBoxIcon[k];
break;
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
}
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
}
return MessageBox(hWnd,lpText,lpCaption,myType);
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
}
int APIENTRY WinMain(HINSTANCE hInstance,
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
HINSTANCE hPrevInstance,
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
LPSTR lpCmdLine,
int nCmdShow)
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
{
// TODO: Place code here.
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
MyMessageBox(NULL,(
"我要努力!!!"), (
"ihome"), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2);
return 0;
![InBlock.gif](p_w_picpaths/editer/InBlock.gif)
}
转载于:https://blog.51cto.com/ihome/395019