![]() |
'Popup Dialog Box from Menu' by Doyle Whisenant' |
The Code
The BCX code to create this program is in two sections.
To compile with Pelle's C from command line
porc simple.rc bc simple pocc -W1 -Gd -Go -Ze -Zx -Tx86-coff simple.c polink -release -machine:ix86 -subsystem:windows -OUT:simple.exe simple.obj simple.res
To compile using BCXtoEXE
Just drop the BASIC file and the *.RC filein the same folder and point BCXtoEXE to the BASIC file, check GUI and go! Don't change the file names if using BCXtoEXE!
'************* Simple.bas************************
GUI
"SIMPLE"
GLOBAL
Form1AS
HWND'Form ID
GLOBAL
Button1AS
HWND'Button ID
CONST
ID_Button1=
100
'Button constant that identifies your button
' Do all window and control creation here for your main window
SUB
FORMLOAD Form1=
BCX_FORM
(
"Simple Dialog Box Example"
,111
,190
,197
,145
,349110272
,0
)
AddMenu(
Form1)
Button1=
BCX_BUTTON
(
"Show Dialog"
, Form1, ID_Button1 ,70
,97
,50
,15
)
SendMessage(
Button1, WM_SETFONT, GetStockObject(
DEFAULT_GUI_FONT)
,0
)
CENTER
(
Form1)
SHOW
(
Form1)
END
SUB
' All events for your main window happen here, Menu selections, buttons, etc.
BEGIN
EVENTS
SELECT
CASE
CBMSG
CASE
WM_COMMANDIF
CBCTL
=
ID_Button1THEN
' if your button is pressed...
CALL
Button1_Click(
HIWORD(
wParam)
)
' do this
EXIT
FUNCTION
END
IF
IF
CBCTL
=
ID_MENU1THEN
' if menu item "&Simple Dialog" is pressed...
DialogBox(
BCX_HINSTANCE
,MAKEINTRESOURCE(
100
)
,Form1,SimpleDlg)
EXIT
FUNCTION
END
IF
IF
CBCTL
=
ID_MENU3THEN
' if menu item "&Exit"is pressed...
SendMessage(
Form1, WM_CLOSE,0
,0
)
EXIT
FUNCTION
END
IF
CASE
WM_CLOSE DestroyWindow(
Form1)
'we're done so kill the window
EXIT
FUNCTION
END
SELECT
END
EVENTS
'***************************************************************
' "100" is the constant name for the dialog in the simple.rc file
' "SimpleDlg" is the name of your dialog function below
' "BCX_HINSTANCE" is a global hinstance created by BCX just for you to use
'***************************************************************
SUB
Button1_Click(
nmsgAS
WORD
)
DialogBox(
BCX_HINSTANCE
,MAKEINTRESOURCE(
100
)
,Form1,SimpleDlg)
END
SUB
'***************************************************************
' This is your dialog function
' Note this name is in the "DialogBox" call above. It identifies
' which dialog function is used with the call above
'***************************************************************
FUNCTION
SimpleDlg(
hDlgAS
HWND, Msg, wParam, lParam)
SELECT
CASE
MsgCASE
WM_INITDIALOG' do all initialization here
CASE
WM_COMMANDIF
wParam=
101
THEN
EndDialog(
hDlg,0
)
' if the button with the ID of 101
'(in the simple.rc file) is
' pressed, kill the dialog
CASE
WM_CLOSE EndDialog(
hDlg,0
)
' BANG! We're done ;-)
END
SELECT
FUNCTION
=
0
END
FUNCTION
FUNCTION
AddMenu(
hwndOwnerAS
HWND)
AS
BOOL
CONST
ID_MENU0=
9000
CONST
ID_MENU1=
9001
CONST
ID_MENU2=
9002
CONST
ID_MENU3=
9003
'--------------------------------------------------------------------------
GLOBAL
MainMenuAS
HMENU MainMenu=
CreateMenu(
)
'--------------------------------------------------------------------------
GLOBAL
FileMenuAS
HMENU FileMenu=
CreateMenu(
)
InsertMenu(
MainMenu,0
, MF_POPUP, FileMenu,"&File"
)
AppendMenu(
FileMenu, MF_STRING, ID_MENU1,"&Simple Dialog"
)
AppendMenu(
FileMenu, MF_SEPARATOR,0
,""
)
AppendMenu(
FileMenu, MF_STRING, ID_MENU3,"&Exit"
)
'--------------------------------------------------------------------------
' activate menu
IF
NOT
SetMenu(
hwndOwner, MainMenu)
THEN
FUNCTION
=
FALSEEND
IF
FUNCTION
=
TRUEEND
FUNCTION
'************* End Simple.bas************************
'************* Simple.rc************************ #include <windows.h> 100 DIALOG 131, 95, 160, 100 STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU CAPTION "Simple Dialog" FONT 8, "MS Sans Serif" BEGIN CONTROL "A_Button", 101, "Button", WS_TABSTOP, 57, 68, 40, 14 CONTROL "A_Text", 102, "Static", WS_GROUP, 63, 14, 30, 8 CONTROL "A_Edit", 103, "Edit", ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP, 9, 43, 136, 12 END '************* End Simple.rc********************