我使用下面的代码来设置真彩色工具栏
CBitmap bm;
bm.LoadBitmap(IDB_HOTTOOLBAR);
img.Create(25,24,ILC_COLOR24, 0, 0);
img.SetBkColor(GetSysColor (COLOR_BTNFACE));
img.Add(&bm,RGB(255, 0, 255)); 
m_wndToolBar.GetToolBarCtrl().SetHotImageList(&img);但是本来该是透明的,也就是应该是框架颜色的地方却成了黑色,不知道怎么解决?
img.SetBkColor()似乎不起作用,不论设置什么颜色最后都是黑色

解决方案 »

  1.   

    img.Create(25,24,ILC_COLOR24|ILC_MASK, 0, 0);
    //img.SetBkColor(GetSysColor (COLOR_BTNFACE));不用
    img.Add(&bm,RGB(255, 0, 255)); //保证你的bitmap的mask是RGB(255,0,255)
      

  2.   

    要设置透明,可以使用函数SetLayeredWindowAttributes,它是User32.dll中的函数,在MSDN中是查不到的:
    下面的一个例子是应用到了整个窗口,你可以适当的改正试一试。
    typedef BOOL (WINAPI *_SetLayeredWindowAttributes)(HWND hWnd,COLORREF cr,
    BYTE bAlpha,DWORD dwFlags);
    _SetLayeredWindowAttributes SetLayeredWindowAttributes=NULL;
    SetLayeredWindowAttributes=(_SetLayeredWindowAttributes)GetProcAddress(
    hInst,"SetLayeredWindowAttributes");
    if(!SetLayeredWindowAttributes)
    {
    MessageBox("Load Function Error!");
    return FALSE;
    }
    ::SetWindowLong(m_hWnd,GWL_EXSTYLE, GetWindowLong(m_hWnd,
    GWL_EXSTYLE)^WS_EX_LAYERED);
    SetLayeredWindowAttributes(m_hWnd,0,100,LWA_ALPHA);
    RedrawWindow();