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

📄 xmessagebox.cpp

📁 读取XML信息
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		msgrect.left += cxIcon + icon_x;
		msgrect.right += cxIcon + icon_x;

		mbrect.right = msgrect.right + SpacingSize;

		SetRect(&iconrect, icon_x, icon_y, icon_x + cxIcon + 2, icon_y + cyIcon + 2);
		AddItem(CXDialogItem::STATICTEXT, 1000, &iconrect, _T(""));
	}
	else if (pXMB->szIcon[0] != _T('\0'))
	{
		m_hIcon = ::LoadIcon(hInstanceIcon, pXMB->szIcon);
	}
	else if (nStyle & MB_ICONMASK)
	{
		LPTSTR lpIcon = (LPTSTR)IDI_EXCLAMATION;

		switch (nStyle & MB_ICONMASK)
		{
			case MB_ICONEXCLAMATION: lpIcon = (LPTSTR)IDI_EXCLAMATION; break;
			case MB_ICONHAND:        lpIcon = (LPTSTR)IDI_HAND;        break;
			case MB_ICONQUESTION:    lpIcon = (LPTSTR)IDI_QUESTION;    break;
			case MB_ICONASTERISK:    lpIcon = (LPTSTR)IDI_ASTERISK;    break;
		}

		if (lpIcon)
		{
			m_hIcon = ::LoadIcon(NULL, lpIcon);

			int cxIcon = GetSystemMetrics(SM_CXICON);
			int cyIcon = GetSystemMetrics(SM_CYICON);

			int icon_x = SpacingSize;
			int icon_y = SpacingSize;

			msgrect.left += cxIcon + icon_x;
			msgrect.right += cxIcon + icon_x;

			mbrect.right = msgrect.right + SpacingSize;

			SetRect(&iconrect, icon_x, icon_y, icon_x + cxIcon + 2, icon_y + cyIcon + 2);
			AddItem(CXDialogItem::STATICTEXT, 1000, &iconrect, _T(""));
		}
	}

	///////////////////////////////////////////////////////////////////////////
	// add message text
	AddItem(CXDialogItem::STATICTEXT, m_nMaxID++, &msgrect, GetMessageText());

	int cItems = 0;

	if (m_szCustomButtons[0] == _T('\0'))
	{
		// process standard buttons

		switch (nStyle & MB_TYPEMASK)
		{
			case MB_ABORTRETRYIGNORE      : cItems = 3; break;
			case MB_CANCELTRYCONTINUE     : cItems = 3; break;
			case MB_CONTINUEABORT         : cItems = 2; break;
			case MB_IGNOREIGNOREALLCANCEL : cItems = 3; break;
			case MB_OK                    : cItems = 1; break;
			case MB_OKCANCEL              : cItems = 2; break;
			case MB_RETRYCANCEL           : cItems = 2; break;
			case MB_SKIPSKIPALLCANCEL     : cItems = 3; break;
			case MB_YESNO                 : cItems = 2; break;
			case MB_YESNOCANCEL           : cItems = 3; break;
		}

		if (nStyle & MB_YESTOALL)
		{
			_ASSERTE((nStyle & MB_YESNO) || (nStyle & MB_YESNOCANCEL));
			if ((nStyle & MB_YESNO) || (nStyle & MB_YESNOCANCEL))
				cItems++;
		}

		if (nStyle & MB_NOTOALL)
		{
			_ASSERTE((nStyle & MB_YESNO) || (nStyle & MB_YESNOCANCEL));
			if ((nStyle & MB_YESNO) || (nStyle & MB_YESNOCANCEL))
				cItems++;
		}
	}
	else
	{
		// process custom buttons

		TCHAR szCustomButtons[MAX_PATH];
		_tcscpy(szCustomButtons, m_szCustomButtons);

		int i = 0;
		TCHAR * cp = _tcstok(szCustomButtons, _T("\n"));
		while (cp != NULL)
		{
			if (i >= MaxCustomButtons)
				break;

			cp = _tcstok(NULL, _T("\n"));
			i++;
		}

		cItems += i;
	}

	int nHelpButton = 0;
	if (nStyle & MB_HELP)
	{
		cItems++;
		nHelpButton = cItems;
	}

	int nReportButton = 0;
	if (m_lpReportFunc)
	{
		cItems++;
		nReportButton = cItems;
	}

	if (nStyle & MB_DONOTASKAGAIN)
		Set(DoNotAskAgain);
	else if (nStyle & MB_DONOTTELLAGAIN)
		Set(DoNotTellAgain);
	else if (nStyle & MB_DONOTSHOWAGAIN)
		Set(DoNotShowAgain);

	_ASSERTE(cItems > 0);

	CXRect buttonrow;
	y = (msgrect.bottom > iconrect.bottom) ? msgrect.bottom : iconrect.bottom;
	y += SpacingBetweenMessageAndButtons;

	// allow for wider buttons if timeout specified
	int button_width = m_nTimeoutSeconds ? ButtonTimeoutWidth : ButtonWidth;

	int w = button_width * cItems + (ButtonSpacing * (cItems - 1));

	SetRect(&buttonrow,0, y, w, y + ButtonHeight);

	switch (nStyle & MB_DEFMASK)
	{
		case MB_DEFBUTTON1 : m_nDefButton = 1; break;
		case MB_DEFBUTTON2 : m_nDefButton = 2; break;
		case MB_DEFBUTTON3 : m_nDefButton = 3; break;
		case MB_DEFBUTTON4 : m_nDefButton = 4; break;
		case MB_DEFBUTTON5 : m_nDefButton = 5; break;
		case MB_DEFBUTTON6 : m_nDefButton = 6; break;
		default:             m_nDefButton = 1; break;
	}

	if (m_nDefButton > cItems)
		m_nDefButton = 1;

	if (nHelpButton == m_nDefButton)
	{
		TRACE(_T("ERROR:  Help button cannot be default button\n"));
		_ASSERTE(FALSE);
	}

	if (nReportButton == m_nDefButton)
	{
		TRACE(_T("ERROR:  Report button cannot be default button\n"));
		_ASSERTE(FALSE);
	}

	///////////////////////////////////////////////////////////////////////////
	// add buttons

	mbrect.bottom = buttonrow.bottom + BottomMargin;

	int bw = buttonrow.Width();
	int bleft = 2 * SpacingSize;
	int bright = bleft + bw;

	if (mbrect.right <= (bright + (2 * SpacingSize)))
		mbrect.right = bright + (2 * SpacingSize);

	x = (mbrect.Width() - bw) / 2;
	y = buttonrow.top;

	if (m_bRightJustifyButtons)
	{
		x = mbrect.right - ButtonSpacing - cItems * (ButtonSpacing + button_width);
	}

	if (m_szCustomButtons[0] == _T('\0'))
	{
		// no custom buttons

		switch (nStyle & MB_TYPEMASK)
		{
			case MB_OK:
				SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDOK, &rect, szOK);
				Set(OkButton);
				break;

			case MB_OKCANCEL:
				SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDOK, &rect, szOK);

				x += button_width + ButtonSpacing;
				SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDCANCEL, &rect, szCancel);
				Set(CancelButton);
				break;

			case MB_YESNO:
				SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDYES, &rect, szYes);

				if (nStyle & MB_YESTOALL)
				{
					x += button_width + ButtonSpacing;
					SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
					AddItem(CXDialogItem::BUTTON, IDYESTOALL, &rect, szYesToAll);
				}

				x += button_width + ButtonSpacing;
				SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDNO, &rect, szNo);

				if (nStyle & MB_NOTOALL)
				{
					x += button_width + ButtonSpacing;
					SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
					AddItem(CXDialogItem::BUTTON, IDNOTOALL, &rect, szNoToAll);
				}
				break;

			case MB_YESNOCANCEL:
				SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDYES, &rect, szYes);

				if (nStyle & MB_YESTOALL)
				{
					x += button_width + ButtonSpacing;
					SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
					AddItem(CXDialogItem::BUTTON, IDYESTOALL, &rect, szYesToAll);
				}

				x += button_width + ButtonSpacing;
				SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDNO, &rect, szNo);

				if (nStyle & MB_NOTOALL)
				{
					x += button_width + ButtonSpacing;
					SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
					AddItem(CXDialogItem::BUTTON, IDNOTOALL, &rect, szNoToAll);
				}

				x += button_width + ButtonSpacing;
				SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDCANCEL, &rect, szCancel);
				Set(CancelButton);
				break;

			case MB_ABORTRETRYIGNORE:
				SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDABORT, &rect, szAbort);

				x += button_width + ButtonSpacing;
				SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDRETRY, &rect, szRetry);

				x += button_width + ButtonSpacing;
				SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDIGNORE, &rect, szIgnore);
				break;

			case MB_RETRYCANCEL:
				SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDRETRY, &rect, szRetry);

				x += button_width + ButtonSpacing;
				SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDCANCEL, &rect, szCancel);
				Set(CancelButton);
				break;

			case MB_CONTINUEABORT:
				SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDCONTINUE, &rect, szContinue);

				x += button_width + ButtonSpacing;
				SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDABORT, &rect, szAbort);
				break;

			case MB_CANCELTRYCONTINUE:
				rect.SetRect(x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDCANCEL, &rect, szCancel);

				x += button_width + ButtonSpacing;
				rect.SetRect(x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDTRYAGAIN, &rect, szTryAgain);

				x += button_width + ButtonSpacing;
				rect.SetRect(x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDCONTINUE, &rect, szContinue);
				Set(CancelButton);
				break;

			case MB_SKIPSKIPALLCANCEL:
				rect.SetRect(x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDSKIP, &rect, szSkip);

				x += button_width + ButtonSpacing;
				rect.SetRect(x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDSKIPALL, &rect, szSkipAll);

				x += button_width + ButtonSpacing;
				rect.SetRect(x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDCANCEL, &rect, szCancel);
				Set(CancelButton);
				break;

			case MB_IGNOREIGNOREALLCANCEL:
				rect.SetRect(x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDIGNORE, &rect, szIgnore);

				x += button_width + ButtonSpacing;
				rect.SetRect(x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDIGNOREALL, &rect, szIgnoreAll);

				x += button_width + ButtonSpacing;
				rect.SetRect(x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDCANCEL, &rect, szCancel);
				Set(CancelButton);
				break;

			default:
				SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
				AddItem(CXDialogItem::BUTTON, IDOK, &rect, szOK);
				break;
		}
	}
	else
	{
		// process custom buttons

		TCHAR szCustomButtons[MAX_PATH];
		_tcscpy(szCustomButtons, m_szCustomButtons);

		int i = 0;
		TCHAR * cp = _tcstok(szCustomButtons, _T("\n"));
		while (cp != NULL)
		{
			if (i >= MaxCustomButtons)
				break;

			if (i > 0)
				x += button_width + ButtonSpacing;

			rect.SetRect(x, y, x + button_width, y + ButtonHeight);
			AddItem(CXDialogItem::BUTTON, IDCUSTOM1 + i, &rect, cp);
			cp = _tcstok(NULL, _T("\n"));
			i++;
		}
	}

	if (nStyle & MB_HELP)
	{
		x += button_width + ButtonSpacing;
		SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
		AddItem(CXDialogItem::BUTTON, IdExHelp, &rect, szHelp);
	}

	if (m_lpReportFunc)
	{
		x += button_width + ButtonSpacing;
		SetRect(&rect,x, y, x + button_width, y + ButtonHeight);
		AddItem(CXDialogItem::BUTTON, IdExReport, &rect, szReport);
	}

	///////////////////////////////////////////////////////////////////////////
	// add checkbox

	nMaxWidth = ::GetSystemMetrics(SM_CXSCREEN) / 3;

	CXRect checkboxrect;
	SetRect(&checkboxrect,0, 0, nMaxWidth, DoNotAskAgainHeight);

	if (nStyle & MB_DONOTASKAGAIN)
		AddCheckBox(hdc, x, y, rect, mbrect, buttonrow, checkboxrect, szDoNotAskAgain);
	else if (nStyle & MB_DONOTTELLAGAIN)
		AddCheckBox(hdc, x, y, rect, mbrect, buttonrow, checkboxrect, szDoNotTellAgain);
	else if (nStyle & MB_DONOTSHOWAGAIN)
		AddCheckBox(hdc, x, y, rect, mbrect, buttonrow, checkboxrect, szDoNotShowAgain);

	if (buttonrow.bottom >= mbrect.bottom)
		mbrect.bottom = buttonrow.bottom + (2 * SpacingSize);

	if (mbrect.right < (buttonrow.right + (2 * SpacingSize)))
		mbrect.right = buttonrow.right + (2 * SpacingSize);

	short hidbu = HIWORD(GetDialogBaseUnits());
	short lodbu = LOWORD(GetDialogBaseUnits());

	m_dlgTempl.x = 0;
	m_dlgTempl.y = 0;
	m_dlgTempl.cx = (short)((mbrect.Width() * 4) / lodbu);
	m_dlgTempl.cy = (short)((mbrect.Height() * 8) / hidbu);

	::SelectObject(hdc, hOldFont);
	::DeleteDC(hdc);
}

///////////////////////////////////////////////////////////////////////////////
// CXDialogTemplate dtor
CXDialogTemplate::~CXDialogTemplate()
{
	if (m_hIcon)
		DestroyIcon(m_hIcon);

	if (m_hFont)
		::DeleteObject(m_hFont);

	for (int i = 0; i < MaxItems; i++)
	{
		if (m_pDlgItemArray[i])
		{
			delete m_pDlgItemArray[i];

⌨️ 快捷键说明

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