You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
I looked at the Cool.bas program, but now I have a greater source of confusion. I've been developing an app using the DDT functions, which seems very straightforward, but when I look at Cool.bas and other examples such as code generated by PBGEN, I see a lot of code that looks unfamiliar, which seems to revolve around one particular little segment:
WHILE GetMessage(Msg, %NULL, 0, 0)
TranslateMessage Msg
DispatchMessage Msg
Wend
Being a newby to PB and Windows programming (other than VB, which didn't require this level of knowledge), I'm having difficulty understanding what this does, and how the timer example in cool.bas relates to the type of program developed with DDT, which doesn't have any of these constructs in it.
#Compile Exe
#Register None
#Dim All
#Include "Win32Api.INC"
CallBack Function Dlg_CB
Select Case CbMsg
Case %WM_INITDIALOG: SetTimer CbHndl, 1, 2000, ByVal %NULL
' Every 2 seconds
Case %WM_TIMER
Control Set Text CbHndl, 201, "Time: " + Time$
Case %WM_DESTROY: KillTimer CbHndl, 1
End Select
End Function
Function PbMain () As Long
Local HDLG As Long
Dialog New 0, "Test", 1, 1, 80, 30, %DS_CENTER Or _
%WS_CAPTION Or %WS_SYSMENU, 0 To HDLG
Control Add Label, Hdlg, 201, "", 10, 10, 80, 14
Dialog Show Modal HDLG, Call Dlg_CB
End Function
That's perfect! I was reading some of the discussion on the forum about DDT vs. Dialogs from Resource Editors etc. and I think I'm slowly starting to grasp the differences between the two approaches. I will be buying a book or two on Windows programming, which may help.
The GetMessage() loop (known as a "message pump" loop) is always required when you create GUI windows using raw API calls such as CreateWindow(), CreateWindowEx(), etc. You may also see it implemented with a call to PeekMessage().
A message pump works by reading messages from the application's message queue, and (depending on the type of message) dispatches each message to the appropriate callback function (via the TranslateMessage() and DispatchMessage() API calls).
When you use a modal dialog, you are really using a special window class that is handled internally by Windows dialog engine - IOW, it provides it's own message pump and dispatches messages to your dialog callback, etc. When you use a modal DDT dialog, it also handles the message pump itself in the same way.
However, modeless dialogs are different - they require the application to handle the message pump itself, which is why a DDT modeless dialog needs to have a DIALOG DOEVENTS loop. DIALOG DOEVENTS is a "wrapper" for a PeekMessage().
In recent times, Semem has been experimenting with providing a message pump for his modeless DDT dialogs that uses the raw message handling API's, rather than the DIALOG DOEVENTS statement. This is a neat trick which enables the application to intercept certain messages that the DDT engine "filters" out, such as %WM_KEYUP, etc. So far this approach seems to work well, but it is (to date) an unofficial technique. The example code Semen posted above just uses the built-in model dialog message pump.
To go a little deeper, there are messages that do not go through the message pump - these are known as "non-queued messages", and are messages like %WM_PAINT, etc.
Confused? It's hard to give an indepth explanation on such a 'complex' part of Windows operations. A good book such as Petzold or Rector/Newcomer will explain all of this in great depth - see the FAQ forum for a list of recommended titles and ISBN numbers.
PS: once you read one of these books, you'll also find out that a modal dialog is really a modeless dialog with a twist!
Obviously, I've been living in the sheltered world of VBLand for too long, where the messaging is just a bunch of hidden "black magic" that happens somehow.
Thanks for all the information - I'm sure I'll be back with more questions after I dig deeper into PB and get some reading done.
So here's a DDT sample of a splash screen using the timer to time out 3.5 seconds so it can close itself....
Code:
"#1031" is the bitmap in the resource file:
'#define mybitmap 1031
'bitmap splash.bmp mybitmap
'In your winmain call InitSplash to show the splash screen...it will run until sTimer is checked and the dialog is exited in the callback function...
'========================================================================================================================
Function InitSplash() As Long
Local l_Height As Long
Local l_Width As Long
l_Width = 294
l_Height = 122
Dialog New 0, "",,, l_Width,l_Height, %WS_POPUP Or %WS_DLGFRAME To sDlg
Control Add Image, sDlg, -1,"#1031",-1,-1,l_Width,l_Height
Dialog Show Modal sDlg Call SplashScreen
End Function
CallBack Function SplashScreen() As Long
Local wMsg As Long
Local wParam As Long
Local lParam As Long
wMsg = CbMsg
lParam = CbLparam
wparam = CbWparam
MousePtr 11 'BUSY
Select Case wMsg
Case %WM_INITDIALOG
SetTimer sDlg, %IDT_TIMER1, 3500,%NULL 'Set timer to check every 3.5 seconds
Case %WM_DESTROY
KillTimer sDlg, %IDT_TIMER1
Case %WM_TIMER
Select Case CbWparam
Case %IDT_TIMER1
MousePtr 0
Dialog End sDlg, 1
End Select
End Select
End Function
Scott Turchin
MCSE, MCP+I http://www.tngbbs.com
---------------------- True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment