我在对话框上放了4个静态文本。
想要在文本上单击后产生:颜色改变,弹出其他对话框窗口。
我原来是:在WM_CTLCOLOR设置颜色,设置全局变量声明已经被点击过了,设置了NOTIFY属性。
但要求每个文本分别设置一个全局变量,很麻烦。
我想封装到一个类中,请问如何写代码???

解决方案 »

  1.   

    从CStatic继承一个自定义的static,响应单击消息
      

  2.   

    www.vckbase.com上面找找那个做成超连接的类
      

  3.   

    从cstatic继承一个自己得类,用这个类创建静态文本控件,然后在这个类得WM_LBUTTONDWON里面设定改变,这样就不要全局变量了
      

  4.   

    http://www.codeguru.com/Cpp/controls/staticctrl/
      

  5.   

    VckBase上的
    CLinkCtrl类做的不错。
      

  6.   

    // MyStatic.cpp : implementation file
    //#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_)