我想要做一个按钮,按下去后不弹起,处于选中状态,再按一下才弹起。
想问以下几个问题:
1)应该说可以用CHECK控件采用push-like风格实现,但我的控件不是在资源编辑器中生成,那个push-like该怎么指定?另外我还想在上面显示位图,要控件的大小正好包围位图,其它的地方不显示,该怎么办?
2)或者有没有简单的办法,就用一般的CButton就可以?
3)用CBitmapButton应该可以,但单击时响应有点问题,这个问题我正在发贴提问。

解决方案 »

  1.   

    CMyButton is a class derived from CButton. The CMyButton
    object was created as follows:
     CMyButton myButton;
     myButton.Create(_T("My button"), 
          WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW, 
                                            ~~~~~~~~~~~~~
          CRect(10,10,100,30), pParentWnd, 1);
    void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    {
       UINT uStyle = DFCS_BUTTONPUSH;   // This code only works with buttons.
       ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON);   // If drawing selected, add the pushed style to    
       // DrawFrameControl.You can change here to set 
       // the pushing state of button
       if (lpDrawItemStruct->itemState & ODS_SELECTED)
          uStyle |= DFCS_PUSHED;   // Draw the button frame.
       ::DrawFrameControl(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem, DFC_BUTTON, uStyle);   // Get the button's text.
       CString strText;
       GetWindowText(strText);   // Draw the button text using the text color red.
       COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(255,0,0));
       ::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(), 
          &lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
       ::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
       //also you can draw a bitmap here
    }