Date: 02-16-2022
Return to Index
created by gbSnippets
'This snippet is intended to be a brief introduction/overview of DDT vs SDK topics.
'Details are provided in the next several snippets.
'In general, SDK-style programming refers to the direct use of API in code, rather
'than the wrapper statements supplied by PowerBASIC. It also specifically refers to
'the creation of windows using the CreateWindowEx API rather than the use of dialogs,
'which are the basis of the PowerBASIC DDT technology. These two examples help
'clarify the differences:
API vs DDT Statements
'In this first comparison, the PowerBASIC CONTROL SEND statement is used to send
'a message. In the second line, the SendMessage API is used. Both achieve exactly the
'same result.
DDT: Control Send hDlg, %ID_TextBox, %xxx, %xxx, %xxx
SDK: SendMessage hTextBox, %xxx, %xxx, %xxx
'In this second comparison, the PowerBASIC DIALOG NEW statement is used to create
'a dialog (which is a specific, pre-defined window class). In the second line, the
'CreateWindowEx API is used to create a window.
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
hWnd = CreateWindow(szAppName, "SDK Demo", %WS_OVERLAPPEDWINDOW, 500,400,300,150,%Null, %Null, hInst, ByVal %Null)
API vs DDT Application Skeletons
'Whether you're working with a dialog or an SDK-style window, there's a similarity
'between the two - a main function to start the program and a designated procedure
'to receive messages. As a reminder, here's how a basic DDT application looks - PBMain()
'to start the program and DlgProc() to receive messages.
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
End Function
'In contrast, here's the similar functions for an SDK-style application - a WinMain()
'to start the program (must include a message pump) and a WndProce() to receive messages
Function WinMain (ByVal hInst As Dword, ByVal hPrevInstance As Dword,
_ByVal lpCmdLine As Asciiz PTR, ByVal iCmdShow As Long) As Long
'content for defining a message class, registering the class, and displaying the window
'are covered in the next several snippets
'message loop
While GetMessage(Msg, %NULL, 0, 0)
If IsFalse ISDialogMessage (hDlg, Msg)) Then
IsFalse TranslateAccelerator (hWnd, hAccel, Msg) Then
TranslateMessage Msg
DispatchMessage Msg
End If
End If
Wend
End Function
Function WndProc (ByVal hWnd AS Dword, ByVal wMsg AS Dword,
_ByVal wParam AS Dword, ByVal lParam As Long) EXPORT As Long
'... content
End Function
API vs DDT Skeleton Differences
'There are several noticeable differences between the two skeletons.
'1. Main Function - DDT uses PBMain() whereas SDK uses WinMain()
'2. Arguments - DDT requires no PBMain() or DlgProc() arguments, whereas in SDK the
' program must supply the arguments.
'3. Message Pump - DDT modal dialogs have a built-in message pump, whereas in SDK the
' program must explicitly include a message pump
'Note: Regardless of the approach, SDK or DDT, the windows procedures can be any name
'the programmer chooses. DlgProc and WndProc are typically used, but any name will do.
Dialogs vs Windows
'The entire PowerBASIC DDT technology is built on the use of the pre-defined dialog window,
'as compared to the use of windows created using the CreateWindowEX API. There are
'several tradeoffs involved in this decision. I suggest reading the following PowerBASIC
'forum threads for more information.
http://www.powerbasic.com/support/pbforums/showthread.php?t=39776
http://www.powerbasic.com/support/pbforums/showthread.php?t=36705
http://www.powerbasic.com/support/pbforums/showthread.php?t=39796
'gbs_00359
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm