What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Adding Object into Title bar VB6

Adding Object into Title bar VB6
Author: Message:
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
O.P. Adding Object into Title bar VB6
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.

This post was edited on 10-31-2004 at 01:06 AM by matty.
10-31-2004 12:52 AM
Profile E-Mail PM Find Quote Report
Choli
Elite Member
*****

Avatar
Choli

Posts: 4714
Reputation: 42
42 / Male / Flag
Joined: Jan 2003
RE: Adding Object into Title bar VB6
I don't have time to understand the code :P 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?
Messenger Plus! en espaņol:
<< http://www.msgpluslive.es/ >>
<< http://foro.msgpluslive.es/ >>
:plus4:
10-31-2004 01:52 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On