当前位置:网站首页>VS2019 MFC IP Address Control 控件繼承CIPAddressCtrl類重繪
VS2019 MFC IP Address Control 控件繼承CIPAddressCtrl類重繪
2022-06-12 07:25:00 【lzc881012】
CMyIPAddressCtrl.h繼承類h頭文件
#include"MacroDefinition.h"
#pragma once
class CMyIPAddressCtrl:public CIPAddressCtrl
{
DECLARE_DYNAMIC(CMyIPAddressCtrl)
public:
CMyIPAddressCtrl();
virtual ~CMyIPAddressCtrl();
CBrush m_NrBkBrush;
CBrush m_SlBkBrush;
BOOL m_SelectedFlag;
CFont* p_Font;
COLORREF m_SlTextCtrl;
COLORREF m_UnSlTextCtrl;
COLORREF m_SlTextBkCtrl;
COLORREF m_UnSlTextBkCtrl;
CFont m_Text;
protected:
DECLARE_MESSAGE_MAP()
public:
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
void SetTextNrBackColor(COLORREF eTextNrBkCtrl);
void SetTextSlBackColor(COLORREF eTextSlBkCtrl);
void SetTextNrColor(COLORREF eNrTextCtrl);
void SetTextSlColor(COLORREF eSlTextColor);
void SetIPAddressCtrlBackColorNormal(COLORREF iPAddressBkCtrlNormal);
void SetIPAddressCtrlBackColorSelect(COLORREF iPAddressBkCtrlSelect);
bool SetTextFont(LONG nHeight, bool bBold, bool bItalic, bool bunderline ,const CString& sFaceName);
bool SetTextFont(CFont *m_cfont);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnMouseLeave();
};
CMyIPAddressCtrl.CPP實現文件
#include "pch.h"
#include "CMyIPAddressCtrl.h"
IMPLEMENT_DYNAMIC(CMyIPAddressCtrl, CIPAddressCtrl);
CMyIPAddressCtrl::CMyIPAddressCtrl()
{
m_SelectedFlag = FALSE;
SetIPAddressCtrlBackColorNormal(RGB(150,130,50));
SetIPAddressCtrlBackColorSelect(RGB(0,0,255));
SetTextNrBackColor(RGB(150, 130, 50));
SetTextSlBackColor(RGB(0, 0, 255));
SetTextNrColor(RGB(0, 0, 255));
SetTextSlColor(RGB(255, 0, 0));
p_Font = NULL;
p_Font = new CFont;
}
CMyIPAddressCtrl::~CMyIPAddressCtrl()
{
p_Font->Detach();
p_Font->DeleteObject();
p_Font = NULL;
m_NrBkBrush.DeleteObject();
m_SlBkBrush.DeleteObject();
}
BEGIN_MESSAGE_MAP(CMyIPAddressCtrl, CIPAddressCtrl)
ON_WM_CTLCOLOR()
ON_WM_MOUSEMOVE()
ON_WM_MOUSELEAVE()
END_MESSAGE_MAP()
HBRUSH CMyIPAddressCtrl::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
pDC->SetBkMode(TRANSPARENT);
if (m_SelectedFlag==FALSE)
{ pDC->SetTextColor(m_UnSlTextCtrl);
pDC->SetBkColor(m_UnSlTextBkCtrl);
return(HBRUSH)m_NrBkBrush;
}
else
{
pDC->SetTextColor(m_SlTextCtrl);
pDC->SetBkColor(m_SlTextBkCtrl);
return(HBRUSH)m_SlBkBrush;
}
}
void CMyIPAddressCtrl::SetTextNrBackColor(COLORREF eTextNrBkCtrl)
{
m_UnSlTextBkCtrl = eTextNrBkCtrl;
}
void CMyIPAddressCtrl::SetTextSlBackColor(COLORREF eTextSlBkCtrl)
{
m_SlTextBkCtrl = eTextSlBkCtrl;
}
void CMyIPAddressCtrl::SetTextNrColor(COLORREF eNrTextCtrl)
{
m_UnSlTextCtrl = eNrTextCtrl;
}
void CMyIPAddressCtrl::SetTextSlColor(COLORREF eSlTextColor)
{
m_SlTextCtrl = eSlTextColor;
}
void CMyIPAddressCtrl::SetIPAddressCtrlBackColorNormal(COLORREF iPAddressBkCtrlNormal)
{
m_NrBkBrush, Detach();
m_NrBkBrush.CreateSolidBrush(iPAddressBkCtrlNormal);
}
void CMyIPAddressCtrl::SetIPAddressCtrlBackColorSelect(COLORREF iPAddressBkCtrlSelect)
{
m_SlBkBrush.Detach();
m_SlBkBrush.CreateSolidBrush(iPAddressBkCtrlSelect);
}
bool CMyIPAddressCtrl::SetTextFont(LONG nHeight, bool bBold, bool bItalic,bool bunderline, const CString& sFaceName)
{
p_Font->CreateFontW(nHeight, 0, 0, 0, bBold, bItalic, bunderline, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, sFaceName);
return this->SetTextFont(p_Font);
}
bool CMyIPAddressCtrl::SetTextFont(CFont *m_cfont)
{
this->SetFont(m_cfont, TRUE);
return true;
}
void CMyIPAddressCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
TRACKMOUSEEVENT csTME;
if (!m_SelectedFlag)
{
m_SelectedFlag = TRUE;
Invalidate();
csTME.cbSize = sizeof(csTME);
csTME.dwFlags = TME_LEAVE;
csTME.hwndTrack = m_hWnd;
csTME.dwHoverTime = 1;
::_TrackMouseEvent(&csTME);
}
CIPAddressCtrl::OnMouseMove(nFlags, point);
}
void CMyIPAddressCtrl::OnMouseLeave()
{
if (m_SelectedFlag)
{
m_SelectedFlag = FALSE;
Invalidate();
}
CIPAddressCtrl::OnMouseLeave();
}
边栏推荐
- 速度自关联函数—LAMMPS V.S MATALB
- D
- Shortcut key modification of TMUX and VIM
- Continuous local training for better initialization of Federated models
- @DateTimeFormat @JsonFormat 的区别
- 右击文件转圈卡住、刷新、白屏、闪退、桌面崩溃的通用解决方法
- lambda 函数完美使用指南
- Learning to continuously learn paper notes + code interpretation
- [wax chain tour] release a free and open source alien worlds script TLM
- 新知识:Monkey 改进版之 App Crawler
猜你喜欢

Day 4 of pyhon

Esp8266 firmware upgrade method (esp8266-01s module)

Pyhon的第四天

TypeScript基础知识全集

2022起重机械指挥考试题模拟考试平台操作

2022年危险化学品经营单位安全管理人员特种作业证考试题库及答案

Summary of machine learning + pattern recognition learning (II) -- perceptron and neural network

RT thread studio learning (VII) using multiple serial ports

基于eNSP加防火墙的千人中型校园/企业网络规划与设计(附所有配置命令)

libprint2
随机推荐
Detailed principle of 4.3-inch TFTLCD based on warship V3
Node, topic, parameter renaming and global, relative and private namespaces in ROS (example + code)
Unity用Shader实现UGU i图片边缘选中高亮
新知识:Monkey 改进版之 App Crawler
Map to sort
RT thread studio learning (I) new project
[image detection] SAR image change detection based on depth difference and pcanet with matlab code
Federated reconnaissance: efficient, distributed, class incremental learning paper reading + code analysis
8086/8088 instruction execution pipeline disconnection reason
Construction of running water lamp experiment with simulation software proteus
QT realization tray
Federated meta learning with fast convergence and effective communication
Kali与编程:如何快速搭建OWASP网站安全实验靶场?
Can official account also bring goods?
Complete set of typescript Basics
TypeScript基础知识全集
Detailed explanation of TF2 command line debugging tool in ROS (parsing + code example + execution logic)
Test manager defines and implements test metrics
sql——课程实验考查
Improved schemes for episodic memory based lifelong learning