博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
自绘static控件,实现特殊效果
阅读量:4048 次
发布时间:2019-05-25

本文共 2919 字,大约阅读时间需要 9 分钟。

#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);
}

转载地址:http://ipfci.baihongyu.com/

你可能感兴趣的文章
java自定义容器排序的两种方法
查看>>
如何成为编程高手
查看>>
本科生的编程水平到底有多高
查看>>
AngularJS2中最基本的文件说明
查看>>
从头开始学习jsp(2)——jsp的基本语法
查看>>
使用与或运算完成两个整数的相加
查看>>
备忘:java中的递归
查看>>
DIV/CSS:一个贴在左上角的标签
查看>>
Solr及Spring-Data-Solr入门学习
查看>>
Vue组件
查看>>
python_time模块
查看>>
python_configparser(解析ini)
查看>>
selenium学习资料
查看>>
<转>文档视图指针互获
查看>>
从mysql中 导出/导入表及数据
查看>>
HQL语句大全(转)
查看>>
几个常用的Javascript字符串处理函数 spilt(),join(),substring()和indexof()
查看>>
javascript传参字符串 与引号的嵌套调用
查看>>
swiper插件的的使用
查看>>
layui插件的使用
查看>>