PDA

View Full Version : multi dialog modeless



Lionheart008
07-01-2010, 17:01
because I am eager to understand all the different possibilities for callback functions and ui features here a little example with two dialogs and listbox you can select, quite easy and ready to take off :)
it's easy to make 10 or 100 dialogs only with adding



Make_Dlg hDlg
Make_Dlg hDlg2
Make_Dlg hDlg3
Make_Dlg hDlg4
...



' Empty GUI script created on 01-07-2010 15:41:23 by frank (ThinAIR)
'-------------------------------------------------------------------
Uses "ui"


Function TBMAIN()
Dim hDlg As Long, hDlg2 As Long, COUNT As Long, i As Long
Make_Dlg hDlg
Make_Dlg hDlg2
Do
Dialog DoEvents To Count
Loop While Count
End Function


CallBack Function My_DlgProc() As Long
Dim txt As String
Select Case CBMSG
Case %WM_COMMAND
Select Case CBCTL
Case 104
LISTBOX Get Text CBHNDL, 105 To txt
MsgBox 0, "ListBox text is " & txt
End Select
End Select
End Function


Function Make_Dlg(hDlg As Long) As Long
Static hInst As Long
Dim i As Long

Dialog New 0, "thinbasic modeless dialog",100+hInst*100, 100+hInst*130,250,100, _
%WS_POPUP Or %WS_SYSMENU Or %WS_CAPTION Or %WS_MINIMIZEBOX, 0 To hDlg '%WS_OVERLAPPEDWINDOW

Control Add Button, hDlg, 104,"Get Sel",190,80,50,13
Control Add LISTBOX, hDlg, 105,, 10, 25, 130, 80,%LBS_NOTIFY Or %WS_TABSTOP Or _
%WS_VSCROLL Or %LBS_USETABSTOPS, %WS_EX_CLIENTEDGE '
For i = 1 To 30
LISTBOX Add hDlg, 105, "This is Dialog" & Str$(hInst) & " rec: " + Str$(i)
Next
LISTBOX Select hDlg, 105, 1
Dialog Show Modeless hDlg, Call My_DlgProc()
Incr hInst
End Function

any constructive feedback is welcome. best regards, frank

Lionheart008
07-01-2010, 17:16
same example like above only with three dialogs :)


' Empty GUI script created on 01-07-2010 15:41:23 by frank (ThinAIR)
'-------------------------------------------------------------------
Uses "ui"


Function TBMAIN()
Dim hDlg As Long, hDlg2 As Long, hDlg3 As Long, count As Long, i As Long
Make_Dlg hDlg
Make_Dlg hDlg2
Make_Dlg hDlg3
Do
Dialog DoEvents To Count
Loop While Count
End Function


CallBack Function My_DlgProc() As Long
Dim txt As String
Select Case CBMSG
Case %WM_COMMAND
Select Case CBCTL
Case 104
LISTBOX Get Text CBHNDL, 105 To txt
MsgBox 0, "ListBox text is: " & txt
End Select
End Select
End Function


Function Make_Dlg(ByVal hDlg As Long) As Long
Static hInst As Long
Dim i As Long

Dialog New 0, "thinbasic modeless dialog",100+hInst*100, 100+hInst*130,250,100, _
%WS_POPUP Or %WS_SYSMENU Or %WS_CAPTION Or %WS_MINIMIZEBOX, 0 To hDlg '%WS_OVERLAPPEDWINDOW

Control Add Button, hDlg, 104,"Get Sel",190,80,50,13
Control Add LISTBOX, hDlg, 105,, 10, 25, 130, 80,%LBS_NOTIFY Or %WS_TABSTOP Or _
%WS_VSCROLL Or %LBS_USETABSTOPS, %WS_EX_CLIENTEDGE '
For i = 1 To 30
LISTBOX Add hDlg, 105, "This is Dialog: " & Str$(hInst) & " rec: " + Str$(i)
Next
LISTBOX Select hDlg, 105, 1
Dialog Show Modeless hDlg, Call My_DlgProc()
Incr hInst
End Function

Petr Schreiber
07-01-2010, 17:26
Hi Frank,

thanks for the example.

I will try to give some advices:
#1/ Do not use numbers to identify dialog controls. In larger programs, you will get lost. I remember in ThinEdge I had all controls named using equates, to avoid confusion, and it worked well.
Also, better to not pick random numbers for control equates, but start from %WM_USER as start value.

Begin Const
%bGetSel = %WM_USER + 1
%lbListbox
End Const


#2/ When capturing button click, don't use just:


Select Case CBMSG
Case %WM_COMMAND
Select Case CBCTL
Case %bGetSel
LISTBOX Get Text CBHNDL, %lListbox To txt
MsgBox 0, "ListBox text is " & txt
End Select
End Select


but this, proper message filter:


Select Case CBMSG
Case %WM_COMMAND
Select Case CBCTL
Case %bGetSel
If CBCTLMSG = %BN_CLICKED Then ' <-- Enables response just and only to button click
LISTBOX Get Text CBHNDL, %lListbox To txt
MsgBox CBHNDL, "ListBox text is " & txt ' <-- CbHndl instead of 0, to bind msgbox to dialog
EndIf
End Select
End Select


#3/ There is no point in declaring hDlg, hDlg2 .. unless you declare the function parameter as byref. This way you can read back the hDlg value.


Function Make_Dlg(ByVal hDlg As Long) As Long


to


Function Make_Dlg(ByRef hDlg As Long) As Long



Petr

Lionheart008
07-01-2010, 18:02
my grandmum would say, "don't use old socks!" :)

thanks for modern callback way I haven't done it yet, because I found this old example at my ui folder from autumn 2008 I have started with exploring ui module. usually I prefer also this way. 2kilo chocolate bomb upon my head.

modern and correct version:


' Empty GUI script created on 01-07-2010 15:41:23 by frank (ThinAIR)
'-------------------------------------------------------------------
Uses "ui"

Begin Const
%listb = %WM_USER + 1
%listb2
%button1
End Const


Function TBMAIN()
Dim hDlg As Long, hDlg2 As Long, hDlg3 As Long, count As Long, i As Long
Make_Dlg hDlg
Make_Dlg hDlg2
Make_Dlg hDlg3
Do
Dialog DoEvents To Count
Loop While Count
End Function


CallBack Function My_DlgProc() As Long
Dim txt As String
Select Case CBMSG
Case %WM_COMMAND
Select Case CBCTL
Case %listb
If CBCTLMSG = %BN_CLICKED Then
LISTBOX Get Text CBHNDL, %listb2 To txt
MsgBox CBHNDL, "ListBox text is " & txt
EndIf
End Select
End Select
End Function


Function Make_Dlg(ByRef hDlg As Long) As Long
Static hInst As Long
Dim i As Long

Dialog New 0, "thinbasic modeless dialog",100+hInst*100, 100+hInst*130,250,100, _
%WS_POPUP Or %WS_SYSMENU Or %WS_CAPTION Or %WS_MINIMIZEBOX, 0 To hDlg

Control Add Button, hDlg, %listb,"Get Sel",190,80,50,13
Control Add LISTBOX, hDlg, %listb2,, 10, 25, 130, 80,%LBS_NOTIFY Or %WS_TABSTOP Or _
%WS_VSCROLL Or %LBS_USETABSTOPS, %WS_EX_CLIENTEDGE '
For i = 1 To 30
LISTBOX Add hDlg, %listb2, "This is Dialog: " & Str$(hInst) & " rec: " + Str$(i)
Next
LISTBOX Select hDlg, %listb2, 1
Dialog Show Modeless hDlg, Call My_DlgProc()
Incr hInst
End Function


thanks for advices ! I was too fast, as usual... and I am freezing, must grinning.

last edit: correct version below :)

frank

Petr Schreiber
07-01-2010, 18:09
2kg of chocolate, that would kill even me :)

Thanks for the update. It seems the notes #2 and #3 are not applied yet.
Then it will be perfect :)

Lionheart008
07-01-2010, 18:21
my fingers are so cold I am not able to "copy" + "paste" in correct way and saved thinbasic file separately ! :unguee:
saved file again in my last post with "modern style", thanks again, I need a warm shower-bath, but there is still waiting an ice bear monster for me, he has same problems with actual ice time wheather :D,
servus, frank

Petr Schreiber
07-01-2010, 19:40
Thanks for the update,

good job!