?
Solved

SHOWWINDOW API - Hide then show the same window.

Posted on 2005-03-15
10
Medium Priority
?
821 Views
Last Modified: 2012-06-27
I have the following procedure... I hide the window then I want to show it again, this code does not work. You can try this with calculator. Does anyone have a soultion to this problem.

Thanks in advance


Mark

Public Sub Dock_Window( _
        ByVal sAppHandle As Long, _
        ByVal lParentHandle As Long)

        Dim lOriginalParent As Long
        lOriginalParent = GetParent(sAppHandle)

        Call ShowWindow(sAppHandle, 0)                         'Hides the window
        Application.DoEvents()
        Call SetParent(sAppHandle, lOriginalParent)
        Call ShowWindow(sAppHandle, 1)

    End Sub
0
Comment
Question by:MarkNieuwoudt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13543370
where are you API declarations?
0
 
LVL 12

Expert Comment

by:S-Twilley
ID: 13543373
... and as far as i know, you want to use Integer instead of Long now...

Public Sub Dock_Window( _
        ByVal sAppHandle As Integer, _
        ByVal lParentHandle As Integer)

        Dim lOriginalParent As Integer
0
 

Author Comment

by:MarkNieuwoudt
ID: 13543415
s-Twilley

Here is the API declaration. Where can I find a list of all the declarations which return integers instead of longs.

 Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
   

Thanks

Mark
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Accepted Solution

by:
S-Twilley earned 172 total points
ID: 13543434
i think nearly all (if not all) API's are using integers instead of longs... at least the window related ones.

Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String) As Integer

As for return values... Im not too sure off the top of my head
==========

The other thing with API's in .NET that might cause you problems is the "Any" keyword... you can't use it in .NET, so just replace it with the expected data type, or make multiple API declarations of the same API with varying datatypes in place of the Any keyword
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 13545605
Are you working with windows external to your application?

Bob
0
 
LVL 86

Assisted Solution

by:Mike Tomlinson
Mike Tomlinson earned 164 total points
ID: 13547136
You don't need the GetParent() and SetParent() calls.  Try this simple example:

    Private Declare Function ShowWindow Lib "user32" Alias "ShowWindow" (ByVal hwnd As Integer, ByVal nCmdShow As Integer) As Integer

    Private Const SW_HIDE As Integer = 0
    Private Const SW_NORMAL As Integer = 1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Button1.Enabled = False

        ' start and show calc for 3 seconds
        Dim p As Process = Process.Start("calc")
        p.WaitForInputIdle()
        Application.DoEvents()
        System.Threading.Thread.Sleep(3000) ' wait 3 seconds

        ' hide calc for 3 seconds
        Application.DoEvents()
        ShowWindow(p.MainWindowHandle.ToInt32, SW_HIDE)
        Application.DoEvents()
        System.Threading.Thread.Sleep(3000) ' wait 3 seconds

        ' show for 3 more seconds
        Application.DoEvents()
        ShowWindow(p.MainWindowHandle.ToInt32, SW_NORMAL)
        Application.DoEvents()
        System.Threading.Thread.Sleep(3000) ' wait 3 seconds

        ' close calc
        p.CloseMainWindow()
        Application.DoEvents()

        Button1.Enabled = True
    End Sub
0
 
LVL 10

Assisted Solution

by:heintalus
heintalus earned 164 total points
ID: 13550305
Bob raised an important point which hasn't been answered

Are you working with windows external to your application?
If not and they're part of your application then you wouldn't want to use the API you'd just use the forms visible property.

If they are external then IDLE_MIND has given you som simple code that should work, but heres an expanded sample that might be of use to yourself & others who stumble across it, I've also shown how to use GetWindowPlacement & SetWindowPlacement.

Enum nCmdShow
        SW_HIDE = 0             'Hide the window.
        SW_SHOWNORMAL = 1       'Show the window and activate it (as usual).
        SW_SHOWMINIMIZED = 2    'Show the window minimized.
        SW_SHOWMAXIMIZED = 3    'Show the window maximized.
        SW_SHOWNOACTIVATE = 4   'Show the window in its most recent size and position but do not activate it.
        SW_SHOW = 5             'Show the window.
        SW_MINIMIZE = 6         'Minimize the window.
        SW_SHOWMINNOACTIVE = 7  'Show the window minimized but do not activate it.
        SW_SHOWNA = 8           'Show the window in its current state but do not activate it.
        SW_RESTORE = 9          'Restore the window (not maximized nor minimized).
    End Enum

    Structure POINTAPI
        Dim x As Integer
        Dim y As Integer
    End Structure

    Structure RECT
        Dim Left As Integer
        Dim Top As Integer
        Dim Right As Integer
        Dim Bottom As Integer
    End Structure
    Structure WINDOWPLACEMENT
        Dim Length As Integer
        Dim flags As Integer
        Dim showCmd As Integer
        Dim ptMinPosition As POINTAPI
        Dim ptMaxPosition As POINTAPI
        Dim rcNormalPosition As RECT
    End Structure


    Declare Function ShowWindow Lib "user32" (ByVal hwnd As IntPtr, ByVal Cmd As nCmdShow) As Integer
    Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As IntPtr, ByRef lpwndpl As WINDOWPLACEMENT) As Integer
    Declare Function SetWindowPlacement Lib "user32" (ByVal hwnd As IntPtr, ByRef lpwndpl As WINDOWPLACEMENT) As Integer

    ''' <summary>
    '''     Either minimizes or maximises task manager if its open
    ''' </summary>
    Private Sub btnMaximise_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMaximise.Click
        Dim WinEst As WINDOWPLACEMENT
        Dim rtn As Long
        WinEst.Length = Len(WinEst)

        Dim proc As Process
        For Each proc In Process.GetProcesses
            If proc.ProcessName.ToLower = "taskmgr" Then
                'get the current window placement
                rtn = GetWindowPlacement(proc.MainWindowHandle, WinEst)
                If WinEst.showCmd = nCmdShow.SW_SHOWMINIMIZED Then
                    ShowWindow(proc.MainWindowHandle, nCmdShow.SW_SHOWMAXIMIZED)
                Else
                    ShowWindow(proc.MainWindowHandle, nCmdShow.SW_SHOWMINIMIZED)
                End If
                Exit For
            End If
        Next
    End Sub

    ''' <summary>
    '''     Either minimizes or shows task manager in a specific position and size if its open
    ''' </summary>
    Private Sub btnMax2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMax2.Click
        Dim WinEst As WINDOWPLACEMENT
        Dim rtn As Long
        WinEst.Length = Len(WinEst)

        Dim proc As Process
        For Each proc In Process.GetProcesses
            If proc.ProcessName.ToLower = "taskmgr" Then
                'get the current window placement
                rtn = GetWindowPlacement(proc.MainWindowHandle, WinEst)
                If WinEst.showCmd = nCmdShow.SW_SHOWMINIMIZED Then
                    WinEst.rcNormalPosition.Top = 100
                    WinEst.rcNormalPosition.Bottom = 600
                    WinEst.rcNormalPosition.Left = 100
                    WinEst.rcNormalPosition.Right = 900

                    WinEst.showCmd = nCmdShow.SW_RESTORE
                    SetWindowPlacement(proc.MainWindowHandle, WinEst)
                Else
                    ShowWindow(proc.MainWindowHandle, nCmdShow.SW_SHOWMINIMIZED)
                End If
                Exit For
            End If
        Next

    End Sub

HTH
Andy
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question