Window Manipulation
Posted: 2002-06-01
By: ArchiveBot
Viewed: 66
Filed Under:
No attachments for this post
This code will show you how to retreive a handle of an open window and how to manipulate that window once you have it's handle.
Original Author: Joe Estock
API Declarations
'Add the following declarations to your form's
'General (Declarations) section
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FlashWindow Lib "user32" (ByVal hwnd As Long, ByVal bInvert As Long) As Long
Private Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Code
'Add a command button to a form, set the command
'button's name to Command1, then add this code
'to your form's code.
Private Sub Command1_Click()
Dim lhWnd As Long 'Holds the handle to the window
'The FindWindow parameter is as follows:
'lpClassName: This is the name of the class
' Use the Spy ++ utility to retreive
' this information
'lpWindowName: This is the caption of the window
lhWnd = FindWindow("Minesweeper", "Minesweeper")
Text1.Text = lhWnd
'Make sure we have a valid handle
If lhWnd <> 0 Then
'Flash the window by inverting it
'If it has focus, then remove focus
'If it doesn't have focus, give it focus
FlashWindow lhWnd, 1
End If
If lhWnd <> 0 Then
'Change the window's caption
SetWindowText lhWnd, "ChangedSweeper"
End If
End Sub
Comments on this post
No comments have been added for this post.
You must be logged in to make a comment.