sandyrepope
28-02-2007, 06:09
I've been looking at the examples and am totally lost so I thought I'd ask questions.
Do we have to use dialog before we can use things like buttons?
Once a window is open, what keeps it open?
I hope these questions aren't too silly.
ErosOlmi
28-02-2007, 18:00
Sandy,
to reply to your question I need 2/3 months :D
The best way to learn Windows programming or in general event driven programming is to start with a good book. The only I can suggest is "Programming in Windows" by Charles Petzold. It is an old book but is contains the basis for all Windows programming.
Now back to some practical ... here a base code that created a dialog (or if you prefer a window) with 2 buttons. It will handle few events fired by the dialog.
'---Define modules to be used
uses "UI"
'---Controls ID. Every control must have a unique ID number
%ID_OK = 1
%ID_CANCEL = 2
'---Some global variables
LOCAL hDlg AS long '---Handle of the main dialog
local Msg AS LONG '---Will contain message code fired by dialog
local wParam AS LONG '---Additional param for message
local lParam AS LONG '---Additional param for message
'--- Create a new dialog
DIALOG NEW 0, "What is your name?", -1, -1, 160, 60, _
%WS_DLGFRAME OR %DS_CENTER OR %WS_CAPTION OR %WS_SYSMENU OR %WS_OVERLAPPEDWINDOW, _
0 TO hDlg
'---Add relevant controls
CONTROL ADD BUTTON , hDlg, %ID_OK, "OK", 34, 32, 40, 14, %BS_DEFAULT
CONTROL ADD BUTTON , hDlg, %ID_CANCEL, "Cancel", 84, 32, 40, 14, 0
'--- Display the dialog
DIALOG SHOW modeless hDlg
'---Start of main window message loop
WHILE IsWindow(hDlg)
'---Get the message and fill wParam and lParam
Msg = GetMessage(hDlg, wParam, lParam)
'---Now test the message
SELECT CASE Msg
case %WM_INITDIALOG
'---Message fired at the very beginning when dialog is initialized
case %WM_Command
'---This message is fired when a button or a menu
' (or other controls not worth to mention now)
' is pressend or activated
'---Now we have to check wParam in order to check which control ID sent the message
select case wParam
case %ID_CANCEL
msgbox hDlg, "You pressed Cancel button.\nI will now close this message box and exit from main message loop\n\nBye bye.", %MB_ICONEXCLAMATION
exit while
case %ID_OK
msgbox hDlg, "You pressed OK button.\nI will remain in main message loop.\nScript will continue to run.", %MB_ICONEXCLAMATION
end select
CASE %WM_SYSCOMMAND
'---
SELECT CASE wParam
CASE %SC_CLOSE
'---Message fired when X window button is pressed
EXIT WHILE
END SELECT
case else
end select
wend
'---When WHILE/WEND exits, we have to close dialog.
DIALOG END hDlg
When you create a dialog, you have to maintain and handle a message pump for that window. In thinBasic it is done using a WHILE/WEND loop
As soon as a dialog is created, even if it is not on screen, windows starts to send messages to that window and that window will start to queue messages to be handled. It is programmer responsability to handle dialog messages or discard those not needed.
Using a WHILE/WEND loop is just the thinBasic way to manage dialogs message pumps.
In other languages it is done in different ways (for example using functions pointers to callbacks) so please do not keep this method as universal one.
Ciao
Eros
sandyrepope
28-02-2007, 23:22
Thank you, ErosOlmi. This clears up a lot of things for me. I'm a lot closer to being able to writing a program now using the dialog and controls.
Thanks
Sandy
Michael Hartlef
28-02-2007, 23:27
Hi Sandy,
I can only say, try try try. If you hit a wall, ask ask ask. We are not many here but all are willing to help within the abilities. :)
Michael
Sandy, i wrote a simple forms maker that generates a script for you to flesh out.
Here is the thread with all the development and latest versions:
http://www.codingmonkeys.com/index.php?topic=701.msg4673#msg4673
Version 1.4 is the last and it also has a wmv overview of new features.
You might want to watch the videos to see how the older functions worked.