Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 729
  • Last Modified:

adding button to titlebar

i would like to add a button to titlebar in vb6. the button should be able to show tooltip and it should be compatible with XP.

thanks in advance
0
kolistivra
Asked:
kolistivra
  • 5
  • 3
1 Solution
 
Stephen MandersonSoftware EngineerCommented:
Hi there, this will allow you to creat your own title bar with buttons.


'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Set form BorderStyle property to 0-None.You can add your own Command Buttons to the
'Title Bar.
'Insert this code to the module :

Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Declare Function DrawCaption Lib "User32" (ByVal hwnd As Long, ByVal hdc As _
Long, pcRect As RECT, ByVal un As Long) As Long
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
Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hwnd As _
Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Sub ReleaseCapture Lib "User32" ()
Public Const WM_NCLBUTTONDOWN = &HA1
Public Const HTCAPTION = 2

'Insert this code to your form:

'Here you can change the title bar width.
Const TitleWidth = 20
Dim r As RECT

Private Sub Form_Load()
Form1.AutoRedraw = True
Me.Cls
Me.ScaleMode = vbPixels
SetRect r, 0, 0, Me.ScaleWidth, TitleWidth
'To change the title bar color, replace the two '&H9' below with
'&H18' or '&H19' or '&H28'
DrawCaption Me.hwnd, Me.hdc, r, &H9
End Sub

Private Sub Form_Resize()
SetRect r, 0, 0, Me.ScaleWidth, TitleWidth
DrawCaption Me.hwnd, Me.hdc, r, &H9
End Sub

'The following code allow the user to move the form by pressing on the title bar. If you
'don't want this option, don't add the code below.
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Y > TitleWidth Then Exit Sub
Dim lngReturnValue As Long
If Button = 1 Then
Call ReleaseCapture
lngReturnValue = SendMessage(Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End If
End Sub

Manderson
0
 
kolistivraAuthor Commented:
thx for your effort but what i want is not drawing a titlebar from beginning. if you look at emule, you can see what i mean better.

thanks
0
 
Stephen MandersonSoftware EngineerCommented:
Sorry, there has been a similar question asked before.

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20149057.html

Hope this helps you find an answer.

Manderson
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kolistivraAuthor Commented:
yes, this is similar to what i want but:

i want a button, normal button. no images or something, a button with a dot or a letter on it.
also, it doesn't show any tooltip.

thanks
0
 
Stephen MandersonSoftware EngineerCommented:
0
 
kolistivraAuthor Commented:
it almost is what i want :)

the problem i have with it is about the icon. i am using win xp with windows classis style theme and the icon seems much bigger than it is. also, the system menu doesn't appear when i click on somewhere on titlebar. besides, it is wonderful.

if you can solve this problems, this one will be just what i want :)

thanks
0
 
Stephen MandersonSoftware EngineerCommented:
Hi there, you would have to add a manifest file. It tells you at the bottom of the above link how to do it.

Regards
Manderson
0
 
Stephen MandersonSoftware EngineerCommented:
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now