我继承了Cbutton类自绘按扭,
UINT style = this->GetButtonStyle();
UINT format = DT_VCENTER |DT_SINGLELINE;
if(style & BS_CENTER )
format |= DT_CENTER;
else if(style & BS_LEFT)
format |= DT_LEFT; pDC->DrawText(text,rcText,format);
无法判断类型,请帮忙看看

解决方案 »

  1.   

    你的类型错了,CButton的类型有
    BS_3STATE   Same as a check box, except that the box can be dimmed as well as checked. The dimmed state typically is used to show that a check box has been disabled.BS_AUTO3STATE   Same as a three-state check box, except that the box changes its state when the user selects it.BS_AUTOCHECKBOX   Same as a check box, except that a check  appears in the check box when the user selects the box; the check  disappears the next time the user selects the box.BS_AUTORADIOBUTTON   Same as a radio button, except that when the user selects it, the button automatically highlights itself and removes the selection from any other radio buttons with the same style in the same group.BS_BITMAP   Specifies that the button displays a bitmap. BS_BOTTOM   Places text at the bottom of the button rectangle. BS_CENTER   Centers text horizontally in the button rectangle. BS_CHECKBOX   Creates a small square that has text displayed to its right (unless this style is combined with the BS_LEFTTEXT style).BS_DEFPUSHBUTTON   Creates a button that has a heavy black border. The user can select this button by pressing the ENTER key. This style enables the user to quickly select the most likely option (the default option).BS_FLAT   Specifies that the button is two-dimensional; it does not use the default shading to create a 3-D image. BS_GROUPBOX   Creates a rectangle in which other buttons can be grouped. Any text associated with this style is displayed in the rectangle's upper-left corner.BS_ICON   Specifies that the button displays an icon. BS_LEFT   Left aligns the text in the button rectangle. However, if the button is a check box or radio button that does not have the BS_RIGHTBUTTON style, the text is left aligned on the right side of the check box or radio button. BS_LEFTTEXT   When combined with a radio-button or check-box style, the text appears on the left side of the radio button or check box.BS_MULTILINE   Wraps the button text to multiple lines if the text string is too long to fit on a single line in the button rectangle. BS_NOTIFY   Enables a button to send BN_DBLCLK, BN_KILLFOCUS, and BN_SETFOCUS notification messages to its parent window. Note that buttons send the BN_CLICKED notification message regardless of whether it has this style. BS_OWNERDRAW   Creates an owner-drawn button. The framework calls the DrawItem member function when a visual aspect of the button has changed. This style must be set when using the CBitmapButton class.BS_PUSHBUTTON   Creates a pushbutton that posts a WM_COMMAND message to the owner window when the user selects the button.BS_PUSHLIKE   Makes a button (such as a check box, three-state check box, or radio button) look and act like a push button. The button looks raised when it isn't pushed or checked, and sunken when it is pushed or checked. BS_RADIOBUTTON   Creates a small circle that has text displayed to its right (unless this style is combined with the BS_LEFTTEXT style). Radio buttons are usually used in groups of related, but mutually exclusive, choices.BS_RIGHT   Right aligns the text in the button rectangle. However, if the button is a check box or radio button that does not have the BS_RIGHTBUTTON style, the text is right aligned on the right side of the check box or radio button. BS_RIGHTBUTTON   Positions a radio button's circle or a check box's square on the right side of the button rectangle. Same as the BS_LEFTTEXT style. BS_TEXT   Specifies that the button displays text. BS_TOP   Places text at the top of the button rectangle. BS_USERBUTTON   Obsolete, but provided for compatibility with 16-bit versions of Windows. Win32-based applications should use BS_OWNERDRAW instead. BS_VCENTER   Places text in the middle (vertically) of the button rectangle.
      

  2.   

    switch (style & BS_CENTER)
    {
    case BS_LEFT:
    format |= DT_LEFT;
    break;
    case BS_RIGHT:
    format |= DT_RIGHT;
    break;
    default:
    format |= DT_CENTER;
    }
      

  3.   

    to cnzdgs:
    不行,style = 0x0000008b
    我是在对话框资源中建立的按扭.添加了一个CButton的变量,把CButton 换成我的自绘类.ModifyStyle(0, BS_OWNERDRAW);
    是不是有了BS_OWNERDRAW风格,
    我在资源中改变文本左右布局,总是style = 0x0000008b
    这个值.
      

  4.   

    要自绘按钮的话,就应该使用DRAWITEMSTRUCT结构与响应WM_DRAWITEM消息,你这样简单地判断并设置按钮的属性不是很好的方法。