A couple of people want to know how to change window states from VB6.
Well to do this you need to first get the handle (reference)to the window and then change the window state.
I would use first FindWindow:-
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Called like this :-
Dim lHandle As Long
Dim sClassName As String
Dim sWindowName As String
sWindowName = "MS-DOS Prompt"
lHandle = FindWindow(sClassName, sWindowName)
This will assign the handle of the window containing the text "MS-DOS Prompt" to the variable lHandle.
Now you need to change the properties of this Window.
I'd use ShowWindow :-
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Called like this:-
ShowWindow lHandle, SW_MINIMIZE
or ShowWindow lHandle, SW_HIDE
Available are:
SW_FORCEMINIMIZE - W2k minimizes even if hung
SW_HIDE - hides the window and activates another
SW_MAXIMIZE - guess
SW_MINIMIZE - rings for a pizza !
SW_RESTORE - Activates and displays the window original size
SW_SHOW - Activates and displays in current size/position
SW_SHOWDEFAULT - Sets the show state specified in the
STARTUPINFO structure
SW_SHOWMAXIMIZED - Activates and maximizes
SW_SHOWMINIMIZED - Activates and minimizes
SW_SHOWMINNOACTIVE - Min but not active
SW_SHOWNA - SW_SHOW but not active
SW_SHOWNOACTIVE - current size/position but not active
SW_SHOWNORMAL - Activates and displays in original size/position
So to maximize a window called "Microsoft Internet Explorer"
Your code could be:
'Declarations
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Dim lHandle As Long
Dim sClassName As String
Dim sWindowName As String
Private Sub Command1_Click()
'Get Handle
sWindowName = "Microsoft Internet Explorer"
lHandle = FindWindow(sClassName, sWindowName)
'Change State
ShowWindow lHandle, SW_MAXIMIZE
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.