Re: bitmaps in menus



On Thu, 6 Jul 2006 08:57:07 +0200, "Lars" <no_spam@xxxxxxxxxxxxxxx>
wrote:

When I define a menuitem from a resource, I use this code:

I_IMAGENONE, 120, TBSTATE_ENABLED, TBSTYLE_AUTOSIZE, 203, 0, 0,

The string is defined by 203 value, from a stringtable.

How to use a bitmap instead of a string ? Thanks

I use the following function. This version works for all Windows CE
platforms; I have another version for "big" Windows. I edited out some
of my specialized tools, but didn't bother to eliminate all. I can't
provide more detail or explanation (too much and/or proprietary). So
you will need to work a bit to extract what is useful for you.


// ----------------------------------------------------------
// AddButton
BOOL ClsPFCommandBar::AddButton( int nID, LPCTSTR sBitMapName, int
nBitMap, BOOL bIsPopup, HINSTANCE hInst )
{
// See thread called "Pocket PC Toolbars (Transparent icons on
white background)"
// started 8 Mar 2001 by Peter Koch in
microsoft.public.pocketpc.developer
// From a 24 May 2004 contribution by Almon B. Strowger to thread
called
// "TB_SETBUTTONINFO does not update tool button bitmap image
immediately" in
// microsoft.public.windowsce.app.development (in response to a
question about
// updating a bitmap of a tool button):
// "MenuBars in Pocket PC are a bastardized contrivance
// which lead to a lot of confusion.
// For info about possibly invisible toolbar buttons (at least
under Pocket PC 2003
// Compact Framework), see 29 Apr - 2 May 2005 thread called
// "toolbar buttons in windows mobile 2003 sp2" in
microsoft.public.pocketpc.developer
//
// Try using:
// CommandBar_DrawMenuBar( hwndCB, 0 );

#if 1
// Enabled for all (CE) builds 19 May 05 (7.7.0.31)
// getItemCount gets number of buttons already in menu
int nPosBefore = getItemCount( m_hMenu ); // 22 Apr 05
(7.7.0.28)
#endif

// Help files mention only 6 fields, but typedef in CommCtrl.h
shows 7,
// (including bReserved). Samples generally show 6 initializers.
BZ
// decided to be safe, by being explicit
TBBUTTON tButton[1];

tButton[0].iBitmap = nBitMap;
tButton[0].idCommand = nID;
tButton[0].fsState = TBSTATE_ENABLED;
tButton[0].fsStyle = TBSTYLE_BUTTON;
tButton[0].dwData = 0;
tButton[0].iString = 0;

// FOR_PocketPC is a macro defined elsewhere that I use for
// compile-time control
#ifdef FOR_PocketPC
// 22 Nov 05 (7.7.0.50)
// Kludge for WM 5
// GetOSVersionD is my function to get double representing OS
version number
if (ClsPFGeneralInfo::GetOSVersionD() >= 5.0)
tButton[0].iBitmap--;
#endif


// Must explicitly call LoadBitmap (using string as arg), and must
then use NULL as HINST
// in CommandBar_AddBitmap
if (hInst == NULL)
hInst = ClsPFRoot::GetGenInfoP()->GetHinst();
int n = 0;
for ( ; n < m_nBMap; n++)
{
if (m_pfBMapName[n].SameString( sBitMapName ))
break;
}
ASSERT( n <= m_nBMap );
if (n == m_nBMap)
{
// New bitmap
TEST_VALID( static_cast<size_t>(m_nBMap) <= PFMDim( m_hBMap )
- 1 );
m_hBMap[m_nBMap] = ::LoadBitmap( hInst, sBitMapName );
m_pfBMapName[m_nBMap] = sBitMapName;
n = ::CommandBar_AddBitmap( m_hWnd, NULL,
reinterpret_cast<int>(m_hBMap[m_nBMap]),
1, 16, 16 );
//lint -esym( 529, n ) not subsequently referenced
ASSERT_EXPLAIN( n == m_nBMap );
m_nBMap++;
}

int iButton = 0;
for ( ; iButton < m_clsButtons.GetCount(); iButton++)
{
if (m_clsButtons[iButton].nID == nID)
break;
}
if (iButton == m_clsButtons.GetCount())
{
// New slot
VERIFY( m_clsButtons.FoundAnother() );
}
#if ISDEBUG
else
{
ASSERT( iButton < m_clsButtons.GetCount() );
}
#endif
m_clsButtons[iButton].nID = nID;
m_clsButtons[iButton].nPos = nPosBefore + iButton; // Count
before adding is current position
m_clsButtons[iButton].hMenu = bIsPopup ? ::CreatePopupMenu() :
NULL;

BOOL bRc = ::CommandBar_AddButtons( m_hWnd, 1, tButton );
ASSERT_EXPLAIN( bRc );

return bRc;

} // AddButton




-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 478
Boston, MA 02116
www.penfact.com
.


Loading