Dynamic menus in eVC without resources
- From: r_z_aret@xxxxxxxxxxxx
- Date: Thu, 28 Apr 2005 17:35:26 -0400
Several folks, including me, have discussed attempts to add menus to a
dialog box in Pocket PC without using resources. In my case, I want to
support dialog boxes created completely in a statically linked
library. Well, I finally stumbled on a decent workaround: a toolbar.
Seems somewhat obvious in hind sight. The code for handling menu items
is the same as for any other menu. Here's the main section of code I
use to create a toolbar. I left it completely unedited. I can't
provide more details (too much specialized and/or proprietary code),
but I think the names I use should be clear enough:
First ,my definition of g_kiMenuHeight
#if defined( FOR_PocketPC )
// ::GetSystemMetrics( SM_CYMENU ) returns 23, which is too small
// SM_CYMENUSIZE is not defined for Windows CE 3.0 and newer
// 26 from Shell sample for eVT; also from p. 776 of Boling 2nd
Edition, and
// 16 Aug 2000 contribution from Gary Peluso to thread called "Full
Size PocketPC Dialogs"
// in microsoft.public.windowsce.app.development
// 15 Aug 03 contribution from Tim Wilson to thread called "menu
height?"
// in microsoft.public.pocketpc.developer suggested using
SystemInformation, but
// BZ found that SystemInformation is part of .NET
const g_kiMenuHeight = 26;
#elif defined( FOR_Smartphone)
// 24 seems to be the right value (BZ guestimate) 25 Mar 04 (4.0.0.59)
const g_kiMenuHeight = 24;
#endif
then the code
// 13 Feb 05 (7.7.0.21)
// use ToolBar
// See 20-24 Feb 04 called "SHCreateMenuBar() without a
resource file" in
// microsoft.public.pocketpc.developer. In particular, see 20
Feb 04
// contribution from Almond Stowger for ideas adapated here.
Also, a
// 19 Feb 04 contribution from Eddy Escardo says:
// SHCreateMenuBar does not currently support
programatically
// generated HMENUs, as the SHCMBF_HMENU flag just means
that
// nToolBarId will represent the ID of a menu in a
compiled
// resource module, not an actual HMENU that you can pass
to
// the SHCreateMenuBar call (as you've probably figured
out by now).
// 13 Feb 05
// Adapted from 19 April 2001 contribution by Alex Blekhman to
thread
// called "Toolbar help please" in
comp.os.ms-windows.programmer.win32
#if 0
// From reference
DWORD dwStyle = CCS_NODIVIDER | CCS_NOPARENTALIGN |
CCS_NORESIZE |
TBSTYLE_FLAT | TBSTYLE_LIST |
TBSTYLE_TOOLTIPS |
WS_CHILD | WS_CLIPCHILDREN |
WS_CLIPSIBLINGS | WS_VISIBLE;
#else
DWORD dwStyle = CCS_NODIVIDER | CCS_NOPARENTALIGN |
CCS_NORESIZE |
TBSTYLE_FLAT | TBSTYLE_LIST |
WS_CHILD | WS_VISIBLE;
#endif
ASSERT( m_nID != 0 ); // Should be set by initInternal
VERIFY( PFInitCCCommandBar() );
m_hWnd = CreateWindowEx(
0, // DWORD dwExStyle
TOOLBARCLASSNAME, // LPCTSTR
lpClassName
NULL, // LPCTSTR
lpWindowName
dwStyle, // DWORD dwStyle
ClsPFDialogBox::Gap(),
0,
// BZ added WS_BORDER to styles (to make edges
visible), then experimented
// with x and width. Multiplier needed on right for
symmetry depended on
// whether CS_NORESIZE was included in styles
// 5 with CS_NORESIZE
// 7 without CS_NORESIZE
// TODO: Why?
::GetSystemMetrics( SM_CXSCREEN ) -
(ClsPFDialogBox::Gap() * 5),
g_kiMenuHeight,
m_hWndParent,
reinterpret_cast<HMENU>(m_nID), //
HMENU hMenu
m_hInstance, // HINSTANCE
hInstance
NULL // LPVOID lpParam
);
ASSERT( IsWindow() );
ASSERT( pMenu != NULL );
m_sClassName = TOOLBARCLASSNAME; // keep Validate happy
IGNORE_RETURN( PFWSendMessage( TB_BUTTONSTRUCTSIZE, sizeof(
TBBUTTON ), 0 ) );
#if 0
// Enable to make labels bold
m_hFont = PFWGetFontFromSpacing( g_kiMenuHeight, 50, TRUE );
SetFont( m_hFont );
#endif
m_bIsToolBar = TRUE;
VERIFY( BuildFromStruct( pMenu ) );
#if 0
// Seemed to have no effect, so ommited
IGNORE_RETURN( PFWSendMessage( TB_AUTOSIZE, 0, 0 ) );
#endif
}
-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).
Robert E. Zaret, eMVP
PenFact, Inc.
500 Harrison Ave., Suite 3R
Boston, MA 02118
www.penfact.com
.
- Prev by Date: Re: SOCKETS
- Next by Date: Re: Sprint PPC-6600 Development
- Previous by thread: windows ce 5.0
- Next by thread: RE: TAPI on PocketPC problem
- Index(es):