INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Visual Basic (Microsoft) Versions 5/6 FAQ

Windows API

Changing Window States by SUNRlSE
Posted: 9 Jan 02

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

:+)

Back to Visual Basic (Microsoft) Versions 5/6 FAQ Index
Back to Visual Basic (Microsoft) Versions 5/6 Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close