..X Commands

Category: Apps/Dialogs

Date: 07-23-2010

Return to Index


 
'Sometimes I want to add more functionality to my applications but don't
'want to enlarge the dialog or add more controls. So what I do is take
'an existing control (such as a combobox) and modify the code to watch
'for special user inputs, usually starting with ".." to help prevent confusing
'the command with any other valid user input, as in the following few examples:
 
Case "..Exit"                       'ends the application
   Dialog End hDlg
Case "..ShowInfo"                 'display content of a text variable
   MsgBox EditControlText$     
Case "..dh"                        'convert decimal to hex
   MsgBox Str$(Val("+Mid$(temp$,4)))    
 
'Advantages:
'1. Enables me to keep my fingers on the keyboard, 
'   which is more efficient than jumping back and forth
'   between the keyboard and mouse.
'2. Requires NO changes to the user interface - minimizing
'   the introduction of errors which sometimes creep in as
'   an application grows.
 
'Compilable Example:
'This example captures pressing 'Enter' in a combobox, then takes
'action depending on the content of the edit box.
#Compile Exe
#Dim All
#Include "Win32api.inc"
Global hDlg As DWord, hCombo 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 ComboBox, hDlg, 100, MyArray(), 50,50,75,100
  Control Handle hDlg, 100 To hCombo
  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 ComboBox edit box
               If CB.Ctlmsg = %BN_Clicked Then
                  Select Case GetParent(GetFocus)
                     Case hCombo
                        Control Get Text hDlg, 100 To temp$
                        If Left$(temp$, 3) = "..xThen
                           Dialog End hDlg
                           Exit Function
                        ElseIf Left$(temp$,5) = "..db Then       'decimal to binary
                           'example: type in "db 12" and press Enter
                           temp$ = Bin$(Val(Mid$(temp$,6)))
                        ElseIf Left$(temp$,5) = "..hd Then       'hex to decimal
                           'example: type in "db A9" and press Enter
                           temp$ = Str$(Val("&H0"+Mid$(temp$,6)))
                        ElseIf Left$(temp$,5) = "..dh Then       'decimal to hex
                           'example: type in "db 32" and press Enter
                           temp$ = Hex$(Val(Mid$(temp$,6)))
                        End If
                  End Select
                  MsgBox temp$
                  Function = 1
               End If
         End Select
   End Select
End Function
 
'gbs_00034
 


created by gbSnippets: http://www.garybeene.com