Hi,
I am trying to create a custom toolbar. I am doing this by creating a
bitmap, blitting images to the bitmap, and then calling SetBitmap on the
command bar. This works when I run it on a 240x320 Pocket PC. However, when
I try running it on a VGA Pocket PC (480x640) the images do not show up.
When I run it in debug mode I get a debug Assertion Failure in the MFC
library. When I run in debug mode on a 240x320 Pocket PC I do not get any
debug assertion failures.
The assertion that fails is in CToolBar::AssertValid and it is
ASSERT(m_hbmImageWell == NULL ||
(afxData.bWin95 || ::GetObjectType(m_hbmImageWell) == OBJ_BITMAP));
To get the custom toolbar to work I did the following
1. Create the bitmap
//mBmp is a CBitmap object and bmpWidth is the number of buttons
//on the toolbar times the width of each button.
mBmp.CreateCompatibleBitmapGetDC(), bmpWidth, btnHeight);
2. Add the buttons. For each button I did
CDC bmpCDC1;
CBitmap bmp1;
CDC bmpCDC;
bmpCDC.CreateCompatibleDC(GetDC());
bmpCDC.SelectObject(&mBmp);
bmpCDC1.CreateCompatibleDC(GetDC());
//imgRscId is the resource ID of the image to put on the toolbar
bmp1.LoadBitmap(imgRscId);
bmpCDC1.SelectObject(&bmp1);
short btnWidth = GetButtonWidth();
short btnHeight = GetButtonHeight();
short btnX = btnWidth * mNumButtons;
bmpCDC.BitBlt(btnX,0,btnWidth,btnHeight,&bmpCDC1,0,0,SRCCOPY);
3. Once all of the buttons have been added I load the toolbar
short btnWidth = GetButtonWidth();
short btnHeight = GetButtonHeight();
//mToolbar is the CCeCommandBar object
mToolbar->SetBitmap((HBITMAP)mBmp.Detach());
//mCmds is an array of the command to push in the message queue for
//each button
mToolbar->SetButtons(mCmds, mNumButtons);
CSize btnSize(btnWidth + 7, btnHeight + 6);
mToolbar->SetSizes(btnSize, CSize(btnWidth, btnHeight));
Does anyone have any idea why this would work for 240x320 PocketPcs but no
for 480x640 PocketPCs?
Thanks,
Stephen