I'm looking for a combobox style treeview control, that is, a control that looks (and acts) like a combobox but drops down into a treeview instead of a simple list.
Use a hook. Drop the following into a public module:
Option Explicit
Public mp_lpPrevWndProc As Long
Public Const GWL_WNDPROC As Long = -4
Private Const CBN_DROPDOWN As Long = 7
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private m_ctlCombo As ComboBox
Public Sub Unhook_Combo(hwnd As Long)
If mp_lpPrevWndProc <> 0 Then
Call SetWindowLong(hwnd, GWL_WNDPROC, mp_lpPrevWndProc)
mp_lpPrevWndProc = 0
End If
End Sub
Public Sub Hook_Combo(hwnd As Long, ByRef ctlCombo As ComboBox)
If mp_lpPrevWndProc = 0 Then
Set m_ctlCombo = ctlCombo
mp_lpPrevWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
End If
End Sub
Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
If hwnd = m_ctlCombo.hwnd Then
Select Case uMsg
Case CBN_DROPDOWN
WindowProc = 1
Case Else
WindowProc = CallWindowProc(mp_lpPrevWndProc, hwnd, uMsg, wParam, lParam)
End Select
End If
End Function
And add this to the Form_Load event:
If mp_lpPrevWndProc = 0 Then Hook_Combo Combo1.hwnd, Combo1
And this to the Form_Unload event:
If mp_lpPrevWndProc <> 0 Then Unhook_Combo Combo1.hwnd
Do not mess with the code in the WindowProc proceedure when the program is running and make sure you stop the program properly.
After each time that the combo gets the focus, it will work once. Assumming you will add a TreeView and move the Focus there on the click, there shouldn't be a problem.
If you use a different type of combo box, such as the DataCombo, you will need to change the variable:
Private m_ctlCombo As ComboBox
to
Private m_ctlCombo As DataCombo [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.