tipdlg.cpp

来自「这是本人两年前兼职为某个公司做的石油钻进设计软件」· C++ 代码 · 共 131 行

CPP
131
字号
// TipDlg.cpp : implementation file
//

#include "stdafx.h"
#include "TipDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTipDlg dialog

CTipDlg::CTipDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTipDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTipDlg)
	m_pParent     = pParent;
	m_nID         = CTipDlg::IDD;
	//}}AFX_DATA_INIT
}

CTipDlg::~CTipDlg()
{
}

void CTipDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTipDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTipDlg, CDialog)
	//{{AFX_MSG_MAP(CTipDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTipDlg message handlers
/*************************************************************************
 *
 * Create()
 *
 * 功  能: 创立对话框
 *
 * 参  数: 无
 *
 * 返回值: 无
 *************************************************************************/
BOOL CTipDlg::Create()
{
	return CDialog::Create(m_nID, m_pParent);
}

void CTipDlg::SetTipInfo(CString m_cTipInfo, CRect rc)
{
	CString      str;
	TEXTMETRIC   tm;
	int          pos   = 0xFFFF;
	CDC          *dc   = GetWindowDC();
	CFont        *font = GetFont();
	short        cxChar, cyChar;
	COLORREF     bkColor = RGB(157, 243, 139);
	CBrush       bkBrush(bkColor);

	dc->SelectObject(font);
    dc->SetTextColor(RGB(240, 6, 0));
	dc->SetBkColor(bkColor);
	dc->SelectObject(&bkBrush);
	dc->GetTextMetrics(&tm);
	cxChar = (short)tm.tmAveCharWidth;
	cyChar = (short)(tm.tmHeight + tm.tmExternalLeading);

	int len = m_cTipInfo.GetLength();
	for(int i = 0; i < len; i++)
	{
		if(m_cTipInfo.GetAt(i) == '\n' && i != len - 1)
		{
			pos = i;
			break;
		}
	}

	if(pos != 0xFFFF)
	{
		int width;

		if(pos > len - pos - 1)
			width = pos;
		else
			width = len - pos - 1;
		dc->Rectangle(0, 0, cxChar * width + 4, cyChar * 2 + 2);
		SetWindowPos(NULL, 
			         rc.left - cxChar * width / 2, 
					 rc.top - cyChar * 2 - 6, 
					 cxChar * width + 4, 
					 cyChar * 2 + 2, 
					 SWP_NOACTIVATE);
		ShowWindow(SW_SHOWNOACTIVATE);
		str = m_cTipInfo.Left(pos);
		dc->TextOut(2, 2, str);
		str = m_cTipInfo.Right(len - pos - 1);
		dc->TextOut(2, cyChar + 2, str);
	}
	else
	{
		dc->Rectangle(0, 0, cxChar * m_cTipInfo.GetLength() + 4, cyChar + 2);
		SetWindowPos(NULL, 
			         rc.left - cxChar * m_cTipInfo.GetLength() - 4 - 20, 
					 rc.top - cyChar - 2, 
					 cxChar * m_cTipInfo.GetLength() + 4, 
					 cyChar + 2, 
					 SWP_SHOWWINDOW);
		dc->TextOut(2, 1, m_cTipInfo);
	}

	dc->SelectObject(font);
}

BOOL CTipDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();	

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

⌨️ 快捷键说明

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