Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

SHOWWINDOW API - Hide then show the same window.

Posted on 2005-03-15
10
Medium Priority
?
826 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
7 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

572 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