Date: 02-16-2022
Return to Index
created by gbSnippets
'A button with an ID of the pre-defined equate %IDOK is
'triggered (clicked) when the ENTER key is pressed by the user,
'The exception is when controls, such as textbox or a
'rich edit control capture the Enter keystroke, preventing the
'%IDOK message from being sent to the Callback function.
'If no control captures Enter, the %IDOK message is
'available in the Callback function.
'Additionally, the ComboBox and TreeView controls 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)
'This example captures pressing 'Enter' in a combobox, then takes
'action depending on the content of the edit box.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32api.inc"
%IDC_TextBox = 500
%IDC_ComboBox = 501
Global hDlg, hComboEdit As Dword
Function PBMain() As Long
Dim MyArray(3) As String
Array Assign MyArray() = "zero", "one", "two", "three"
Dialog New Pixels, 0, "ComboBox Test",300,300,200,200, _
%WS_SysMenu, 0 To hDlg
Control Add Button, hDlg, %IdOk, "Press", 50,20,75,20
Control Add TextBox, hDlg, %IDC_TextBox, "", 50,50,75,20
Control Add ComboBox, hDlg, %IDC_ComboBox, MyArray(), 50,80,100,100
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local ComboInfo As ComboBoxInfo, temp$
Select Case Cb.Msg
Case %WM_InitDialog
ComboInfo.cbSize = SizeOf(ComboBoxInfo)
GetComboBoxInfo(GetDlgItem(hDlg,%IDC_ComboBox), ByVal VarPtr(ComboInfo)) 'get data about combobox
hComboEdit = ComboInfo.hwndItem 'handle to edit control of combobox
Case %WM_Command
Select Case %IdOk
If Cb.CtlMsg = %BN_Clicked Then
Select Case GetFocus
Case hComboEdit
? "ENTER pressed in ComboBox Edit Control"
Case GetDlgItem(hDlg, %IDC_ComboBox)
? "ENTER pressed in ComboBox"
Case GetDlgItem(hDlg,%IdOk)
? "Button pressed"
Case GetDlgItem(hDlg,%IDC_TextBox)
? "ENTER pressed in TextBox"
End Select
End If
End Select
End Select
End Function
'gbs_00191
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm