1
Visual Basic 6 / ComboBox no despliega contenido en barra de titulo
« en: Marzo 19, 2012, 08:22:24 pm »
:)Hola, un saludo a cobein, xkiz & coco y por supuesto a Leandro, Amigos, tengo un proyecto que inserta un combobox en una barra de titulo, pero al ejecutarlo no se despliega la lista del combobox, espero alguien pueda sugerirme alguna solución. Les mando saludos. Este es el código:
Código: [Seleccionar]
Option Explicit
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook&, ByVal lpfn&, ByVal hmod&, ByVal dwThreadId&) As Long
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook&) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type CWPSTRUCT
lParam As Long
wParam As Long
Message As Long
hwnd As Long
End Type
Private Const WM_MOVE = &H3
Private Const WM_SETCURSOR = &H20
Private Const WM_NCPAINT = &H85
Private Const WM_COMMAND = &H111
Private Const SWP_FRAMECHANGED = &H20
Private Const GWL_EXSTYLE = -20
Private WHook&
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Const SM_CXSIZE = 30 'Width of title bar
Private Const SM_CYSIZE = 31 'height of title bar
Public Sub Init()
WHook = SetWindowsHookEx(4, AddressOf HookProc, 0, App.ThreadID)
Call SetWindowLong(frmMain.Combo1.hwnd, GWL_EXSTYLE, &H80)
Call SetParent(frmMain.Combo1.hwnd, GetParent(frmMain.hwnd))
End Sub
Public Sub Terminate()
Call UnhookWindowsHookEx(WHook)
Call SetParent(frmMain.Combo1.hwnd, frmMain.hwnd)
End Sub
Public Function HookProc&(ByVal nCode&, ByVal wParam&, Inf As CWPSTRUCT)
Dim R As RECT
Static LastParam&
If Inf.hwnd = GetParent(frmMain.Combo1.hwnd) Then
If Inf.Message = WM_COMMAND Then
Select Case LastParam
Case frmMain.Combo1.hwnd: Call frmMain.Combo1.SetFocus
End Select
ElseIf Inf.Message = WM_SETCURSOR Then
LastParam = Inf.wParam
End If
ElseIf Inf.hwnd = frmMain.hwnd Then
If Inf.Message = WM_NCPAINT Or Inf.Message = WM_MOVE Then
Call GetWindowRect(frmMain.hwnd, R)
Call SetWindowPos(frmMain.Combo1.hwnd, 0, R.Right - 250, _
R.Top + 4, 150, 50, SWP_FRAMECHANGED)
End If
End If
End Function
EN EL FORM:
Option Explicit
Public Sub Combo1_Click()
MsgBox "hola"
End Sub
Private Sub Form_Load()
Combo1.AddItem "Reg 01"
Combo1.AddItem "Reg 02"
Combo1.AddItem "Reg 03"
Call Init
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call Terminate
End Sub