Cimagelist ::add//使用的疑惑
BOOL CToolBarEx::SetButtonEx(LPCTSTR lpszResourceName)
{
CClientDC rdc(this);
CDC dc1;
CBitmap bmp1,bmpd;
bmp1.LoadBitmap(lpszResourceName);
dc1.CreateCompatibleDC(&rdc);
dc1.SelectObject(&bmp1);
LPBYTE lpbts;
int ncount=0;
ncount=(bitmap.bmHeight*bitmap.bmWidthBytes);
lpbts=new BYTE[ncount];
bmp1.GetBitmapBits(ncount,lpbts);
bmpd.SetBitmapBits(ncount,lpbts);
m_imglstNormal.DeleteImageList();
m_imglstNormal.Create(m_nButtonWidth, m_nButtonHeight, bitmap.bmBitsPixel|ILC_MASK, 1, 1);
m_imglstNormal.Add(&bmpd, maskcolor);
//为什么换成bmp1;返回0值图片加载成功;但是为什么是黑图呢
bmp1.GetBitmapBits(ncount,lpbts);
bmpd.SetBitmapBits(ncount,lpbts);执行这两步操作 就是彩图!
GetToolBarCtrl().SetImageList(&m_imglstNormal);
delete[] lpbts;
return TRUE;
}
BOOL CGDIxToolBar::LoadToolBar(UINT nIDResource)
{
LPCTSTR lpszResourceName = MAKEINTRESOURCE(nIDResource);
HINSTANCE hInst = AfxFindResourceHandle(lpszResourceName,RT_TOOLBAR);
HRSRC hRsrc = ::FindResource(hInst,lpszResourceName,RT_TOOLBAR);
}
BOOL CGDIxToolBar::LoadBitmap(LPCTSTR lpszResourceName)
{
HINSTANCE hInstImageWell = AfxFindResourceHandle(lpszResourceName,RT_BITMAP);
HRSRC hRsrcImageWell = ::FindResource(hInstImageWell,lpszResourceName,RT_BITMAP);
if(hRsrcImageWell == NULL)
return FALSE;
HGLOBAL hglb;
if((hglb = LoadResource(hInstImageWell,hRsrcImageWell)) == NULL)
return FALSE;
LPBITMAPINFOHEADER lpBitmap = (LPBITMAPINFOHEADER)LockResource(hglb);
if(lpBitmap == NULL)
return NULL;
::FreeResource(hglb);
m_lpszResourceName = lpszResourceName;
SetButtonEx(lpszResourceName);
return TRUE;
}
//对话框与单文档还是一起退了
void CFrameWnd::OnDestroy()
{
DestroyDockBars();
// reset menu to default before final shutdown
if (m_hMenuDefault != NULL && ::GetMenu(m_hWnd) != m_hMenuDefault)
{
::SetMenu(m_hWnd, m_hMenuDefault);
ASSERT(::GetMenu(m_hWnd) == m_hMenuDefault);
}
// Automatically quit when the main window is destroyed.
CWinApp* pApp = AfxGetApp();
if (pApp != NULL && pApp->m_pMainWnd == this && pApp->m_eHelpType == afxWinHelp)
{
// closing the main application window
::WinHelp(m_hWnd, NULL, HELP_QUIT, 0L);
// will call PostQuitMessage in CWnd::OnNcDestroy
}
CWnd::OnDestroy();
}
BOOL CGDIxToolBar::LoadBitmap(LPCTSTR lpszResourceName)
{
return SetButtonEx(lpszResourceName);
}
BOOL CToolBarEx::SetButtonEx(LPCTSTR lpszResourceName)
{
m_imglstNormal.DeleteImageList();
if (!m_imglstNormal.Create(lpszResourceName, m_nButtonWidth, 1, maskcolor))
{
return FALSE;
}
GetToolBarCtrl().SetImageList(&m_imglstNormal);
return TRUE;
}