⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ppmessagebox.cpp

📁 基于ARM平台的控制系统,自己带有MINIGUI,可以直接在VC下运行界面演示程序
💻 CPP
字号:
#include "ppMessageBox.h"

#include "eeb.h"

#if _USE_GUI == 1
/*
*/
//#define UGMB_OK_TEXT			" 确 定 "
#define UGMB_CANCEL_TEXT		" 取 消 "
#define UGMB_YES_TEXT			" 是 "
#define UGMB_NO_TEXT			" 否 "

#define UGMB_OK_TEXT GetStringResource(strMSGBOX_OK)

#define UGMB_BUTTON_MARGIN	10
#define UGMB_MSGBOX_MARGIN	18
#define UGMB_ICON_WIDTH		32
#define UGMB_ICON_HEIGHT	32

#define UGMB_HEIGHT			120


NANAMessageBox::NANAMessageBox()
{
	w_nIcon = 0;
	memset(w_strCaption, 0x00, UGMB_MAX_TITLE_CHARS*sizeof(char));
	memset(w_strText, 0x00, UGMB_MAX_TEXT_CHARS*sizeof(char));
	w_nStyle = 0;
	w_pParentWnd = 0;

	w_nWidth = 0;
	w_nHeight = 0;
	w_nStartX = 0;
	w_nStartY = 0;
	w_nButtonWidth1 = 0;
	w_nButtonWidth2 = 0;
}

NANAMessageBox::~NANAMessageBox()
{

}

void NANAMessageBox::Show(NANAWnd * pParentWnd,const char* strCaption,const char* strText,int nStyle,int nIcon)
{
	CreateWnd(pParentWnd,strCaption,strText,nStyle,nIcon);
}

void NANAMessageBox::Close()
{
	CloseWindow();
}

int NANAMessageBox::CreateWnd(
					NANAWnd * pParentWnd,
					const char* strCaption,
					const char* strText,
					int nStyle,
					int nIcon)
{
	int nCaptionWidth;
	int nTextWidth;
	int nButtonWidth;
	int nWidth;
	int nHeight;
	int nStartx;
	int nStarty;
	int nButtonWidth1;
	int nButtonWidth2;

	strcpy(w_strCaption, strCaption);
	strcpy(w_strText, strText);
	w_nIcon = nIcon;
	w_nStyle = nStyle;
	w_pParentWnd = pParentWnd;

	if(strlen(w_strCaption) >= (UGMB_MAX_TITLE_CHARS -1))
	{
		return 0 ;
	}

	if(strlen(w_strText) >= (UGMB_MAX_TEXT_CHARS -1))
	{
		return 0;
	}
	
	nCaptionWidth=GetTextWidth(w_strCaption, &NANA_FONT16, -1);
			
	nTextWidth=GetTextWidth(w_strText, &NANA_FONT12, -1);
	
	nWidth = nCaptionWidth>nTextWidth ? nCaptionWidth : nTextWidth;
	
	switch(w_nStyle)
	{
		case UGMB_OK:
			nButtonWidth1 = GetTextWidth(UGMB_OK_TEXT, &NANA_FONT12, -1) + UGMB_BUTTON_MARGIN;
			nButtonWidth = nButtonWidth1;
		break;
		case UGMB_YESNO:
			nButtonWidth1 = GetTextWidth(UGMB_YES_TEXT,&NANA_FONT12,-1) + UGMB_BUTTON_MARGIN;
			nButtonWidth2 = GetTextWidth(UGMB_NO_TEXT,&NANA_FONT12,-1) + UGMB_BUTTON_MARGIN;
			nButtonWidth = nButtonWidth1 + nButtonWidth2 + UGMB_MSGBOX_MARGIN;
		break;
		case UGMB_OKCANCEL:
			nButtonWidth1 = GetTextWidth(UGMB_OK_TEXT,&NANA_FONT12,-1) + UGMB_BUTTON_MARGIN;
			nButtonWidth2 = GetTextWidth(UGMB_CANCEL_TEXT,&NANA_FONT12,-1) + UGMB_BUTTON_MARGIN;
			nButtonWidth = nButtonWidth1 + nButtonWidth2 + UGMB_MSGBOX_MARGIN;
		break;
	}
	
	nWidth = (nWidth > nButtonWidth) ? nWidth : nButtonWidth;
	nWidth += UGMB_MSGBOX_MARGIN;
	nWidth += UGMB_ICON_WIDTH+5;
	
	nHeight = UGMB_HEIGHT;
	nStartx = (SCREEN_WIDTH-nWidth)/2;
	nStarty = (SCREEN_HEIGHT-nHeight)/2;

	w_nWidth = nWidth;
	w_nHeight = nHeight;
	w_nStartX = nStartx;
	w_nStartY = nStarty;
	w_nButtonWidth1 = nButtonWidth1;
	w_nButtonWidth2 = nButtonWidth2;

	//创建窗体
	if(NANAWnd::CreateWnd(NULL, nStartx, nStarty,  nWidth,  nHeight))
	{
		CaptureMouse();
		return 1;
	}
	return 0;
}
void NANAMessageBox::OnClose()
{
	switch(w_nStyle)
	{
		case UGMB_OK:
			w_ButtonOK.CloseWindow();
		break;
		
		case UGMB_YESNO:
			w_ButtonOK.CloseWindow();
			w_ButtonCancel.CloseWindow();
		break;
		case UGMB_OKCANCEL:
			w_ButtonOK.CloseWindow();
			w_ButtonCancel.CloseWindow();
		break;
		default:
			break;
	}
	ReleaseMouse();
}
void NANAMessageBox::OnCreate()
{
	switch(w_nStyle)
	{
		case UGMB_OK:
			w_ButtonOK.CreateWnd(this,
				w_nStartX+(w_nWidth-w_nButtonWidth1)/2 ,
				w_nStartY+w_nHeight-40, 
				w_nButtonWidth1,
				BUTTON_HEIGHT_16);
			w_ButtonOK.SetCaption(UGMB_OK_TEXT);
		break;
		
		case UGMB_YESNO:
			w_ButtonOK.CreateWnd(this,
				w_nStartX+(w_nWidth-w_nButtonWidth1-w_nButtonWidth2)/3,
				w_nStartY+w_nHeight-40, 
				w_nButtonWidth1,
				BUTTON_HEIGHT_16);
			w_ButtonOK.SetCaption(UGMB_YES_TEXT);


			w_ButtonCancel.CreateWnd(this,
				w_nStartX+w_nWidth-(w_nWidth-w_nButtonWidth1-w_nButtonWidth2)/3-w_nButtonWidth2,
				w_nStartY+w_nHeight-40, 
				w_nButtonWidth2,
				BUTTON_HEIGHT_16);
			w_ButtonCancel.SetCaption(UGMB_NO_TEXT);
		break;
		
		case UGMB_OKCANCEL:
			w_ButtonOK.CreateWnd(this,
				w_nStartX+(w_nWidth-w_nButtonWidth1-w_nButtonWidth2)/3,
				w_nStartY+w_nHeight-40, 
				w_nButtonWidth1,
				BUTTON_HEIGHT_16);
			w_ButtonOK.SetCaption(UGMB_OK_TEXT);


			w_ButtonCancel.CreateWnd(this,
				w_nStartX+w_nWidth-(w_nWidth-w_nButtonWidth1-w_nButtonWidth2)/3-w_nButtonWidth2,
				w_nStartY+w_nHeight-40, 
				w_nButtonWidth2,
				BUTTON_HEIGHT_16);
			w_ButtonCancel.SetCaption(UGMB_CANCEL_TEXT);
		break;

		default:
			break;
	}	
}
	
void NANAMessageBox::OnPaint()
{
	NANA_FONT font;
	font = &NANA_FONT16;
	
	NANARect rc;
	GetWindowRect(&rc);
	RoundWindowFrame(rc.w_nX1, rc.w_nY1, rc.w_nX2, rc.w_nY2,1, 30);
	
	if( 0 <= w_nIcon )
	{
		// 合法图标编号
		DrawICON(w_nIcon,rc.w_nX1+UGMB_MSGBOX_MARGIN/2,rc.w_nY1+35,0);
	}
	
	TextPrint((w_strCaption),
			rc.w_nX1 + UGMB_MSGBOX_MARGIN/2,
			rc.w_nY1 + 6,
			&NANA_FONT16,
			1);
	
//	DrawHorizontalLine(rc.w_nX1, rc.w_nY1+24+6, rc.w_nX2-rc.w_nX1, 1);
	TextPrint((w_strText),
			rc.w_nX1 + UGMB_MSGBOX_MARGIN/2+UGMB_ICON_WIDTH+5,
			rc.w_nY1 + 46,
			&NANA_FONT12,
			0);
}
	
void NANAMessageBox::OnKey(int nKeyCode,int bKeyDown)
{
	if (bKeyDown == MSGCODE_KEY_DOWN)
	{
		switch(nKeyCode)
		{
			case UGMB_KEY_OK:
				w_ButtonOK.SetPress(1);
			break;
			case UGMB_KEY_CANCEL:
				if(w_nStyle != UGMB_OK)
				{
					w_ButtonCancel.SetPress(1);
				}
			break;
		}
	}
	else if(bKeyDown == MSGCODE_KEY_UP)
	{
		switch(nKeyCode)
		{
			case UGMB_KEY_OK:
				w_ButtonOK.SetPress(0);
				NotifyWindow(w_pParentWnd,UGNC_MSGBOX,UGMB_NOTIFY_OK,0);
				Close();
				break;
			case UGMB_KEY_CANCEL:
				if(w_nStyle != UGMB_OK)
				{
					w_ButtonCancel.SetPress(0);
					NotifyWindow(w_pParentWnd,UGNC_MSGBOX,UGMB_NOTIFY_CANCEL,0);
					Close();
				}
				break;
			default:
				break;
		}
	}
	else
	{
	}
}
void NANAMessageBox::OnNotify(NANAWnd *pSrcWnd,int nMessageCode,int nParam1,int nParam2)
{
	if(UGNC_CLICK == nMessageCode)
	{
		if(pSrcWnd == &w_ButtonOK)
		{
			NotifyWindow(w_pParentWnd,UGNC_MSGBOX,UGMB_NOTIFY_OK,0);
			Close();
		}else
			if(pSrcWnd == &w_ButtonCancel)
			{
				if(w_nStyle != UGMB_OK)
				{
					NotifyWindow(w_pParentWnd,UGNC_MSGBOX,UGMB_NOTIFY_CANCEL,0);
					Close();
				}
			}
	}
}
void NANAMessageBox::OnTimer(NANATimer * pSrc)
{

}

void NANAMessageBox::OnDefault()
{

}


#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -