How to maximize a window that is in IsIconic state

Using V6, I am trying to maximize a window that is in Isiconic state.  The following code is what I'm trying to use. Any suggestions would be very appreciative.

thanks
barrywl

Public Declare Function ShowWindow& Lib "user32" (hwnd As Long, ByVal nCmdShow As Long)

Public Function SetWindowState(hwnd As Long) As Integer
Dim x As Integer

SW_HIDE = 0
SW_MAXIMIZE = 3
SW_MINIMIZE = 6
SW_RESTORE = 9
SW_SHOW = 5
SW_SHOWMAXIMIZED = 3
SW_SHOWMINIMIZED = 2
SW_SHOWMINNOACTIVE = 7
SW_SHOWNA = 8
SW_SHOWNOACTIVATE = 4
SW_SHOWNORMAL = 1

    If IsIconic(hwnd) Then
       
       x = ShowWindow(hwnd, SW_RESTORE)
       x = ShowWindow(hwnd, SW_SHOWNORMAL)
       x = SetForegroundWindow(hwnd)
       rem Debug.Print x
       
    End If

   
End Function
LVL 1
Barry LysyApplication Systems Analyst / ProgrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Micheal AutryCommented:
The IsIconic function determines whether the specified window is minimized (iconic).  If you have already acquired the handle to the minimized (iconic) window that you want to restore then you just need to ditch the "x = ShowWindow(hwnd, SW_SHOWNORMAL)" statement as it is not needed.

If that doesn't work for you, you will need to do something like the following...

' Imported Functions

<DllImport("user32.dll")> _
Public Shared Function ShowWindow(hWnd As IntPtr, nCmdShow As Integer) As Boolean
End Function

<DllImport("user32.dll")> _
Public Shared Function IsIconic(hWnd As IntPtr) As Boolean
End Function

<DllImport("user32.dll")> _
Public Shared Function SetForegroundWindow(hWnd As IntPtr) As Boolean
End Function

<DllImport("user32.dll")> _
Public Shared Function GetForegroundWindow() As IntPtr
End Function

<DllImport("user32.dll")> _
Public Shared Function GetWindowThreadProcessId(hWnd As IntPtr, ProcessId As IntPtr) As IntPtr
End Function

<DllImport("user32.dll")> _
Public Shared Function AttachThreadInput(idAttach As IntPtr, idAttachTo As IntPtr, fAttach As Integer) As IntPtr
End Function



Stick this code into the method you are using.  Here I have renamed the handle to your window from hwnd to iconicWindowHandle

Dim threadId1 As IntPtr = GetWindowThreadProcessId(GetForegroundWindow(), IntPtr.Zero)
Dim threadId2 As IntPtr = GetWindowThreadProcessId(iconicWindowHandle, IntPtr.Zero)

If threadId1 <> threadId2 Then
      AttachThreadInput(threadId1, threadId2, 1)
      SetForegroundWindow(iconicWindowHandle)
      AttachThreadInput(threadId1, threadId2, 0)
Else
      SetForegroundWindow(iconicWindowHandle)
End If

If IsIconic(iconicWindowHandle) Then
      ShowWindow(iconicWindowHandle, SW_RESTORE)
Else
      ShowWindow(iconicWindowHandle, SW_SHOWNORMAL)
End If


If you want to maximize the window to full screen after restoring it, then you may be able to immediately call ShowWindow again using the SW_SHOWMAXIMIZED constant after the ShowWindow(iconicWindowHandle, SW_RESTORE) call, but if the window is a third party window that has its' WindowState property set to Maximized then you may not be able to maximize it to full screen.

I hope this helps put you in the right direction.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.