Files
envi-code/SourceCode/Code2026/tg_shs/shs_public/TipWnd.cpp
T
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

163 lines
4.6 KiB
C++

// TipWnd.cpp: implementation of the CTipWnd class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "TipWnd.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNAMIC(CTipWnd, CWnd)
CTipWnd::CTipWnd()
{
}
CTipWnd::~CTipWnd()
{
}
BEGIN_MESSAGE_MAP(CTipWnd, CWnd)
//{{AFX_MSG_MAP(CObjectTipWnd)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CTipWnd::OnPaint()
{
if(!m_lstInfo)
return;
CRect Rect;
GetClientRect(Rect);
CPaintDC dc(this); // device context for painting
CFont *pFont=dc.SelectObject(&m_font);
{
CBrush hb1;
hb1.CreateSolidBrush(::GetSysColor(COLOR_INFOBK));
CBrush *pBrush1=dc.SelectObject(&hb1);
dc.Rectangle(0,0,Rect.right,Rect.bottom);
dc.SelectObject(pBrush1);
}
CBrush hb2;
hb2.CreateSolidBrush(RGB(0,0,0));
dc.FrameRect(&Rect,&hb2);
int nGap=4;
CPoint pos(0,0);
pos.x = nGap + m_sizeLab.cx + nGap;
{
CPen pen(PS_DOT, 1, RGB(0,0,0));
CPen *pOldPen=dc.SelectObject(&pen);
dc.MoveTo(pos.x, Rect.top);
dc.LineTo(pos.x, Rect.bottom);
dc.SelectObject(pOldPen);
}
dc.SetTextColor(::GetSysColor(COLOR_INFOTEXT));
dc.SetBkColor(::GetSysColor(COLOR_INFOBK));
for(int i=0; i<m_lstInfo.Length();i++) {
CBlockStruct *pObjUnit=m_lstInfo[i];
pos.y += nGap;
CString csLab=pObjUnit->m_csRecord;
CString csVal=pObjUnit->m_csDesName;
CRect rectLab(nGap, pos.y, pos.x-nGap, pos.y+max(m_sizeLab.cy, m_sizeVal.cy));
dc.DrawText(csLab, rectLab, DT_RIGHT);
CRect rectVal(pos.x+nGap, pos.y, nGap*3+m_sizeLab.cx+m_sizeVal.cx, pos.y+max(m_sizeLab.cy,m_sizeVal.cy));
dc.DrawText(csVal, rectVal, DT_LEFT);
pos.y += max(m_sizeLab.cy,m_sizeVal.cy);
}
//dc.DrawText(m_sText,-1,CRect(2,2,Rect.right-4,Rect.bottom-4),DT_LEFT);
// Do not call CWnd::OnPaint() for painting messages
}
BOOL CTipWnd::Create(DList<CBlockStruct> &lstInfo,int x,int y, CWnd *pParent)
{
LOGFONT m_lf;
ZeroMemory ((PVOID) &m_lf,sizeof (LOGFONT));
NONCLIENTMETRICS nm;
//nm.cbSize = sizeof (NONCLIENTMETRICS); 2010-5-6 沈睿删除,2010下崩溃
//#if ADS<18
nm.cbSize = sizeof (NONCLIENTMETRICS);
//#else
//nm.cbSize = sizeof(NONCLIENTMETRICS) - sizeof(nm.iPaddedBorderWidth);
//#endif
VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
nm.cbSize,&nm,0));
m_lf = nm.lfMenuFont;
m_font.CreateFontIndirect (&m_lf);
// Obtain the width of the text:
CWnd *pWnd = AfxGetMainWnd(); // Get main window
CDC *pDC = pWnd->GetDC(); // Get device context
CFont* pFont=NULL; // Select menu font in...
pFont = pDC->SelectObject (&m_font);// Select menu font in...
lstInfo.SetDelFlag(FALSE);
m_lstInfo.Reset();
m_sizeLab=CSize(0,0);
m_sizeVal=CSize(0,0);
for(int i=0; i<lstInfo.Length();i++) {
CBlockStruct *pObjUnit=lstInfo[i];
if(pObjUnit->m_csDesName == "")
pObjUnit->m_csDesName = "无信息";
m_lstInfo.Append(pObjUnit);
CSize size=pDC->GetTextExtent(CString(pObjUnit->m_csRecord));
m_sizeLab.cx = max(m_sizeLab.cx, size.cx);
m_sizeLab.cy = max(m_sizeLab.cy, size.cy);
size=pDC->GetTextExtent(CString(pObjUnit->m_csDesName));
m_sizeVal.cx = max(m_sizeVal.cx, size.cx);
m_sizeVal.cy = max(m_sizeVal.cy, size.cy);
}
pDC->SelectObject (pFont); // Select old font in
pWnd->ReleaseDC(pDC); // Release the DC
if(m_sizeLab.cx>200) m_sizeLab.cx=200;
if(m_sizeVal.cx>200) m_sizeVal.cx=200;
CSize sizeWnd;
int nGap=4;
sizeWnd.cx = nGap + m_sizeLab.cx + nGap*2 + m_sizeVal.cx + nGap;
sizeWnd.cy = nGap + (max(m_sizeLab.cy, m_sizeVal.cy) + nGap)*lstInfo.Length();
CRect rect;
rect.left = x;
rect.top = y;
rect.right = x + sizeWnd.cx;
rect.bottom = y + sizeWnd.cy;
CWnd *pFrameWnd=pParent;
ASSERT(pFrameWnd);
CRect rectClient;
pFrameWnd->GetClientRect(&rectClient);
if(rect.bottom > rectClient.bottom) {
rect.top -= rect.bottom-rectClient.bottom;
rect.bottom = rectClient.bottom;
}
if(rect.right > rectClient.right) {
rect.left -= rect.right-rectClient.right;
rect.right = rectClient.right;
}
BOOL bRet= CWnd::Create(NULL,NULL,WS_CHILD|WS_VISIBLE,rect,pFrameWnd,0);
GEOAPI double g_nAcadVer;
if(g_nAcadVer>16.11)//2006平台下要多画一次
SetTimer(1,200,NULL);
return bRet;
}