by Eric Morrison (2 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 17th July 2000
Date Added: Mon 8th February 2021
Rating:
(1 Votes)
Changes the Title Bar on any window to whatever you like.
API Declarations
'Eric Morrison
'July 17, 2000
'Nova Scotia, Canada
'This will change the Title Bar on any window you click on
'after you click the Set TitleBar button
'Enter the following in Module (ClientToScreen uses this type)
'Type PointAPI
' x as long
' y as long
'End Type
'Form Items
'1 Text box
'Name=txtString
'
'2 Command Buttons
'Name=cmdSet
'Caption=Set TitleBar
'
'Name=cmdExit
'Caption=E&xit
'
'Extras
'On the Form set the ScaleMode Property to Pixel
Private Declare Function WindowFromPoint Lib "user32" _
(ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function SetCapture Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function ClientToScreen Lib "user32" _
(ByVal hwnd As Long, lpPoint As PointAPI) As Long
Private Declare Function SetWindowText Lib "user32" _
Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Dim blnChoose As Boolean
Unload Me
End Sub
Private Sub cmdSet_Click()
If txtString = "" Then 'Check see if txtString is empty
MsgBox "Please enter a Title in text box"
txtString.SetFocus
Exit Sub
Else
'Capture the mouse and set blnChoose to True
blnChoose = True
intRetVal = SetCapture(hwnd)
End If
End Sub
Private Sub Form_Load()
blnChoose = False 'Set blnChoose to False
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, _
X As Single, Y As Single)
Dim ptPoint As PointAPI
Dim Window As Long
'Determines the screen location when mouse button was pressed
If blnChoose Then
ptPoint.X = X
ptPoint.Y = Y
retVal = ClientToScreen(hwnd, ptPoint)
Window = WindowFromPoint(ptPoint.X, ptPoint.Y)
'Change the Windows Title Bar to the String user enters
Call SetWindowText(Window, txtString)
End If
End Sub
Private Sub txtString_KeyPress(KeyAscii As Integer)
'Check if user hits the Enter key in txtString box
If KeyAscii = 13 Then
cmdSet.SetFocus
End If
End Sub