User Tools

Site Tools


creating_20a_20menu_20from_20a_20resource

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
creating_20a_20menu_20from_20a_20resource [2018/03/31 13:19] – external edit 127.0.0.1creating_20a_20menu_20from_20a_20resource [2024/01/05 00:22] (current) – external edit 127.0.0.1
Line 1: Line 1:
 =====Creating a menu from a resource===== =====Creating a menu from a resource=====
  
-//by Jon Ripley, June 2006//\\ \\  The normal method of creating a menu is to use the Windows API functions "CreateMenu", "CreatePopupMenu" and "AppendMenu" to create a menu structure:\\ +//by Jon Ripley, June 2006//\\ \\  The normal method of creating a menu is to use the Windows API functions "CreateMenu", "CreatePopupMenu" and "AppendMenu" to create a menu structure: 
 + 
 +<code bb4w>
         SYS "CreatePopupMenu" TO m_file%         SYS "CreatePopupMenu" TO m_file%
         SYS "AppendMenu", m_file%, 0, 100, "&New"+CHR$9+"Ctrl+N"         SYS "AppendMenu", m_file%, 0, 100, "&New"+CHR$9+"Ctrl+N"
Line 13: Line 15:
         SYS "SetMenu", @hwnd%, m_main%         SYS "SetMenu", @hwnd%, m_main%
         SYS "DrawMenuBar", @hwnd%         SYS "DrawMenuBar", @hwnd%
-\\  However there may be circumstances when the menu has already been designed and its template is contained as a //resource// within a DLL or EXE file. In that case you can create the menu in your program using the resource data. The code example below creates a menu from the resource data for the BB4W IDE menu (in BBCWIN.EXE or BBCWDEM.EXE):\\ +</code> 
 + 
 +However there may be circumstances when the menu has already been designed and its template is contained as a //resource// within a DLL or EXE file. In that case you can create the menu in your program using the resource data. The code example below creates a menu from the resource data for the BB4W IDE menu (in BBCWIN.EXE or BBCWDEM.EXE): 
 + 
 +<code bb4w>
         REM Acquire handle to BBCWIN.EXE or BBCWDEM.EXE         REM Acquire handle to BBCWIN.EXE or BBCWDEM.EXE
         SYS "GetModuleHandle", 0 TO hmod%         SYS "GetModuleHandle", 0 TO hmod%
Line 29: Line 35:
         REM Destroy the menu and free used memory         REM Destroy the menu and free used memory
         SYS "DestroyMenu", hmenu% TO ret%         SYS "DestroyMenu", hmenu% TO ret%
-Naturally this code will only run within the **BB4W IDE**, because if compiled to an executable file the menu resource data will not be present.\\ \\  To load the menu resource data from a different file (for example a DLL) then replace the call to "GetModuleHandle" with a call to "LoadLibrary" as follows:\\ +</code> 
 + 
 +Naturally this code will only run within the **BB4W IDE**, because if compiled to an executable file the menu resource data will not be present.\\ \\  To load the menu resource data from a different file (for example a DLL) then replace the call to "GetModuleHandle" with a call to "LoadLibrary" as follows: 
 + 
 +<code bb4w>
         SYS "LoadLibrary", "EXAMPLE.DLL" TO hmod%         SYS "LoadLibrary", "EXAMPLE.DLL" TO hmod%
 +</code>
creating_20a_20menu_20from_20a_20resource.1522502352.txt.gz · Last modified: 2024/01/05 00:18 (external edit)