Adding Object into Title bar VB6 - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Adding Object into Title bar VB6 (/showthread.php?tid=33869)
Adding Object into Title bar VB6 by matty on 10-31-2004 at 12:52 AM
Ok guys, I need some serious help here.
I am trying to add a Combo Box onto the title bar of my VB app. So far so good. The only problem is that I can't interact with it in any way shape or form.
Here is some code I found on PSC and just converted it for a Combo box but the result is I can't interact with it which I need to.
code: 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 Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) 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
Const WM_MOVE = &H3
Const WM_SETCURSOR = &H20
Const WM_NCPAINT = &H85
Const WM_COMMAND = &H111
Const SWP_FRAMECHANGED = &H20
Const GWL_EXSTYLE = -20
Private WHook&
Public Sub Init()
WHook = SetWindowsHookEx(4, AddressOf HookProc, 0, App.ThreadID)
Call SetWindowLong(Form1.Combo1.hwnd, GWL_EXSTYLE, &H80)
Call SetParent(Form1.Combo1.hwnd, GetParent(Form1.hwnd))
End Sub
Public Sub Terminate()
Call UnhookWindowsHookEx(WHook)
Call SetParent(Form1.Combo1.hwnd, Form1.hwnd)
End Sub
Public Function HookProc&(ByVal nCode&, ByVal wParam&, Inf As CWPSTRUCT)
Dim FormRect As Rect
Static LastParam&
If Inf.hwnd = GetParent(Form1.Combo1.hwnd) Then
If Inf.Message = WM_COMMAND Then
Select Case LastParam
Case Form1.Combo1.hwnd: Call Form1.cmdInTitlebar_Click
End Select
ElseIf Inf.Message = WM_SETCURSOR Then
LastParam = Inf.wParam
End If
ElseIf Inf.hwnd = Form1.hwnd Then
If Inf.Message = WM_NCPAINT Or Inf.Message = WM_MOVE Then
Call GetWindowRect(Form1.hwnd, FormRect)
Call SetWindowPos(Form1.Combo1.hwnd, 0, FormRect.Right - 133, FormRect.Top + 2, 75, 10, SWP_FRAMECHANGED)
End If
End If
End Function
Now I really need this to work but if it can't (which I know it can) then I will just have to decide on something else.
RE: Adding Object into Title bar VB6 by Choli on 10-31-2004 at 01:52 PM
I don't have time to understand the code but i think you should hook form1.hwnd and GetParent(Form1.hwnd). Maybe the messages sent to the combo go through the window proc of form1 and when you put it in the caption they go through the handler of its parent and you have to rediret them to its original place.
In case that does work, why don't you create a new form, that is borderless, and make it be on top of form1 and move it to be always over the caption? in that form you put the combo....
Anyway, why do you want a combo in the caption bar?
|