PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: paulDiagnos on May 13, 2008, 01:45:52 PM

Title: Combo Box
Post by: paulDiagnos on May 13, 2008, 01:45:52 PM
Hey Guys,

Just a quick question is there a simple way to use a combo box as a text box and enter text into it.

the reason being drop down box contains dir listings files on pc. but it would be nice to use a keyboard input to navigate to a location

cheers Paul.
Title: Re: Combo Box
Post by: TechSupport on May 13, 2008, 07:32:40 PM
Do you mean a combobox with the %CBS_DROPDOWN window style set?
Title: Re: Combo Box
Post by: paulDiagnos on May 14, 2008, 08:19:18 AM
I think so yeah.

drop down, but allowed to type text in.

is it possible?
Title: Re: Combo Box
Post by: TechSupport on May 14, 2008, 08:35:10 AM
Hi Paul,

Maybe I'm missing your point? The %CBS_DROPDOWN styled combobox allows for typing text in and also displaying a drop down list.
Title: Re: Combo Box
Post by: paulDiagnos on May 15, 2008, 07:18:34 AM
sorry should have read your last post.

perfect that was what i needed!! thanks.

although now a bit confused trying to detect a carrage return...

    If wMsg = 135 And wparam = %VK_RETURN Then

         MsgBox FF_Control_GetText hwnd_transfer_drive
   
   End If

doesnt quite work for the custom messages for the drop down.
Title: Re: Combo Box
Post by: paulDiagnos on May 20, 2008, 05:45:40 AM
OR do i have to enable the control or somethign to accept carrage returns>?
Title: Re: Combo Box
Post by: TechSupport on May 20, 2008, 09:58:34 AM
Hi Paul,

I was working on this the other night. I tried subclassing the edit control part of the combobox but I ran into GPF's. I need to examine this more closely because of the "chain" of subclassing that is in place that FireFly does automatically. I ran out of time... I'll try to get you an answer as soon as I can (wicked busy in the "day job") :(
Title: Re: Combo Box
Post by: paulDiagnos on May 20, 2008, 12:01:03 PM
its not a high priority thing for me but would be nice if i could get it done in a couple of months :-)

dont forget about me , but no need to loose sleep over.

Paul.
Title: Re: Combo Box
Post by: paulDiagnos on June 16, 2008, 01:59:38 PM
any more luck with this one?
Title: Re: Combo Box
Post by: TechSupport on June 16, 2008, 07:47:44 PM
Hi Paul,

Here is some code that works. The "tricks" are to (1) Use a Custom Control and create the combo box but do not return a Window handle from the _Init handler in order to prevent FireFly from subclassing the control, (2) Subclass the edit portion of the combo box manually (the edit control has an identifier of 1001), (3) Handle the %WM_GETDLGCODE message in the subclass and return %DLGC_WANTALLKEYS in order to allow the RETURN key to be captured.


Global ghComboFont      As Long
Global gOldProcComboBox As Dword
                       
                       
'------------------------------------------------------------------------------------------------------------------------
Function FORM1_CUSTOMCONTROL1_INIT ( _
                                   ClassName   As Asciiz, _  ' windows class
                                   Caption     As Asciiz, _  ' window caption
                                   hWndParent  As Dword,  _  ' handle of parent window
                                   ExStyles    As Dword,  _  ' extended window styles
                                   Styles      As Dword,  _  ' standard window styles
                                   nLeft       As Dword,  _  ' left position of control
                                   nTop        As Dword,  _  ' top position of control
                                   nWidth      As Dword,  _  ' width of control
                                   nHeight     As Dword   _  ' height of control
                                   ) As Long


   'If your custom control uses CreateWindowEx then use the template below, otherwise
   'follow the instructions provided by the Custom Control's author. The Custom Control
   'INIT function is called during the %WM_CREATE message for the Form on which the
   'Custom Control is created.

   Local hWndControl As Dword
           
   hWndControl = CreateWindowEx(0, _
                                "ComboBox", _
                                "", _
                                %WS_CHILD Or %WS_VISIBLE Or %WS_VSCROLL Or %WS_TABSTOP Or _
                                %CBS_DROPDOWN, _
                                nLeft, nTop, nWidth, nHeight, _
                                hWndParent, IDC_FORM1_CUSTOMCONTROL1, _
                                GetModuleHandle(ByVal %Null), _
                                ByVal %Null)

   ' Stretch the window length of the ComboBox
   MoveWindow hWndControl, nLeft, nTop, nWidth, 200, 0
   ShowWindow hWndControl, %SW_SHOW

   ' Create a font and assign it to the combobox (it is destroyed in WM_DESTROY)
   ghComboFont = FF_MakeFontEx_Internal("MS Sans Serif,-11,0,0,0,400,0,0,0,0,1,2,1,34")
   If ghComboFont Then SendMessage hWndControl, %WM_SETFONT, ghComboFont, %TRUE

   ' Subclass the edit portion (ID=1001) of the combobox control
   gOldProcComboBox = SetWindowLong( GetDlgItem(hWndControl, 1001), %GWL_WNDPROC, ByVal CodePtr(ComboBoxProc) ) 

   'It is important that this function return the Windows Handle to the newly created Control *** Do not delete this ***.
   ' *** Do NOT return the handle because we will subclass control rather than have FireFly do it.
   'Function = hWndControl
   
   
End Function


'------------------------------------------------------------------------------------------------------------------------
Function ComboBoxProc( ByVal hWnd As Dword, _
                       ByVal wMsg As Long, _
                       ByVal wParam As Long, _
                       ByVal lParam As Long _
                       ) As Long
                     
   Select Case wMsg
      Case %WM_GETDLGCODE
         ' Specifies that we want all keys being entered in the textbox
         ' to be available here.
         Function = %DLGC_WANTALLKEYS: Exit Function
         
      Case %WM_CHAR
         If wParam = 13 Then
            MsgBox "Enter Pressed" & Str$(wParam)
         End If
   End Select

   Function = CallWindowProc( gOldProcComboBox, hWnd, wMsg, wParam, lParam )
End Function



'------------------------------------------------------------------------------------------------------------------------
Function FORM1_WM_DESTROY ( _
                          hWndForm      As Dword _  ' handle of Form
                          ) As Long
                         
   If ghComboFont Then
      DeleteObject ghComboFont
      ghComboFont = 0
   End If
     
End Function


Title: Re: Combo Box
Post by: paulDiagnos on June 18, 2008, 07:10:11 AM
Brilliant,
I got the code working, excepting carrage returns etc.

but it seems to affect a few things,
Can I not use the FF functions on the form from now on?
im finding it difficult to move the control, etc.

cheers paul.
Title: Re: Combo Box
Post by: TechSupport on June 18, 2008, 08:33:49 AM
Ah, yes, I see what you mean. If you need to manipulate the control after it is created then the best way to do it will be to use the GetDlgItem API to retrieve the window handle of the control.



hWndControl = GetDlgItem( HWND_FORM1, IDC_FORM1_CUSTOMCONTROL1 )



You can then use the handle in any function that requires the HWND_ of the control.

For example, to move the control to the top left corner of the form (FORM1) you could do the following:



SetWindowPos GetDlgItem(HWND_FORM1, IDC_FORM1_CUSTOMCONTROL1), 0, 0, 0, 0, 0, %SWP_NOZORDER Or %SWP_NOSIZE