#pragma once
// CMyStatic
class CMyStatic : public CStatic
{
DECLARE_DYNAMIC(CMyStatic)
public:
CMyStatic();
virtual ~CMyStatic();
protected:
DECLARE_MESSAGE_MAP()
private:
int m_iDrawFlag;//0无绘,1左绘,2右绘,3左右绘
int m_iDrawNum;//序列循环次数
int m_iDrawType;//需要绘制的图片
bool m_bSelected;//当前是否被选中
public:
void SetDrawFlag(int iDrawFlag) {m_iDrawFlag = iDrawFlag;}
void SetDrawNum(int iDrawNum) {m_iDrawNum = iDrawNum;}
void SetDrawType(int iDrawType) {m_iDrawType = iDrawType;}
void SetSelected(bool bSel) {m_bSelected = bSel;}
afx_msg void OnPaint();
};
// MyStatic.cpp : 实现文件
//
#include "stdafx.h"
#include "TestDock.h"
#include "MyStatic.h"
// CMyStatic
IMPLEMENT_DYNAMIC(CMyStatic, CStatic)
CMyStatic::CMyStatic()
: m_iDrawFlag(0)
, m_iDrawNum(0)
, m_iDrawType(0)
, m_bSelected(false)
{
//ModifyStyle(0,SS_BITMAP|SS_CENTERIMAGE);
}
CMyStatic::~CMyStatic()
{
}
BEGIN_MESSAGE_MAP(CMyStatic, CStatic)
ON_WM_PAINT()
END_MESSAGE_MAP()
// CMyStatic 消息处理程序
void CMyStatic::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: 在此处添加消息处理程序代码
// 不为绘图消息调用 CStatic::OnPaint()
CRect reWnd;
GetClientRect(&reWnd);
//dc.MoveTo(reWnd.left+2, reWnd.top+2);
//dc.LineTo(reWnd.left+2, reWnd.bottom-2);
//dc.MoveTo(reWnd.right-2, reWnd.top+2);
//dc.LineTo(reWnd.right-2, reWnd.bottom-2);
dc.SetTextColor(RGB(255,0,255));
dc.SetBkMode(TRANSPARENT);
CPen pen(PS_SOLID, 2, RGB(255,0,0));
CPen* pOldPen = dc.SelectObject(&pen);
if (!m_bSelected)
{
dc.FillSolidRect(reWnd, RGB(0,255,255));
}
else
{
dc.FillSolidRect(reWnd, RGB(255,255,0));
}
CImage img;
if (m_iDrawType == 0)
{
img.Load(L"res\\self.png");
}
else
{
img.Load(L"res\\CurTrade.png");
}
CRect reImg = reWnd;
reImg.DeflateRect(3,3);
img.Draw(dc.m_hDC, reImg);
const int ciLeft = 6;
const int ciTop = 6;
if (m_iDrawFlag == 3)
{
//左右绘
dc.MoveTo(reWnd.left+ciLeft*2, reWnd.top+ciTop);
dc.LineTo(reWnd.left+ciLeft, reWnd.top+ciTop);
dc.LineTo(reWnd.left+ciLeft, reWnd.bottom-ciTop);
dc.LineTo(reWnd.left+ciLeft*2, reWnd.bottom-ciTop);
CString csText;
csText.Format(L"%d", m_iDrawNum);
dc.TextOutW(reWnd.right-ciLeft*4, reWnd.top+ciTop*2, csText);
dc.MoveTo(reWnd.right-ciLeft*2, reWnd.top+ciTop);
dc.LineTo(reWnd.right-ciLeft, reWnd.top+ciTop);
dc.LineTo(reWnd.right-ciLeft, reWnd.bottom-ciTop);
dc.LineTo(reWnd.right-ciLeft*2, reWnd.bottom-ciTop);
}
else if (m_iDrawFlag == 1)
{
//左绘
dc.MoveTo(reWnd.left+ciLeft*2, reWnd.top+ciTop);
dc.LineTo(reWnd.left+ciLeft, reWnd.top+ciTop);
dc.LineTo(reWnd.left+ciLeft, reWnd.bottom-ciTop);
dc.LineTo(reWnd.left+ciLeft*2, reWnd.bottom-ciTop);
}
else if (m_iDrawFlag == 2)
{
//右绘
CString csText;
csText.Format(L"%d", m_iDrawNum);
dc.TextOutW(reWnd.right-ciLeft*4, reWnd.top+ciTop*2, csText);
dc.MoveTo(reWnd.right-ciLeft*2, reWnd.top+ciTop);
dc.LineTo(reWnd.right-ciLeft, reWnd.top+ciTop);
dc.LineTo(reWnd.right-ciLeft, reWnd.bottom-ciTop);
dc.LineTo(reWnd.right-ciLeft*2, reWnd.bottom-ciTop);
}
else
{
//无绘
}
dc.SelectObject(pOldPen);
}