PDA

View Full Version : ui example



Lionheart008
27-11-2009, 22:49
hi.

can anybody please check this ui callback example ? ;)

1) => I am wondering why this example starts with two dialogs at same time ?

2) the "extrahelp" (dialog one) button doesn't appear at the start, but should do it. After pushing "close myClassroom" button ("dialog two", you may try it two times to close it!) the "extrahelp" in main dialog appears again.

3) if you come with mouse over "extrahelp" button ("dialog one") the next dialog popup starts immediately and I cannot clear exit this new dialog. perhaps it's not very smart to include "dialog new" into callback function, but I wanted to do that one. - it's just an experiment. critics are welcome!

updated example:


Uses "UI"

'#include "%APP_INCLUDEPATH%\RichEdit32.inc"

' -- ID numbers of controls
Begin Const
%bClose = %WM_USER + 1
%tInput
%tInput2
%TextboxName
%ButtonOk
%ButtonCancel
%ButtonBrowse
%ButtonRep
%ButtonDel
%ButtonAdd
%LISTBOXFRANK
%TextboxPath
%LabelPath
%LabelName
%Help
%ButtonSave
%ButtonNewchil
%bOpenX
End Const

' -- Create dialog here
Function TBMAIN() as long
Local hDlg As DWord

Dialog NEW 0, "You can use only h,e,l,l,o, f,r,a,n,k",-1,-1, 220, 120, _
%WS_POPUP Or %WS_VISIBLE Or %WS_CAPTION Or %WS_SYSMENU Or %WS_MINIMIZEBOX To hDlg

' -- Place controls here
Control ADD TEXTBOX, hDlg, %tInput, "", 5, 5, 150, 14, Call bInputProc
Control ADD TEXTBOX, hDlg, %tInput2, "", 5, 25, 150, 14, Call bInputProx
Control ADD BUTTON , hDlg, %bClose, "Click to close", 5, 50, 150, 14, Call bCloseProc
Control ADD BUTTON , hDlg, %bOpenX, "OpenX", 5, 70, 150, 14 '-- , Call bCloseProc
Control ADD BUTTON , hDlg, %Help, "ExtraHelp", 5, 90, 150, 14, Call FranksClassroomEditorGet

Dialog SHOW MODAL hDlg, Call dlgProc

End Function

' -- Callback for dialog
CallBack Function dlgProc()

' -- Test for messages
Select Case CBMSG

Case %WM_INITDIALOG
' -- Put code to be executed after dialog creation here

Case %WM_CLOSE
' -- Put code to be executed before dialog end here

End Select

End Function

' -- Callbacks for controls
CallBack Function bCloseProc()

If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then
' -- Closes the dialog
Dialog End CBHNDL
End If
End If
End Function

'xxx - one callback -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

CallBack Function bInputProc()
Local s As String, pos, selStart, selEnd As Long

If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %EN_UPDATE Then
' -- Get the current text
Control GET TEXT CBHNDL, %tInput To s

' -- Is it longer than 0 characters
If Len(s) > 0 Then
' -- Store original cursor position
Control SEND CBHNDL, %tInput, %EM_GETSEL, VARPTR(selStart), VARPTR(selEnd)

' -- Does it contain something else than abc?
pos = Verify(s, "hello")

' -- If yes, trim it!
If pos Then s = LEFT$(s, pos-1)
' --Put text back
Control SET TEXT CBHNDL, %tInput, s

' -- Restore original cursor position
Control SEND CBHNDL, %tInput, %EM_SETSEL, selStart, selEnd
End If

End If
End If

End Function

'xxx - two callback -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

CallBack Function bInputProx()
Local t As String, pos2, selStart, selEnd As Long

If CBMSG = %WM_COMMAND Then

If CBCTLMSG = %EN_UPDATE Then
' -- Get the current text
Control GET TEXT CBHNDL, %tInput2 To t

' -- Is it longer than 0 characters
If Len(t) > 0 Then
' -- Store original cursor position
Control SEND CBHNDL, %tInput2, %EM_GETSEL, VARPTR(selStart), VARPTR(selEnd)

' -- Does it contain something else than abc?
pos2 = Verify(t, "frank")

' -- If yes, trim it!
If pos2 Then t = LEFT$(t, pos2-1)
' --Put text back
Control SET TEXT CBHNDL, %tInput2, t

' -- Restore original cursor position
Control SEND CBHNDL, %tInput2, %EM_SETSEL, selStart, selEnd
End If

End If
End If
End Function

'xxx - three callback -xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

CallBack Function FranksClassroomEditorGet()

Local FranksEditorhDlg As Long
Local hDlg As Long
Local myTitle As ASCIIZ *60
$AppName = "Franks Classroom GUI EditorHelp"

myTitle = $AppName & " - Franks Classroom GUI Editor/Help file - Add"

Dialog NEW hDlg, $AppName & " - Franks Classroom GUI Editor/Help file", 0,0 , 195, 175, _
%WS_POPUP Or %WS_VISIBLE Or %WS_CLIPSIBLINGS Or %WS_CAPTION Or _
%WS_SYSMENU Or %DS_3DLOOK Or %DS_NOFAILCREATE Or %DS_SETFONT Or %WS_MINIMIZEBOX, _
%WS_EX_CONTROLPARENT To FranksEditorhDlg

Control ADD LABEL, FranksEditorhDlg, %LabelName, "Name of children to display", 3, 3, 96, 34, _
%WS_CHILD Or %WS_VISIBLE

Control ADD TEXTBOX, FranksEditorhDlg, %TextboxName, "ludwig van beethoven", 3, 15, 186, 12, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %ES_AUTOHSCROLL, %WS_EX_CLIENTEDGE

Control ADD LABEL, FranksEditorhDlg, %LabelPath, ".doc, .exe, .txt, .hlp, .xls full path " & _
"?", 3, 30, 165, 12, %WS_CHILD Or %WS_VISIBLE

Control ADD TEXTBOX, FranksEditorhDlg, %TextboxPath, "teacher map1", 3, 42, 186, 12, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %ES_AUTOHSCROLL, %WS_EX_CLIENTEDGE

Control ADD TEXTBOX, FranksEditorhDlg, %LISTBOXFRANK,"" , 3, 66, 96, 82, _
%WS_CHILD Or %WS_VISIBLE Or %WS_BORDER Or %WS_VSCROLL Or %WS_TABSTOP _
Or %LBS_NOTIFY Or %LBS_SORT Or %LBS_USETABSTOPS or %ES_MULTILINE or %ES_WANTRETURN OR %WS_EX_LEFT, %WS_EX_CLIENTEDGE
Control set Text FranksEditorhDlg, %LISTBOXFRANK, "type in here some silly things"
CONTROL set Focus FranksEditorhDlg, %LISTBOXFRANK

Control ADD BUTTON, FranksEditorhDlg, %ButtonAdd, "&Add", 111, 66, 33, 15, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_CENTER Or %BS_VCENTER

Control ADD BUTTON, FranksEditorhDlg, %ButtonDel, "&Del", 111, 90, 33, 15, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_CENTER Or %BS_VCENTER

Control ADD BUTTON, FranksEditorhDlg, %ButtonRep, "&Repl", 111, 114, 33, 15, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_CENTER Or %BS_VCENTER

Control ADD BUTTON, FranksEditorhDlg, %ButtonBrowse, "&Browse", 153, 66, 33, 15, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_CENTER Or %BS_VCENTER

Control ADD BUTTON, FranksEditorhDlg, %ButtonCancel, "&Cancel", 153, 90, 33, 15, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_CENTER Or %BS_VCENTER

Control ADD BUTTON, FranksEditorhDlg, %ButtonOk, "&OK", 153, 114, 33, 15, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_CENTER Or %BS_VCENTER

Control ADD BUTTON, FranksEditorhDlg, %ButtonNewchil, "&new", 153, 134, 33, 15, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_CENTER Or %BS_VCENTER

Control ADD BUTTON, FranksEditorhDlg, %ButtonSave, "&save", 111, 134, 33, 15, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_CENTER Or %BS_VCENTER

Control ADD BUTTON,FranksEditorhDlg, %bClose, "Close myClassRoom", 5, 156, 150, 14, Call bCloseProx

Dialog SHOW MODAL FranksEditorhDlg, call dlgProbe', Call FranksChildrenGetProc

End Function


'------ callback for closing new dialog with Classroom
CallBack Function bCloseProx()

If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then
' -- Closes the dialog
Dialog End CBHNDL
End If
End If
End Function

' ------- dummy Callback for dialog
CallBack Function dlgProbe()

Select Case CBMSG

Case %WM_INITDIALOG

Case %WM_CLOSE

End Select

End Function



best regards, frank

Petr Schreiber
28-11-2009, 11:37
Frank,

no mystery in here.
For button with ID %Help you have FranksClassroomEditorGet callback.

In that callback, you do not have any test for CBCTLMSG = %BN_CLICKED, so the callback (where you have dialog creation) is called when any event occurs to %Help button.

Lionheart008
28-11-2009, 15:00
thank you petr for this hint.


you do not have any test for CBCTLMSG = %BN_CLICKED,

of course, I have forgotten this one :



If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then
FranksClassroomEditorGet
End If
End If


now I have splitted callbacks and functions for my three different dialogs.

so here is one possible and running solution :) !


'-------- three dialogs with callback and string / value returns for inputs by frank

Uses "UI"

'#include "%APP_INCLUDEPATH%\RichEdit32.inc"

' -- ID numbers of controls
Begin Const
%bClose = %WM_USER + 1
%tInput
%tInput2
%TextboxName
%ButtonOk
%ButtonCancel
%ButtonBrowse
%ButtonRep
%ButtonDel
%ButtonAdd
%LISTBOXFRANK
%TextboxPath
%LabelPath
%LabelName
%Help
%ButtonSave
%ButtonNewchil
%bOpenX
End Const

' -- Create dialog here
Function TBMAIN() as long
Local hDlg As DWord

Dialog NEW 0, "(A) you can use only h,e,l,l,o, f,r,a,n,k",-1,-1, 230, 120, _
%WS_POPUP Or %WS_VISIBLE Or %WS_CAPTION Or %WS_SYSMENU Or %WS_MINIMIZEBOX To hDlg

' -- Place controls here
Control ADD TEXTBOX, hDlg, %tInput, "", 25, 5, 150, 14, Call bInputProc
Control ADD TEXTBOX, hDlg, %tInput2, "", 25, 25, 150, 14, Call bInputProx
Control ADD BUTTON , hDlg, %bClose, "Click to close", 25, 50, 150, 14, Call bCloseProc
Control ADD BUTTON , hDlg, %bOpenX, "OpenX", 25, 70, 150, 14, Call openx
Control ADD BUTTON , hDlg, %Help, "ExtraHelp", 25, 90, 150, 14, Call FranksClassroomEditorGetX

Dialog SHOW MODAL hDlg, Call dlgProc

End Function

' -- 1. Callback for dialog
CallBack Function dlgProc()
' -- Test for messages
Select Case CBMSG
Case %WM_INITDIALOG
' -- Put code to be executed after dialog creation here
Case %WM_CLOSE
' -- Put code to be executed before dialog end here
End Select
End Function

' -- Callbacks for controls
CallBack Function bCloseProc()

If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then
' -- Closes the dialog
Dialog End CBHNDL
End If
End If
End Function

'---------------------------------------------------

CallBack Function bInputProc()
Local s As String, pos, selStart, selEnd As Long

If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %EN_UPDATE Then
' -- Get the current text
Control GET TEXT CBHNDL, %tInput To s
' -- Is it longer than 0 characters
If Len(s) > 0 Then
' -- Store original cursor position
Control SEND CBHNDL, %tInput, %EM_GETSEL, VARPTR(selStart), VARPTR(selEnd)

' -- Does it contain something else than abc?
pos = Verify(s, "hello")
' -- If yes, trim it!
If pos Then s = LEFT$(s, pos-1)
' --Put text back
Control SET TEXT CBHNDL, %tInput, s
' -- Restore original cursor position
Control SEND CBHNDL, %tInput, %EM_SETSEL, selStart, selEnd
End If

End If
End If

End Function


CallBack Function bInputProx()
Local t As String, pos2, selStart, selEnd As Long

If CBCTLMSG = %EN_UPDATE Then
' -- Get the current text
Control GET TEXT CBHNDL, %tInput2 To t
' -- Is it longer than 0 characters
If Len(t) > 0 Then
' -- Store original cursor position
Control SEND CBHNDL, %tInput2, %EM_GETSEL, VARPTR(selStart), VARPTR(selEnd)
' -- Does it contain something else than abc?
pos2 = Verify(t, "frank")
' -- If yes, trim it!
If pos2 Then t = LEFT$(t, pos2-1)
' --Put text back
Control SET TEXT CBHNDL, %tInput2, t
' -- Restore original cursor position
Control SEND CBHNDL, %tInput2, %EM_SETSEL, selStart, selEnd
End If
End If
End Function

'-- callback for new dialog to open 'classroom' ---

CallBack Function FranksClassroomEditorGetX()
Local hDlg As Long

If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then
FranksClassroomEditorGet
End If
End If
End Function


'-- callback 4 only for open new dialog ----------------------------------

CallBack Function FranksClassroomEditorGet()
Local FranksEditorhDlg As Long
Local hDlg As Long
Local myTitle As ASCIIZ *60
$AppName = "(B): Franks Classroom GUI EditorHelp"

myTitle = $AppName & "- Franks Classroom GUI Editor/Help file - Add"

Dialog NEW hDlg, $AppName & "(B) Franks Classroom GUI Editor/Help file", 0,0 , 195, 175, _
%WS_POPUP Or %WS_VISIBLE Or %WS_CLIPSIBLINGS Or %WS_CAPTION Or _
%WS_SYSMENU Or %DS_3DLOOK Or %DS_NOFAILCREATE Or %DS_SETFONT Or %WS_MINIMIZEBOX, _
%WS_EX_CONTROLPARENT To FranksEditorhDlg

Control ADD LABEL, FranksEditorhDlg, %LabelName, "Name of children to display", 3, 3, 96, 34, _
%WS_CHILD Or %WS_VISIBLE

Control ADD TEXTBOX, FranksEditorhDlg, %TextboxName, "ludwig van beethoven", 3, 15, 186, 12, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %ES_AUTOHSCROLL, %WS_EX_CLIENTEDGE

Control ADD LABEL, FranksEditorhDlg, %LabelPath, ".doc, .exe, .txt, .hlp, .xls full path " & _
"?", 3, 30, 165, 12, %WS_CHILD Or %WS_VISIBLE

Control ADD TEXTBOX, FranksEditorhDlg, %TextboxPath, "teacher map1", 3, 42, 186, 12, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %ES_AUTOHSCROLL, %WS_EX_CLIENTEDGE

Control ADD TEXTBOX, FranksEditorhDlg, %LISTBOXFRANK,"" , 3, 66, 96, 82, _
%WS_CHILD Or %WS_VISIBLE Or %WS_BORDER Or %WS_VSCROLL Or %WS_TABSTOP _
Or %LBS_NOTIFY Or %LBS_SORT Or %LBS_USETABSTOPS or %ES_MULTILINE or %ES_WANTRETURN OR %WS_EX_LEFT, %WS_EX_CLIENTEDGE
Control set Text FranksEditorhDlg, %LISTBOXFRANK, "type in here some silly things"
CONTROL set Focus FranksEditorhDlg, %LISTBOXFRANK

Control ADD BUTTON, FranksEditorhDlg, %ButtonAdd, "&Add", 111, 66, 33, 15, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_CENTER Or %BS_VCENTER

Control ADD BUTTON, FranksEditorhDlg, %ButtonDel, "&Del", 111, 90, 33, 15, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_CENTER Or %BS_VCENTER

Control ADD BUTTON, FranksEditorhDlg, %ButtonRep, "&Repl", 111, 114, 33, 15, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_CENTER Or %BS_VCENTER

Control ADD BUTTON, FranksEditorhDlg, %ButtonBrowse, "&Browse", 153, 66, 33, 15, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_CENTER Or %BS_VCENTER

Control ADD BUTTON, FranksEditorhDlg, %ButtonCancel, "&Cancel", 153, 90, 33, 15, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_CENTER Or %BS_VCENTER

Control ADD BUTTON, FranksEditorhDlg, %ButtonOk, "&OK", 153, 114, 33, 15, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_CENTER Or %BS_VCENTER

Control ADD BUTTON, FranksEditorhDlg, %ButtonNewchil, "&new", 153, 134, 33, 15, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_CENTER Or %BS_VCENTER

Control ADD BUTTON, FranksEditorhDlg, %ButtonSave, "&save", 111, 134, 33, 15, _
%WS_CHILD Or %WS_VISIBLE Or %WS_TABSTOP Or %BS_CENTER Or %BS_VCENTER

Control ADD BUTTON,FranksEditorhDlg, %bClose, "Close myClassRoom", 5, 156, 150, 14, Call bCloseProx

Dialog SHOW MODAL FranksEditorhDlg, call dlgProbe


End Function


'------ callback for closing new dialog with Classroom
CallBack Function bCloseProx()

If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then
' -- Closes the dialog
Dialog End CBHNDL
End If
End If
End Function

' ------- dummy Callback for dialog
CallBack Function dlgProbe()

Select Case CBMSG

Case %WM_INITDIALOG

Case %WM_CLOSE

End Select

End Function

'------------ callback for open alternative dialog (second one)

callback function openx()

If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then
openwin
End If
End If

end function

function openwin() as long
%ButtonClose = 1001
Dim hDlg As DWORD

DIALOG New 0, "(C) myNewTitle",-1,-1, 210, 100, _
%WS_POPUP Or _
%WS_VISIBLE Or _
%WS_CLIPCHILDREN Or _
%WS_CAPTION Or _
%WS_SYSMENU Or _
%WS_MINIMIZEBOX, _
0 To hDlg

CONTROL ADD BUTTON, hDlg, %ButtonClose, "Shotdown the monster", 60, 50, 80, 24
DIALOG SHOW MODAL hDlg Call cbDialoggy

end function

'--------------------------------------------------------------

CALLBACK Function cbDialoggy() As Long
Select Case CBMSG
Case %WM_Command
If CBWPARAM = %ButtonClose Then DIALOG End CBHNDL
Case %WM_DESTROY
MSGBOX 0, "Window is to be destroyed."
End Select
End Function

'-- end of callback example

first little experiment successful.

nice day, thanks. best regards, frank
ps: is there any complete list for this kind of keywords (%WM_COMMAND, %WM_CREATE, %WM_CLOSE...) for callbacks ?

ErosOlmi
28-11-2009, 15:28
is there any complete list for this kind of keywords (%WM_COMMAND, %WM_CREATE, %WM_CLOSE...) for callbacks ?


Not in thinBasic help otherwise I would double the size of the help.
But thinBasic is very "standard" in the sense that we just use (whenever possible) standard Microsoft indication so you can find all messages and constants in MSDN.
For example see here: http://msdn.microsoft.com/en-us/library/dd469354(VS.85).aspx

One important difference is that thinBasic is not able to trap %WM_CREATE (due to internal UI module organization) but you can use %WM_INITDIALOG to trap window initialization.

Petr Schreiber
28-11-2009, 17:38
Nice work Frank,

now just please change:


CallBack Function FranksClassroomEditorGet()


to


Function FranksClassroomEditorGet()


as it no longer serves as callback.