编辑框(CEdit)汇总.
来源:互联网 发布:linux 改名字命令 编辑:程序博客网 时间:2024/05/17 04:51
目录:
0.常用消息截获
1.示例功能
实现超链接效果.
编辑框右键菜单
0.常用消息截获
WM_CONTEXTMENU<虚截获>,响应右键
实现超链接效果
概要向导解析:
1.自定义文本控件<就是从CStatic进行类派生>
2.从工具栏直接拖原始控件就行.<但是在主界面Dialog中别忘了替换绑定也就是利用DDX_Control将资源控件ID和该派生出来的对象进行绑定>
3.重写相关虚函数.<这里有个概念认知,父类中的非虚拟函数是设计成不被子类改写的。根据有无virtual关键字,PreSubclassWindow重写>
好了,下面直接贴代码了:
.h文件
#if !defined(AFX_SUPERLABEL_H__3027B777_6D85_416C_A768_EC7BC3C03E3A__INCLUDED_)
#define AFX_SUPERLABEL_H__3027B777_6D85_416C_A768_EC7BC3C03E3A__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// SuperLabel.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CSuperLabel window
class CSuperLabel : public CStatic
{
// Construction
public:
CSuperLabel();
// Attributes
public:
CFont m_Font;
CString m_ConnectStr;
LOGFONT lfont;
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSuperLabel)
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CSuperLabel();
// Generated message map functions
protected:
//{{AFX_MSG(CSuperLabel)
afx_msg void OnPaint();
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_SUPERLABEL_H__3027B777_6D85_416C_A768_EC7BC3C03E3A__INCLUDED_)
.cpp文件
// SuperLabel.cpp : implementation file
//
#include "stdafx.h"
#include "SuperConnect.h"
#include "SuperLabel.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSuperLabel
CSuperLabel::CSuperLabel()
{
// m_Font.CreateFont(18,18,0,0,400,0,1,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DRAFT_QUALITY,DEFAULT_PITCH,"楷体32");
}
CSuperLabel::~CSuperLabel()
{
}
BEGIN_MESSAGE_MAP(CSuperLabel, CStatic)
//{{AFX_MSG_MAP(CSuperLabel)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSuperLabel message handlers
void CSuperLabel::OnPaint()
{
CPaintDC dc(this); // device context for painting
CDC* pDC = GetDC();
CString text;
GetWindowText(text);
if (m_ConnectStr.IsEmpty())
m_ConnectStr = text;
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(0,0,255));
pDC->SelectObject(&m_Font);
pDC->TextOut(0,0,text);
// Do not call CStatic::OnPaint() for painting messages
}
void CSuperLabel::OnLButtonDown(UINT nFlags, CPoint point)
{
ShellExecute(m_hWnd,NULL,m_ConnectStr,NULL,NULL,SW_SHOW);
CStatic::OnLButtonDown(nFlags, point);
}
void CSuperLabel::PreSubclassWindow()
{
GetWindowText(m_ConnectStr);
CFont* pFont = GetFont();
pFont->GetLogFont(&lfont);
lfont.lfUnderline =TRUE;
m_Font.CreateFontIndirect(&lfont);
CStatic::PreSubclassWindow();
}
void CSuperLabel::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
::SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR1));
CStatic::OnMouseMove(nFlags, point);
}
编辑框右键菜单
{
if (point.x == -1 && point.y == -1)
{
CRect rect;
GetClientRect(rect);
ClientToScreen(rect);
point = rect.TopLeft();
point.Offset(5, 5);
}
CMenu menu;
VERIFY(menu.LoadMenu(m_menuID));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = this;
while (pWndPopupOwner->GetStyle() & WS_CHILD)
pWndPopupOwner = pWndPopupOwner->GetParent();
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
pWndPopupOwner);
}
- 编辑框(CEdit)汇总.
- 编辑框CEdit
- [MFC]CEdit编辑框类
- MFC:整数编辑框CEdit
- 自绘编辑框CEdit(继承CEdit方式)
- CEdit获取编辑框的内容
- VC++ 实现CEdit编辑框输入小数!
- CEdit获取编辑框的内容
- CEdit获取编辑框的内容
- 编辑框CEdit自动换行简单设置
- CEdit编辑框透明的实现
- 如何禁止编辑框输入汉字CEdit
- CEdit获取编辑框的内容
- MFC CEdit获取编辑框内容
- 编辑框CEdit的EN_CHANGE通知消息
- CEdit编辑控件
- 控制编辑框焦点在最下面的方法(CEdit)
- WINCE中编辑框(CEdit)的“奇怪现象”
- 对所用对象的通用方法
- jzoj P2153【2017.7.7普及】串
- 广师oj 2238 最长回文子串
- bootstrap路径、分页、标签、徽章
- UnityShader入门精要学习笔记(十一):透明效果-下部分
- 编辑框(CEdit)汇总.
- mysql5.7.18解压版启动mysql服务
- python select网络编程模块详解
- dom4j解析Xml文件工具类
- 分布式文件系统 FastDFS 与nginx 结合
- 递归分治与动态规划--上台阶的问题
- macos中的YUV420p内存布局...
- Linux下的git配置
- 【C++笔记】宏定义数据类型与typedef