borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Raising Events - attaching)Next Topic (VB app. idle time) New Topic New Poll Post Reply
AndreaVB Forum : API : Form Title Bar Color
Poster Message
kjward
Level: Guest


icon Form Title Bar Color

i would like for one particular form (not all forms) to appear active in a vb application whether it is active or inactive.  how can i keep its title bar color constant?
thanks in advance

10-09-2004 at 06:57 PM
| Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon Re: Form Title Bar Color

I think you would need to subclass the form and draw the title bar by yourself. But, I dont think it would be wise, since it can make user think that form is active, even if it isnt...

____________________________
If you find the answer helpful, please mark this topic as solved.

10-09-2004 at 08:17 PM
View Profile Send Email to User Show All Posts | Quote Reply
kjward
Level: Guest

icon Re: Form Title Bar Color

we actually have "married" one form (without titlebar, etc) to the bottom of another to simulate a single form.  each form is available separately or as a "unit".  when used as a unit, we want the user to be able to move onto the lower form without the upper (master) form appearing to have lost focus.  we have managed to cover our bases regarding resizing and/or moving both as a unit, and the only bit left is the telltale titlebar.

aside from your legitimate concerns regarding potential user confusion around this, what precisely would i have to do to address the upper form's titlebar color property via the subclassing?

thanks

10-09-2004 at 08:59 PM
| Quote Reply
Goran
Level: Moderator

Registered: 16-05-2002
Posts: 1681
icon Re: Form Title Bar Color

It came accross to me that it might be done with a little easier way. The idea is to always inform original window procedure to draw active title bar. There is a WM_NCACTIVATE message, which is sent to a window procedure whenever non-client area is activated/deactivated. If you look in documentation, you will see that wParam parameter holds the value that tells window procedure to draw active or inactive title bar.

wParam=False - inactive title bar
wParam=True ' active title bar

So, basically, if we intercept WM_NCACTIVATE and set wParam to 1, it should draw active title bar no matter if form is activated or deactivated. I assumed that you are familiar with subclassing, so I left the details abour DefWindowProc and how to subclass the window. I will post here module code that will show you how to intercept this message. To run this code, in Form_Load and Form_Unload events put

StartSubclassing Me.hWnd and
StopSubclassing Me.hWnd, respectively.

Code for module

Option Explicit

Const WM_NCACTIVATE = &H86
Const GWL_WNDPROC = (-4)

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 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 PrevProc As Long

Public Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    If uMsg = WM_NCACTIVATE Then
        wParam = 1
    End If
    
    WndProc = CallWindowProc(PrevProc, hWnd, uMsg, wParam, lParam)
End Function

Public Sub StartSubclassing(ByVal hWnd As Long)
    PrevProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WndProc)
End Sub

Public Sub StopSubclassing(ByVal hWnd As Long)
    SetWindowLong hWnd, GWL_WNDPROC, PrevProc
End Sub


This is only an idea, so it might need some extra coding, but I think it will give you a good start.

And one thing more, you could also set this main form as MDIForm, and other forms to child forms, so MDIForm title bar will always be active, no matter if you work on child forms.

____________________________
If you find the answer helpful, please mark this topic as solved.

10-09-2004 at 11:59 PM
View Profile Send Email to User Show All Posts | Quote Reply
kjward
Level: Guest

icon Re: Form Title Bar Color

thanks goran...i'll have a go and let you know.

14-09-2004 at 12:38 PM
| Quote Reply
AndreaVB Forum : API : Form Title Bar Color
Previous Topic (Raising Events - attaching)Next Topic (VB app. idle time) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder