Library code snippets

Custom Title Bar

This code and description provide a way of creating a custom window title bar, just in case you need to get rid of the normal title bar of any form. It will even provide means to move the form using the mouse like you normally would using the standard title bar of the form.

Ok, open a new vb project. Remove the form's caption and controls boxes.

Add a label to the form and set a caption for it. Make the label appear flat and give it a border. Put the label where you want the title bar to be.

Now go to the code window for the form and add the following:

Option Explicit

' API functions
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long

' Constants for above API calls
Private Const HTCAPTION = 2
Private Const WM_NCLBUTTONDOWN = &HA1

Private Sub Form_Load()
  Dim retVal As Long
   
  retVal = SetWindowText(Me.hwnd, Label1)
End Sub

Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  ReleaseCapture
  SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub

This will put a caption in the task bar (ensure that the property for the form to display in taskbar is set to true) and will allow you to move the form around when the mouse is down on the label. You can add extra labels (or buttons) and code for minimize and maximize.

Enjoy.

nzjonboy

Comments

  1. 16 Oct 2002 at 08:07
    asass
  2. 01 Jan 1999 at 00:00

    This thread is for discussions of Custom Title Bar.

Leave a comment

Sign in or Join us (it's free).

 nzjonboy

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

Want to stay in touch with what's going on? Follow us on twitter!