自己写个类吧,在vckbase,vchelp上code 多的很,看去把

解决方案 »

  1.   

    我看过了,都是在资源上先画一个Button,然后Attach,但是我需要自己Create。
      

  2.   

    我已经重载了DrawItem,可以显示,但是无法响应消息。
      

  3.   

    但是我需要自己Create。 
    那么你有没有给它指定resource ID?
      

  4.   

    重载OnLButtonUp(),在其中PostMessage,可以到www.vchelp.net找相关的资料
      

  5.   

    不行,不能响应任何消息(OnLButtonUp等等)
      

  6.   

    你说的我不太明白、、、你自己把CButton子类化一下,里面Draw一下,给这个类添加相应的消息处理
    create,show出来不就行了么?
      

  7.   

    我刚刚开始也是这么想的,但是实际情况完全不一样,它无法响应任何消息。
    我用spy看了一下,button被自动置为disable
      

  8.   

    只有OnCreate,Destory等管用,对于任何mouse事件都不起作用。
      

  9.   

    奇怪的是,当我使用IDC_STATIC作为BUTTON的ID时能够响应消息,其它任何自己定义的ID都不可以。
      

  10.   

    Define a class CMyButton :public CButton
    add a virtual function to it
    void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    {
    // TODO: Add your code to draw the specified item
    HDC hdc=lpDrawItemStruct->hDC;
    CString strcatpion;
    this->GetWindowText(strcatpion);
    DrawText(hdc,strcatpion,strcatpion.GetLength(),&lpDrawItemStruct->rcItem,DT_CENTER);
    }
    Define a resource ID :
    ID_MYBUTTON.
    Add a CMyButton member to the view class:
    CMyButton m_button;
    Add WM_CREATE message handle to the view class
    int CObuttonView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
    {
    if (CView::OnCreate(lpCreateStruct) == -1)
    return -1;

    // TODO: Add your specialized creation code here m_button.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW, 
        CRect(10,10,100,30), this, ID_MYBUTTON); return 0;
    }
    Add a line to handle button click into the MessageMap 
    ON_WM_CREATE()
    ON_BN_CLICKED(ID_MYBUTTON, OnMyButton)//add this line
    Add a function to the View class
    afx_msg void OnMyButton();
    //implementation example
    void CObuttonView::OnMyButton()
    {
    AfxMessageBox("clicked");
    }
      

  11.   

    谢谢masterz()的源代码,但是还是不行。
    因为你是在View中Create,而我必须在派生的dialogbar中创建这个button,但是当在派生的dialogbar中Create Button时,这个button不能响应任何消息。
      

  12.   

    我想问题可能在这里:
        记得在TOOLBAR中的一个按扭如果没有定义消息响应函数,这个按扭就自动为DISABLE,在DIALOGBAR中可能也是这个问题。给BUTTON的ID定义一个消息响应函数试一下。
      

  13.   

    利用上面的CMyButton class,
    add a member to your derived class CMyDialogBar
    CMyButton m_button.
    为CMyDialog加WM_CREATE message handle
    int CMyDialogBar::OnCreate(LPCREATESTRUCT lpCreateStruct) 
    {
    if (CDialogBar::OnCreate(lpCreateStruct) == -1)
    return -1;
    m_button.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW, 
        CRect(10,10,100,30), this, ID_MYBUTTON);
    return 0;
    }View菜单Resource symbols dialog中增加一个resource ID: ID_MYBUTTON
    加一个成员函数给CMyDialogBar
    afx_msg void OnButtonClick();
    void CMyDialogBar::OnButtonClick()
    {
    AfxMessageBox("button of dlgbar clicked");
    }
    在Message_MAp 中加上button 的message handle
    BEGIN_MESSAGE_MAP(CMyDialogBar, CDialogBar)
    //{{AFX_MSG_MAP(CMyDialogBar)
    ON_WM_CREATE()
    ON_BN_CLICKED(ID_MYBUTTON, OnButtonClick)//add this line
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
      

  14.   

    这个问题俄vary easy.第一种 在属性中选上自给。然后在派生了子类,再用子类化。
    第二种, 在属性中选上自给,然后还父窗口中处理WM_DRAWITEM
      

  15.   

    A_Qiao()说的情况我考虑到了,但是经过试验不是这样。
      

  16.   

    masterz()的源代码我也试了,还是不能响应任何消息。
      

  17.   

    ShapeRock(单刀侠)提的两种方法,我已经验证了无数遍,不行。
      

  18.   

    Let me have a look at your project.send your project to [email protected]
      

  19.   

    你重载presubclasswindow();没有?
      

  20.   

    masterz()
    OK,我已经发过去了。
      

  21.   

    我是动态创建,不是attach,不需要重载presubclasswindow
      

  22.   

    gstan(潇逍岚风):
    thank you,Email?
      

  23.   

    masterz()
    THANK YOU VERY MUCH!!!!!!!!!!!!!!!!
      

  24.   

    记住要重载virtual void DrawItem(LPDRAWITEMSTRUCT lps)
    函数!!!!!实在不行把你的代码发给我,我给你看看!!!
    [email protected]