Date: 02-16-2022
Return to Index
created by gbSnippets
'When ENTER is pressed on a dialog, the %IDOK notification
'message is sent to the Callback function.
'However, some controls trap the ENTER key, preventing the
'%IDOK message from being sent. TextBoxes do this, for example,
'when their style %ES_WantReturn OR %ES_Mu
'The ComboBox and TreeView controls, among others, contain edit
'controls (top part of a ComboBox or the in-place label edit
'of TreeView) in which the user can press Enter. This also
'generates the %IDOK message and can be captured in a Callback.
'Compilable Example: (Jose Includes)
'Click on the ComboBox and press Enter to trigger the %IDOK notification.
'Note that pressing ENTER in either the single or multiline textbox will
'not trigger %IDOK. However, if the multiline textbox has style
'"%ES_WantReturn OR %ES_Multiline", pressing ENTER WILL trigger %IDOK.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "CommCtrl.inc"
#Resource "gbsnippets.pbr"
%IDC_ComboBox = 210
Global hDlg As Dword, hButton as Dword, hComboBox as Dword, hTextA as Dword, hTextB as Dword
Function PBMain() As Long
Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDOK, "OK", 20,10,150,20, %WS_Border
Control Add TextBox, hDlg, 220, "Single line TextBox", 20,70,150,20, %WS_Border
Control Add TextBox, hDlg, 230, "Multiline TextBox", 20,100,150,60, %WS_Border 'Or %ES_WantReturn Or %ES_Multiline
Control Handle hDlg, 220 To hTextA
Control Handle hDlg, 230 To hTextB
Control Handle hDlg, %IDOK To hButton
AddComboBox
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case CB.Msg
Case %WM_Command
Select Case CB.Ctl
Case %IdOk 'pressing Enter in ComboBox edit box
If CB.Ctlmsg = %BN_Clicked Then
Select Case GetParent(GetFocus) 'gets parent of the control which has the focus
Case hTextA
MsgBox "Enter pressed in TextBoxA"
Case hTextB
MsgBox "Enter pressed in TextBoxB!"
Case hComboBox
Control Send hDlg, %IDC_Combobox, %CB_SetCurSel, 0,0
MsgBox "ComboBox edit closed!"
Case Else
MsgBox "OK Button Pressed"
End Select
Function = 1
End If
End Select
End Select
End Function
Sub AddComboBox
Dim MyArray(3) as String
MyArray(0) = "here!" : MyArray(1)= "go" : MyArray(2) = "items" : MyArray(3)= "ListBox"
Control Add ComboBox, hDlg, %IDC_ComboBox,MyArray(), 20,40, 100,60
Control Handle hDlg, %IDC_ComboBox To hComboBox
End Sub
'gbs_00187
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm