Announcement

Collapse
No announcement yet.

Combo box question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Combo box question

    I have this combo box that is used to hold an array of URL's from a file (History.txt).

    All goes well, and I have a hidden button set to default so that when enter is pressed on teh combobox the button is activated and grabs teh text from the combobox.

    This does not work, it returns a NULL string for some reason.

    I was under the impression if I wanted to pull an "ENTER" out of the combobox I would have to subclass it and that seems to be too much work for this little project.
    Not to mention it's over kill, the hidden button works well...

    But I can't get a return from it.
    Ideas?
    Thanks as always!

    Code:
    I created it as follows:
    
    'Array is now loaded
    Dialog New 0, g_szMine,0,0, 300,30, %WS_MINIMIZEBOX Or %WS_CAPTION Or %WS_SYSMENU Or %WS_EX_LEFT  To hDlg
    Control Add ComboBox, hDlg, %IDCOMBOBOX, HistArray(), 5, 1, 290,120, %CBS_DROPDOWN Or %WS_TABSTOP
    Control Add Button, hDlg, %ID_HIDDEN,"&Launch",5,50,45,14,%BS_DEFAULT
    Dialog Send hDlg, %WM_SETICON, %ICON_BIG, hIcon
    Menu Attach hMenu, hDlg
    Dialog Show Modal hDlg Call DialogProc To g_Result
    
    
    '
    '
    
    
        Case %WM_COMMAND
          Select Case LoWrd(wParam)
            Case %IDM_CLEAR
                 g_Result = MsgBox("Are you sure you wish to clear the history?", %MB_ICONINFORMATION Or %MB_YESNO, g_szMine)
                 Control Disable hDlg, %IDM_CLEAR
                 If IsTrue Exist(g_HistFile) Then
                    Kill g_HistFile
                    Erase HistArray()
                    ReDim HistArray(1 To 1000) As String
                 End If
            Case %ID_HIDDEN   'Launch
                  ComboBox Get Text hDlg ,%IDCOMBOBOX To g_szDestURL
                  MsgBox g_szDestURL
                  If Len(g_szDestURL) Then
                      Incr HistIndex
                      g_Result = ShellExecute(ByVal %NULL, "open", g_szDestURL + Chr$(0), ByVal %NULL, ByVal %NULL,%SW_SHOWMAXIMIZED)
                  Else
                     MsgBox "You must enter a valid URL", %MB_ICONSTOP,g_szMine
                  End If
            Case %IDCOMBOBOX
                  If LoWrd(CbCtlMsg) = %CBN_SELENDOK Then
                       ComboBox Get Text hDlg ,%IDCOMBOBOX To g_szDestURL
                       Incr HistIndex
                       ComboBox Select hDlg, %IDCOMBOBOX, HistIndex
                       g_Result = ShellExecute(ByVal %NULL, "open", g_szDestURL + Chr$(0), ByVal %NULL, ByVal %NULL,%SW_SHOWMAXIMIZED)
    
                   End If
                   Function = 1
                   Exit Function
    ------------------
    Scott
    mailto:[email protected][email protected]</A>
    MCSE, MCP+Internet
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

  • #2
    Subclassing is not such a big deal and gives you better possibilities
    for added functionality in the future. Try the following:
    (OldCBProc should be declared as GLOBAL)
    'In PB Main:
    Code:
      LOCAL hCtl AS LONG
      CONTROL HANDLE hDlg, %IDCOMBOBOX TO hCtl   'Sub-class, to trap keyboard events
      OldCBProc = SetWindowLong(hCtl, %GWL_WNDPROC, CODEPTR(CBProc))
    '.. and at some point that is reached when the program terminates
    Code:
      CONTROL HANDLE hDlg, %IDCOMBOBOX TO hCtl
      IF OldCBProc THEN SetWindowLong hCtl, %GWL_WNDPROC, OldCBProc
    '..and the Combo box procedure:
    Code:
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    ' Combobox subclass
    '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    FUNCTION CBProc(BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, _
                           BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG
     
      SELECT CASE wMsg
         CASE %CB_GETDROPPEDSTATE 'get enter key from a %CBS_DROPDOWN combo
            BEEP 'do something, just to show it works
     
         CASE %WM_KEYUP 'get enter key from a %CBS_DROPDOWNLIST combo
            BEEP 'do something, just to show it works
     
      END SELECT
      FUNCTION = CallWindowProc(OldCBProc, hWnd, wMsg, wParam, lParam)
     
    END FUNCTION
    ------------------

    Comment


    • #3
      Actually that wasn't that bad, had to add this in under KEYUP tho:

      KeyNum = LoWrd(wParam&) 'Actual ascii value of keystroke coming in


      Thanks

      Scott


      ------------------
      Scott
      mailto:[email protected][email protected]</A>
      MCSE, MCP+Internet
      Scott Turchin
      MCSE, MCP+I
      http://www.tngbbs.com
      ----------------------
      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

      Comment


      • #4
        For subclassing i often user the GWL_USERDATA variable.


        ------------------
        [email protected]
        hellobasic

        Comment


        • #5
          You lost me on that one...



          ------------------
          Scott
          mailto:[email protected][email protected]</A>
          MCSE, MCP+Internet
          Scott Turchin
          MCSE, MCP+I
          http://www.tngbbs.com
          ----------------------
          True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

          Comment


          • #6
            Originally posted by Edwin Knoppert:
            For subclassing i often user the GWL_USERDATA variable.

            I don't think that's possible with ddt.

            James


            ------------------

            Comment


            • #7
              It possible to have direct access to all messages in DDT without subclassing.
              (I posted such method almost half an year ago; up to now no one message about troubles)
              Code:
                #Compile Exe
                #Register None
                #Dim All
                #Include "Win32Api.Inc"
                
                CallBack Function DlgProc
                   If CbMsg = %WM_DESTROY Then PostQuitMessage 0
                End Function
                
                Function PbMain()
                   Local Msg As tagMsg, hDlg As Long, i As Long
                   Dialog New 0 ,"", , , 200, 100, %WS_CAPTION Or %WS_SYSMENU To hDlg
                   Control Add TextBox, hDlg, 101, "", 10, 10, 170, 12
                   Control Add TextBox, hDlg, 102, "", 10, 30, 170, 12
                   Control Add ComboBox, hDlg, 301,, 10, 65, 170, 100, %CBS_DROPDOWNLIST Or %WS_TABSTOP
                   For i = 1 To 10: ComboBox Add hDlg, 301, "Line"+ Str$(i): Next
                   ComboBox Select hDlg, 301, 1
                   Dialog Show Modeless hDlg Call DlgProc
                   While GetMessage(Msg, %NULL, 0, 0)
                      If Msg.message = %WM_KEYDOWN And Msg.wparam = 13 Then MsgBox "Hello, Scott"
                      If IsDialogMessage(hDlg, Msg) = %FALSE Then _
                         TranslateMessage Msg: DispatchMessage Msg
                   Loop
                   MsgBox "Finished"
                End Function
              ------------------

              Comment


              • #8
                This worked pretty good, rather impressed, it's the subclassed version but I like both possibilities:

                Code:
                '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                ' Combobox subclass
                '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                Function CBProc(ByVal hWnd As Long, ByVal wMsg As Long, _
                                ByVal wParam As Long, ByVal lParam As Long) As Long
                Local KeyNum As Long
                
                Select Case wMsg
                    Case %WM_KEYDOWN
                    Case %WM_CHAR
                    Case %WM_KEYUP
                    Case %CB_GETDROPPEDSTATE 'get enter key from a %CBS_DROPDOWN combo
                         Control Get Text hDlg ,%IDCOMBOBOX To g_szDestURL
                         Incr HistIndex
                         HistArray(HistIndex) = g_szDestURL 'Add to array to write to disk.
                         ComboBox Select hDlg, %IDCOMBOBOX, HistIndex
                         g_Result = ShellExecute(ByVal %NULL, "open", g_szDestURL + Chr$(0), ByVal %NULL, ByVal %NULL,%SW_SHOWMAXIMIZED)
                End Select
                Function = CallWindowProc(OldCBProc, hWnd, wMsg, wParam, lParam)
                End Function
                ------------------
                Scott
                mailto:[email protected][email protected]</A>
                MCSE, MCP+Internet
                Scott Turchin
                MCSE, MCP+I
                http://www.tngbbs.com
                ----------------------
                True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                Comment


                • #9
                  Originally posted by jcfuller:
                  I don't think that's possible with ddt.
                  James
                  James is correct... you cannot use %GWL_USERDATA with DDT controls and dialogs as this area is used internally by the DDT engine.

                  ------------------
                  Lance
                  PowerBASIC Support
                  mailto:[email protected][email protected]</A>
                  Lance
                  mailto:[email protected]

                  Comment

                  Working...
                  X