我在对话框上放了4个静态文本。
想要在文本上单击后产生:颜色改变,弹出其他对话框窗口。
我原来是:在WM_CTLCOLOR设置颜色,设置全局变量声明已经被点击过了,设置了NOTIFY属性。
但要求每个文本分别设置一个全局变量,很麻烦。
我想封装到一个类中,请问如何写代码???
想要在文本上单击后产生:颜色改变,弹出其他对话框窗口。
我原来是:在WM_CTLCOLOR设置颜色,设置全局变量声明已经被点击过了,设置了NOTIFY属性。
但要求每个文本分别设置一个全局变量,很麻烦。
我想封装到一个类中,请问如何写代码???
解决方案 »
- VC6 的工程里怎么使用LuaPlus?
- 四个顶点的CRgn 用FillRgn画出来是两个三角形,何解
- 有iwebbrowser2 和 ihtmldocumen2 如何知道页面是post的还是get得到的
- 请问什么是指针有效性检查?
- 再来求教。谢谢大家支持!也是关于对话框的问题。
- 高分求源代码, 基于阻塞方式的多线程SOCKET的动态链接库.
- 关闭对话框一问,谢谢!(我就剩这点分了)
- 请问vc的入口函数在哪(新手问题)
- 菜鸟问题:像QQ上这种能过点击让按钮移上移下的编程思路是怎样的
- 如何实现在文本框中插入一幅图片?就像在OutlookExpress中“编辑邮件”一样?
- MFC应用程序:子对话框如何操作父对话框的数据成员?
- VC中的提示没有了是怎么回事呀?
CLinkCtrl类做的不错。
//#include "stdafx.h"
#include "test6.h"
#include "MyStatic.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CMyStaticCMyStatic::CMyStatic()
{
m_bColor = FALSE;
}CMyStatic::~CMyStatic()
{
}
BEGIN_MESSAGE_MAP(CMyStatic, CStatic)
//{{AFX_MSG_MAP(CMyStatic)
ON_WM_LBUTTONDOWN()
ON_WM_PAINT()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CMyStatic message handlersvoid CMyStatic::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default m_bColor = TRUE; CStatic::OnLButtonDown(nFlags, point);
}void CMyStatic::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here CRect rect(0, 0, 100, 20);
CString str; GetWindowText(str); CFont *font = GetFont();
CFont *pOldFont = (CFont*)dc.SelectObject(font);
dc.SetBkMode(TRANSPARENT);
dc.SetTextColor(RGB(255,0,0));
dc.DrawText(str, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
dc.SelectObject(pOldFont); // Do not call CStatic::OnPaint() for painting messages
}HBRUSH CMyStatic::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CStatic::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(m_bColor)
{
static HBRUSH hbrEdit = ::CreateSolidBrush( RGB(0, 255, 0) );
pDC->SetTextColor( RGB(0, 255, 0) );
return hbrEdit;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}#if !defined(AFX_MYSTATIC_H__36FDC62E_2F41_48B6_B311_0387B490A1E3__INCLUDED_)
#define AFX_MYSTATIC_H__36FDC62E_2F41_48B6_B311_0387B490A1E3__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// MyStatic.h : header file
///////////////////////////////////////////////////////////////////////////////
// CMyStatic windowclass CMyStatic : public CStatic
{
// Construction
public:
CMyStatic();// Attributes
public:// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyStatic)
//}}AFX_VIRTUAL// Implementation
public:
virtual ~CMyStatic(); // Generated message map functions
protected:
//{{AFX_MSG(CMyStatic)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnPaint();
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
//}}AFX_MSG DECLARE_MESSAGE_MAP()
private:
BOOL m_bColor;
};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_MYSTATIC_H__36FDC62E_2F41_48B6_B311_0387B490A1E3__INCLUDED_)