www.pudn.com > mir3.rar > MirMsgBox.cpp


#include "stdafx.h" 
 
#define WRITESTRLENTH	50 
 
 
CMirMsgBox::CMirMsgBox():CMsgBox()	// Constructor 
{ 
	m_xBoxPos.x = 0; 
	m_xBoxPos.y = 0; 
	m_nImgIndex = 0; 
} 
 
BOOL CMirMsgBox::Load(CWHWilImageData* pxBtnImage=NULL) 
{ 
	if(pxBtnImage!=NULL) 
	{ 
		// Init Button; 
		m_xMsgBtn[0].CreateGameBtn(pxBtnImage,241,243,0,0);	// OK 
		m_xMsgBtn[1].CreateGameBtn(pxBtnImage,244,246,0,0);	// YES 
		m_xMsgBtn[2].CreateGameBtn(pxBtnImage,247,249,0,0);	// NO 
		m_xMsgBtn[3].CreateGameBtn(pxBtnImage,250,252,0,0);	// Cancle 
		m_pxBtnImage = pxBtnImage; 
		m_bSet = TRUE; 
	} 
	else 
	{ 
		m_bSet = FALSE; 
	} 
	return m_bSet; 
} 
 
CMirMsgBox::~CMirMsgBox()	// Destructor 
{ 
} 
 
// Function 
/* 
#define MSG_BTN_OK				1 
#define MSG_BTN_YESNO			2 
#define MSG_BTN_YESNOCANCLE		4 
#define MSG_EDITEXIST			128 
*/ 
 
BOOL CMirMsgBox::ShowMessageBox(CHAR* szMsg,INT nType) // Show	Message box with Initialization 
{ 
	return ShowMessageBox(szMsg,nType,239); 
} 
 
BOOL CMirMsgBox::ShowMessageBox(CHAR* szMsg,INT nType,INT nImgIndex) // Show	Message box with Initialization 
{ 
	INT Lenth; 
	if(!m_bActive) 
	{ 
		if(SetBoxImage(nImgIndex,nType)) 
		{ 
			if(CMsgBox::ShowMessageBox(szMsg,nType)) 
			{ 
				// m_xMsg¿¡´Ù String  
				m_xMsg.ClearAllNodes(); 
				StringDivideLen(WRITESTRLENTH,Lenth, m_szMsg,&m_xMsg); 
 
				// Text Setting 
 
				// Button Setting 
				switch(m_nType) 
				{ 
				case MSG_BTN_YESNO: 
				case MSG_BTN_YESNO|MSG_EDITEXIST: 
					{ 
						m_nStart=1; 
						m_nEnd = 3; 
 
						m_xMsgBtn[1].ChangeRect(m_xBoxPos.x+78,m_xBoxPos.y+134); 
						m_xMsgBtn[2].ChangeRect(m_xBoxPos.x+210,m_xBoxPos.y+134); 
 
						break; 
					} 
				case MSG_BTN_YESNOCANCLE: 
				case MSG_BTN_YESNOCANCLE|MSG_EDITEXIST: 
					{ 
						m_nStart=1; 
						m_nEnd = 4; 
 
						m_xMsgBtn[1].ChangeRect(m_xBoxPos.x+54,m_xBoxPos.y+134); 
						m_xMsgBtn[2].ChangeRect(m_xBoxPos.x+144,m_xBoxPos.y+134); 
						m_xMsgBtn[3].ChangeRect(m_xBoxPos.x+234,m_xBoxPos.y+134); 
						break; 
					} 
				case MSG_BTN_OK: 
					{ 
						m_nStart=0; 
						m_nEnd = 1; 
 
						m_xMsgBtn[0].ChangeRect(m_xBoxPos.x+144,m_xBoxPos.y+134); 
						break; 
					} 
				case MSG_BTN_OK|MSG_EDITEXIST: 
				default: 
					{ 
						m_nStart=0; 
						m_nEnd = 1; 
 
						m_xMsgBtn[0].ChangeRect(m_xBoxPos.x+260,m_xBoxPos.y+134); 
						break; 
					} 
				} 
			} 
			else 
			{ 
				m_bActive = FALSE; 
			} 
		} 
		else 
		{ 
			m_bActive = FALSE; 
			m_bInited = FALSE; 
		} 
	} 
	return m_bActive; 
} 
 
BOOL CMirMsgBox::SetBoxImage(INT nImageIndex,INT nType) 
{ 
	POINT xSize,xPos; 
	if(m_bSet) 
	{ 
		if((nType&MSG_EDITEXIST)==MSG_EDITEXIST) 
		{ 
			m_pxBtnImage->NewSetIndex(nImageIndex+1); 
		} 
		else 
		{ 
			m_pxBtnImage->NewSetIndex(nImageIndex); 
		} 
		m_wpData = (WORD*)m_pxBtnImage->m_pbCurrImage; 
		m_shWidth = m_pxBtnImage->m_lpstNewCurrWilImageInfo->shWidth; 
		m_shHeight = m_pxBtnImage->m_lpstNewCurrWilImageInfo->shHeight; 
		xSize.x = g_xMainWnd.m_rcWindow.right - g_xMainWnd.m_rcWindow.left; 
		xSize.y = g_xMainWnd.m_rcWindow.bottom - g_xMainWnd.m_rcWindow.top; 
		xPos.x = (xSize.x - m_shWidth)/2; 
		xPos.y = (xSize.y - m_shHeight*2)/2; 
		m_xBoxPos = xPos; 
	} 
	return m_bSet; 
} 
 
BOOL CMirMsgBox::HideMessageBox(VOID)							// Hide Message box 
{ 
	m_bActive = FALSE; 
	return FALSE; 
} 
 
BOOL CMirMsgBox::DestoryMessageBox(VOID)						// DestoryMessage box 
{ 
	m_bActive = FALSE; 
	m_bInited = FALSE; 
	m_bSet = FALSE; 
	m_xMsg.ClearAllNodes(); 
	return FALSE; 
} 
 
// Message Process 
HRESULT CMirMsgBox::OnButtonDown(POINT tpMouse)		// Button Down 
{ 
	HRESULT hResult=0; 
	for(int i = m_nStart; i< m_nEnd; i++) 
	{ 
		m_xMsgBtn[i].OnLButtonDown(tpMouse); 
	} 
	return hResult; 
} 
 
HRESULT	CMirMsgBox::OnButtonUp(POINT tpMouse)			// Button Up 
{ 
	HRESULT hResult=0; 
	for(int i = m_nStart; i< m_nEnd; i++) 
	{ 
		if(m_xMsgBtn[i].OnLButtonUp(tpMouse)) 
		{ 
			hResult =(HRESULT)pow(2,i); 
		} 
	} 
	if(hResult!=0) 
	{ 
		hResult = hResult | ((m_nType&MSG_EDITEXIST)==MSG_EDITEXIST ? HAVE_EDITOBOX:0); 
	} 
	return hResult; 
} 
 
BOOL CMirMsgBox::StringDivideLen(INT nDivideLen, INT& nDividedLine, CHAR* szSrc,CDLList* m_pxpStr) 
{ 
	CHAR szTmpCheck[MAX_PATH]; 
	CHAR szResult[MAX_PATH]; 
	 
	nDividedLine = 1; 
 
	INT nStartLen	= 0; 
	INT nEndLen		= 0; 
	INT nResultLen	= 0; 
	INT nWordCheck	= 0; 
 
	if ( szSrc[0] != NULL ) 
	{ 
		ZeroMemory(szResult,MAX_PATH); 
 
		for ( INT nCnt = 0; nCnt < (INT)strlen(szSrc); nCnt++) 
		{ 
			ZeroMemory(szTmpCheck, MAX_PATH); 
			nEndLen = nCnt+1; 
 
			// ÇöÀçºÎºÐ±îÁöÀÇ ¹®ÀÚ¿­À» Àд´Ù. 
			memcpy(&szTmpCheck, &szSrc[nStartLen], nEndLen-nStartLen); 
			INT nsLen; 
			nsLen = strlen(szTmpCheck); 
 
			// ÇöÀç±îÁö Àоî¿Â ºÎºÐÀÌ Çã¿ë³ÐÀ̸¦ ³Ñ¾î¼¹À»¶§. 
			if (nsLen > nDivideLen ) 
			{ 
				// ÇöÀç 2¹ÙÀÌÆ® ¹®ÀÚ¶ó¸é.  
				if ( szSrc[nEndLen-1] < 0 ) 
				{ 
					// ÇöÀç ¾Õ¿¡¹®ÀÚ°¡ 2¹ÙÀÌÆ® ¹®ÀÚ°¡ ¾Æ´Ï¶ó¸é 
					if ( !(nWordCheck%2) ) 
					{ 
						nStartLen += strlen(szTmpCheck)-1; 
						nCnt--; 
						CHAR* pszNewLine; 
						pszNewLine = new CHAR[nResultLen+1]; 
						memcpy(pszNewLine,szResult,nResultLen); 
						pszNewLine[nResultLen]=NULL; 
						m_pxpStr->AddNode(pszNewLine); 
						nResultLen = 0; 
						nDividedLine++; 
					} 
					else 
					{ 
						nStartLen += strlen(szTmpCheck)-2; 
						nCnt -= 2; 
						CHAR* pszNewLine; 
						pszNewLine = new CHAR[nResultLen]; 
						memcpy(pszNewLine,szResult,nResultLen-1); 
						pszNewLine[nResultLen-1]=NULL; 
						m_pxpStr->AddNode(pszNewLine); 
						nResultLen = 0; 
						nDividedLine++; 
						nWordCheck--; 
					} 
				} 
				// 1¹ÙÀÌÆ® ¹®ÀÚ.  
				// ÇöÀ纸´Ù ÇѹÙÀÌÆ®¾ÕºÎºÐ±îÁö¸¸ °í·ÁÇØÁÖ¸é µÈ´Ù. 
				else 
				{ 
					nStartLen += strlen(szTmpCheck)-1; 
					nCnt--; 
					CHAR* pszNewLine; 
					pszNewLine = new CHAR[nResultLen+1]; 
					memcpy(pszNewLine,szResult,nResultLen); 
					pszNewLine[nResultLen]=NULL; 
					m_pxpStr->AddNode(pszNewLine); 
					nResultLen=0; 
					nDividedLine++; 
				} 
			} 
			else if(szSrc[nEndLen-1]=='\n')	// °­Á¦°³Çà     \nÀ¸·ÎÇÏ¸é  Error ???? 
			{ 
				nStartLen += strlen(szTmpCheck)-1; 
				CHAR* pszNewLine; 
				pszNewLine = new CHAR[nResultLen+1]; 
				memcpy(pszNewLine,szResult,nResultLen); 
				pszNewLine[nResultLen]=NULL; 
				m_pxpStr->AddNode(pszNewLine); 
				nResultLen=0; 
				nDividedLine++; 
			} 
			else 
			{ 
				if ( szSrc[nEndLen-1] < 0 ) 
					nWordCheck++; 
 
				szResult[nResultLen] = szSrc[nEndLen-1]; 
				nResultLen++; 
			} 
		} 
		if(nResultLen!=0) 
		{ 
			CHAR* pszNewLine; 
			pszNewLine = new CHAR[nResultLen+1]; 
			memcpy(pszNewLine,szResult,nResultLen); 
			pszNewLine[nResultLen]=NULL; 
			m_pxpStr->AddNode(pszNewLine); 
			nDividedLine++; 
			nResultLen=0; 
		} 
		return TRUE; 
	} 
	return FALSE; 
} 
 
// Render Process 
BOOL CMirMsgBox::RenderMessageBox(INT nLoopTIme)							// Render Function 
{ 
	INT	nCount; 
//	POINT	xPos; 
//	POINT	xSize; 
 
	if(m_bActive&&m_bInited&&m_bSet) 
	{	// ÁøÂ¥ Âï¾î¾ß ÇÒ¶§¸¸ ÂïÀ»°Í 
		// ÂïÀ» À̹ÌÁö ¿µ¿ª È®ÀÎ 
		g_xMainWnd.DrawWithImageForCompClipRgn(m_xBoxPos.x,m_xBoxPos.y,m_shWidth,m_shHeight,m_wpData,800,600); 
 
		POINT	xTxtPos; 
		nCount = m_xMsg.GetCounter(); 
		m_xMsg.MoveCurrentToTop(); 
 
		xTxtPos.x = m_xBoxPos.x +24; 
		switch(nCount) 
		{ 
		case 1:	// ÂïÀ» ÁÙÀÌ 1°³ »ÓÀ϶§ 
			{ 
				xTxtPos.y = 68; 
				INT n = strlen(m_szMsg); 
				if(n