Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Window States

Windows API

Changing Window States

by  SUNRlSE  Posted    (Edited  )
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

Hope this helps some

:+)
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top