按照一般的方法,给Button 添加位图有缺点,就是button 的位置会变化。
我试了不少方法,都无法做到好的效果。
除了编写ActiveX控件,谁还后别的法子?

解决方案 »

  1.   

    建立一个叫IDI_ICON1的ICON资源
    HICON hicon = AfxGetApp()->LoadIcon(IDI_ICON1);
    m_button1.SetIcon(hicon);
      

  2.   

    I tried that.But I failed.
    I believe that if you create a button using function Create(...),then use SetIcon(),you can do it,but if you put a button control on a dialog ,then try to put a picture on it ,I think you can't use SetIcon().What's more,We can get true color using bmp.While using  .ico,there are less color a button surface can hold.
      

  3.   

    I now can do it according to your method.
    Give you score!
      

  4.   

    But it is not beautiful,I want the background to be transparent
      

  5.   

    请参考CBUTTONST的例子
    vckbase.com
      

  6.   

    看看msdn,可以使用CBitmapButton这个类,具体使用方法参照msdn
    To create a bitmap-button control in a window's client area Create one to four bitmap images for the button. 
    Construct the CBitmapButton object. 
    Call the Create function to create the Windows button control and attach it to the CBitmapButton object. 
    Call the LoadBitmaps member function to load the bitmap resources after the bitmap button is constructed. 
      

  7.   

    第一,构造CBitmapButton对象:
    // Declare a bitmap button object on the stack.
    CBitmapButton myButton;// Declare a bitmap button object on the heap.
    CBitmapButton* pmyButton = new CBitmapButton;CButton myButton1, myButton2, myButton3, myButton4;第二,创建windows button控件与CBitmaButton关联
    // Create a push button.
    myButton1.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, 
       CRect(10,10,100,30), pParentWnd, 1);// Create a radio button.
    myButton2.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_RADIOBUTTON, 
       CRect(10,40,100,70), pParentWnd, 2);// Create an auto 3-state button.
    myButton3.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_AUTO3STATE, 
       CRect(10,70,100,100), pParentWnd, 3);// Create an auto check box.
    myButton4.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX, 
       CRect(10,100,100,130), pParentWnd, 4);
    第三,调用LoadBitmaps()装载bitmap资源
    CBitmapButton myButton;// Create the bitmap button (must include the BS_OWNERDRAW style).
    myButton.Create(NULL, WS_CHILD|WS_VISIBLE|BS_OWNERDRAW, 
       CRect(10,10,100,100), pParentWnd, 1);// Load the bitmaps for this button.
    myButton.LoadBitmaps(IDB_UP, IDB_DOWN, IDB_FOCUS, IDB_DISABLE);