Re: Win32lib menus
- Posted by Don Phillips <Graebel at hotmail.com> Jun 18, 2002
- 487 views
>Thanks Derek, for that little lesson in win32lib modification. >Works great !. > >... and Dan, that first '!' doesn't show up in the menubar, it's only a tag >to tell win32lib that you want to create a >top level 'command' menu, in the same fashion that '&' is used to indicate >the ( underlined ) keyboard shortcut in >menu's. > >Wolf Perhaps it is just me, but anything that needs to modify Win32Lib directly (imho) is just coded wrong. Makes it very hard to pass code around to other people if your version of Win32Lib is custom... Anyways. On my system (Win 2k) I put together this code (just now) and it seems to run just fine. If you call this function, a new menu command item will be created and a WM_COMMAND message will be sent to the parent window when it is clicked. Enjoy. -=-=-=-=-=-=-=-=-=-=-=-=- constant xSetMenuItemInfo = registerw32Function( user32, "SetMenuItemInfoA", {C_POINTER,C_LONG,C_LONG,C_POINTER}, C_LONG ) -- create command menu item function createCMI( sequence Caption, atom ParentID ) atom NewMenuItem atom hMenu, MenuCount atom lpmii atom MenuID atom MenuText atom TextBuffer atom Void NewMenuItem = create( Menu, Caption, ParentID, 0, 0, 0, 0, 0 ) hMenu = w32Func( xGetMenu, {getHandle(ParentID)} ) MenuCount = w32Func( xGetMenuItemCount, {hMenu} ) MenuText = allocate_string( Caption ) TextBuffer = allocate( length(Caption)+1 ) for MenuIter = 0 to MenuCount-1 do mem_set( TextBuffer, 0, length(Caption) ) Void = w32Func( xGetMenuString, {hMenu,MenuIter,TextBuffer,length(Caption)+1,#400} ) if compare( peek({TextBuffer,length(Caption)}), Caption ) = 0 then MenuID = MenuIter end if end for free( MenuText ) free( TextBuffer ) lpmii = allocate( 44 ) mem_set( lpmii, 0, 44 ) poke4( lpmii, {44,#4} ) Void = w32Func( xSetMenuItemInfo, {hMenu,MenuID,1,lpmii} ) free( lpmii ) return( NewMenuItem ) end function HelpMenu = createCMI( "&Help", hWin ) -=-=-=-=-=-=-=-=-=-=-=-=-