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:
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):
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%)
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 “GetModuleHandle” with a call to “LoadLibrary” as follows:
SYS "LoadLibrary", "EXAMPLE.DLL" TO hmod%
You can embed one or more resources in your own compiled executable as follows:
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 “REM!Resource” directive:
REM!Exefile @dir$+"myprog.exe",encrypt REM!Resource @dir$+"mydialog.res"
Then you can access the resource from the 'real' program as follows:
SYS "LoadLibrary", @dir$+"myprog.exe" TO hmod%
When you eventually compile your program, containing the resources in its EXE file, this will still work.