bool GDIxToolBar::SetButtonEx(LPCTSTR lpszResourceName)
{

CBitmap bmpBk;
BITMAP bmpSize;
//加载的工具栏资源,工具栏资源无法是Png,这里加载是获取工具栏的高*宽
bmpBk.LoadBitmap(lpszResourceName); bmpBk.GetBitmap(&bmpSize);
CClientDC rdc(this); CDC dcNor,dcHV;
CBitmap bmpNor,bmpHV,bmplast;
CRect m_nHV;
m_nHV.top = m_nHV.left = 0;

if(m_dwStyle & CBRS_ORIENT_HORZ)//判断是横或竖的 工具栏
{
m_nHV.right = m_ButtonSize.cx * m_nButtonCount+6 * m_nSeparatorCount;
m_nHV.bottom = m_ButtonSize.cy;
}
else
{
m_nHV.right = m_ButtonSize.cx;
m_nHV.bottom = m_ButtonSize.cy * m_nButtonCount+6 * m_nSeparatorCount;
}

dcNor.CreateCompatibleDC(&rdc);
dcHV.CreateCompatibleDC(&rdc); int totalbuttons=m_nButtonCount+m_nSeparatorCount;
int buttonindex=0;
int btnindex=0;

bmpNor.CreateBitmap(bmpSize.bmWidth,bmpSize.bmHeight,1,bmpSize.bmBitsPixel,NULL); 
bmpHV.CreateBitmap(m_nHV.right,m_nHV.bottom,1,bmpSize.bmBitsPixel,NULL);
bmplast.CreateBitmap(bmpSize.bmWidth,bmpSize.bmHeight,1,bmpSize.bmBitsPixel,NULL); dcNor.SelectObject(&bmpNor); 
dcHV. SelectObject(&bmpHV); 

//这是封装GDI+操作类 加载俩张png图片  
         //GdipDraw*  imageState[4];
imageState[0] = new GdipDraw(dcHV.m_hDC,m_nHV.right,m_nHV.bottom);
imageState[0]->DrawImage(imageDest[0]);
imageState[0]->DrawImage(imageDest[1]);
imageState[0]->CopyTo(dcHV.m_hDC,m_nHV.right,m_nHV.bottom); for(buttonindex=0,btnindex=0;buttonindex<totalbuttons;buttonindex++)
{
    if(0==m_pbtButtonStyle[buttonindex])//如果是分隔符跳过 ,不进行拷贝//在LoadBar函数里有区分!
{
if (m_dwStyle & CBRS_ORIENT_HORZ)
dcNor.BitBlt(btnindex*m_nButtonWidth,0,m_nButtonWidth,m_nButtonHeight,&dcHV,btnindex*m_ButtonSize.cx+6*(buttonindex-btnindex)+3,3,SRCCOPY);
else if(m_dwStyle & CBRS_ORIENT_VERT)
dcNor.BitBlt(btnindex*m_nButtonWidth,0,m_nButtonWidth,m_nButtonHeight,&dcHV,3,btnindex*m_ButtonSize.cy+6*(buttonindex-btnindex)+3,SRCCOPY);
btnindex++;
}
}


int ncount = (bmpSize.bmHeight*bmpSize.bmWidthBytes);  
lpbts=new BYTE[ncount];
bmpNor.GetBitmapBits(ncount,lpbts); 
bmplast.SetBitmapBits(ncount,lpbts);//获取带有png属性的位图 m_imglstNormal.DeleteImageList(); //m_imglstNormal是成员变量
m_imglstNormal.Create(m_nButtonWidth, m_nButtonHeight,bmpSize.bmBitsPixel|ILC_MASK, 1, 1);
m_imglstNormal.Add(&bmplast,RGB(254,0,254));
GetToolBarCtrl().SetImageList(&m_imglstNormal);

delete[] lpbts;
        return TRUE;
}Image* imageDest[2];void GDIxToolBar::SetImageEx(Image* BK,Image* FG)
{
    imageDest[0] = BK;//图片加载成功!
    imageDest[1] = FG;
    tBrush = new TextureBrush(imageDest[0]);
    DestroyMemDC();
}private:
HDC hMemDC;
HBITMAP hOldBitmap;
int width;
int height;
public:
HBITMAP hBitmap;
GdipDraw::GdipDraw( HDC hDC,int w,int h )
:hMemDC(NULL)
,hBitmap(NULL)
,hOldBitmap(NULL)
,width(0)
,height(0)
{
Create(hDC,w,h);
}bool GdipDraw::Create( HDC hDC,int w,int h )
{
Destroy(); if(hDC == 0 || w <= 0 || h <= 0) 
return false; hBitmap = ::CreateCompatibleBitmap(hDC,w,h);
//BitSave.Attach(hBitmap);
if(hBitmap == 0) return false; hMemDC = ::CreateCompatibleDC(hDC);
if(hMemDC == 0)
{
::DeleteObject(hBitmap);
hBitmap = 0;
return false;
} hOldBitmap = (HBITMAP)::SelectObject(hMemDC,hBitmap);
width = w;
height = h; return true;
}bool GdipDraw::DrawImage( Image *image )
{
if(image == 0 || hMemDC == 0) 
return false; Gdiplus::Graphics graphics(hMemDC);
return graphics.DrawImage(image,0,0,width,height) == Gdiplus::Ok;
}
bool GdipDraw::CopyTo(HDC hDC,int x /*= 0*/,int y /*= 0*/)
{
if(hDC == 0 || hMemDC == 0) 
return false; return ::BitBlt(hDC,x,y,width,height,hMemDC,0,0,SRCCOPY) == TRUE;
}