Creating+a+dialogue+box+from+a+resource

//by Richard Russell, May 2006, revised April 2012//

The normal method of creating a dialogue box in BBC BASIC for Windows is to call the procedures in the **WINLIB2** library:
 * PROC_pushbutton
 * PROC_checkbox
 * PROC_radiobutton
 * PROC_editbox
 * PROC_static
 * PROC_listbox
 * PROC_combobox
 * PROC_dlgitem
 * PROC_dlgctrl

However there may be circumstances when the dialogue box 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 dialogue box in your program using the resource data. The code example below creates a dialogue box from the resource data for BB4W's **Customize** dialogue (in BBCWIN.EXE or BBCWDEM.EXE):

code format="bb4w" INSTALL @lib$+"WINLIB2" REM Acquire handle to BBCWIN.EXE or BBCWDEM.EXE: SYS "GetModuleHandle", 0 TO hmod% REM Locate specific dialog box resource: SYS "FindResource", hmod%, "CustomizeDlg", 5 TO hres% REM Load dialogue template into memory: SYS "LoadResource", hmod%, hres% TO hload% SYS "LockResource", hload% TO hmem% REM Find size of template: SYS "SizeofResource", hmod%, hres% TO rsize% dlg% = FN_newdialog("",0,0,0,0,0,rsize%+16) REM Copy dialogue template into dlg% array: SYS "RtlMoveMemory", dlg%+16, hmem%, rsize% REM Display dialogue box: dlg%?19 OR= &10 : REM Add WS_VISIBLE style PROC_showdialog(dlg%) code Naturally this code will only run within the **BB4W IDE**, because if compiled to an executable file the dialogue box resource data will not be present.

To load the dialogue box resource data from a different file (for example a DLL) then replace the call to with a call to  as follows: code format="bb4w" SYS "LoadLibrary", "EXAMPLE.DLL" TO hmod% code You can embed one or more resources in your own compiled executable as follows:
 * 1) Create the resource in 'Resource Compiler' (**.RC**) format.
 * 2) Compile the resource from a **.RC** file to a **.RES** file using a Resource Compiler.
 * 3) Specify that the resource should be embedded in your program using **REM!Resource**.

To enable you to develop and test your program in the BB4W IDE you can initially create a 'dummy' executable, by compiling a program containing only the directive: code format="bb4w" REM!Exefile @dir$+"myprog.exe",encrypt REM!Resource @dir$+"mydialog.res" code Then you can access the resource from the 'real' program as follows: code format="bb4w" SYS "LoadLibrary", @dir$+"myprog.exe" TO hmod% code When you eventually compile your program, containing the resources in its EXE file, this will still work.