Results 1 to 5 of 5

Thread: VB Titlebar

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2002
    Posts
    9

    VB Titlebar

    Hi,
    Is it possible to change the default font options and color options of the titlebar of a form? Is it possible at all?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Not without changing the color scheme system wide, and the font property would apply to things printed directly to the form, not its caption property.

    In order to accomplish what you ask, you would need to remove the existing titlebar, and programmatically draw your own.

  3. #3
    Addicted Member
    Join Date
    May 2002
    Location
    Rome, Italy
    Posts
    150
    How to draw your own titlebar?
    Catholics Do It With Beads

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Play around with this...
    VB Code:
    1. Private Type RECT
    2.     Left As Long
    3.     Top As Long
    4.     Right As Long
    5.     Bottom As Long
    6. End Type
    7. Private Declare Function DrawCaption Lib "User32" (ByVal hwnd As Long, ByVal hdc As Long, pcRect As RECT, ByVal un As Long) As Long
    8. Private Declare Function SetRect Lib "User32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    9. 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
    10. Private Declare Sub ReleaseCapture Lib "User32" ()
    11.  
    12. Private Const WM_NCLBUTTONDOWN = &HA1
    13. Private Const HTCAPTION = 2
    14. Private Const TitleWidth = 20
    15. Private r As RECT
    16.  
    17. Private Sub Form_Load()
    18. Form1.AutoRedraw = True
    19. Me.Cls
    20. Me.ScaleMode = vbPixels
    21. SetRect r, 0, 0, Me.ScaleWidth, TitleWidth
    22. 'To change the title bar color, replace '&H9' here and
    23. 'in the Form_Resize event with '&H18' or '&H19' or '&H28' or
    24. 'a value representing the color of your choice
    25. DrawCaption Me.hwnd, Me.hdc, r, &H9
    26. End Sub
    27.  
    28. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    29. If Y > TitleWidth Then Exit Sub
    30. Dim lngReturnValue As Long
    31. If Button = 1 Then
    32.     Call ReleaseCapture
    33.     lngReturnValue = SendMessage(Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
    34. End If
    35.  
    36. End Sub
    37.  
    38. Private Sub Form_Resize()
    39. SetRect r, 0, 0, Me.ScaleWidth, TitleWidth
    40. DrawCaption Me.hwnd, Me.hdc, r, &H9
    41. End Sub

  5. #5
    Addicted Member
    Join Date
    May 2002
    Location
    Rome, Italy
    Posts
    150
    Thank you Mr. Hack...
    Catholics Do It With Beads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width