Hi,

How can you see with a VB.NET-application if the Window of another
Application (for exemple an opened Word-Document) is Mimized?
Is there also a way to see if it is Maximized?

Thanks a lot,

Pieter

Re: How to see if another application/Window is minimized? by Shakir

Shakir
Thu Jul 15 11:13:38 CDT 2004

[DllImport("user32")]
public static extern bool IsIconic (int hwnd);

usage

int hwnd = //get msword application handle

bool bMinimized = IsIconic (hwnd);

bMinimized = true means window is in minized state

--
Shak
(Houston)


"DraguVaso" <pietercoucke@hotmail.com> wrote in message
news:eWT5zfmaEHA.2812@TK2MSFTNGP11.phx.gbl...
> Hi,
>
> How can you see with a VB.NET-application if the Window of another
> Application (for exemple an opened Word-Document) is Mimized?
> Is there also a way to see if it is Maximized?
>
> Thanks a lot,
>
> Pieter
>
>



Re: How to see if another application/Window is minimized? by hirf-spam-me-here

hirf-spam-me-here
Thu Jul 15 11:23:10 CDT 2004

* "Shakir Hussain" <shak@fakedomain.com> scripsit:
> [DllImport("user32")]
> public static extern bool IsIconic (int hwnd);
>
> usage
>
> int hwnd = //get msword application handle
>
> bool bMinimized = IsIconic (hwnd);
>
> bMinimized = true means window is in minized state

This will allow you to check the window state, but it won't give you a
notification when the window state changes. 'hwnd' should be 'IntPtr'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Re: How to see if another application/Window is minimized? by DraguVaso

DraguVaso
Fri Jul 16 03:03:30 CDT 2004

I tried it, but unfortunately it didn't work :-(
This is the code I used:

<System.Runtime.InteropServices.DllImport("user32.dll", _
EntryPoint:="IsIconic", _
CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Private Function _
IsIconic(ByVal hWnd As IntPtr) As Boolean
End Function


Public Sub pbenmin()
Dim clsProc As New clsProcesses
Dim p As Process
p = clsProc.ProcessExtra()
Dim IsNormal As Boolean

'Dim HWND As Integer
Dim hwnd As IntPtr
hwnd = p.Handle

If hwnd.ToInt64 = 0 Then
IsNormal = False
Exit Sub
End If
If IsIconic(hwnd) <> 0 Then
IsNormal = False
End If
End Sub


The result of IsIconic was always different than 0...

Any idea what I did wrong?

"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:OTqsMgoaEHA.3356@tk2msftngp13.phx.gbl...
> * "Shakir Hussain" <shak@fakedomain.com> scripsit:
> > [DllImport("user32")]
> > public static extern bool IsIconic (int hwnd);
> >
> > usage
> >
> > int hwnd = //get msword application handle
> >
> > bool bMinimized = IsIconic (hwnd);
> >
> > bMinimized = true means window is in minized state
>
> This will allow you to check the window state, but it won't give you a
> notification when the window state changes. 'hwnd' should be 'IntPtr'.
>
> --
> Herfried K. Wagner [MVP]
> <URL:http://dotnet.mvps.org/>



Re: How to see if another application/Window is minimized? by hirf-spam-me-here

hirf-spam-me-here
Fri Jul 16 06:10:56 CDT 2004

* "DraguVaso" <pietercoucke@hotmail.com> scripsit:
> I tried it, but unfortunately it didn't work :-(
> This is the code I used:
>
> <System.Runtime.InteropServices.DllImport("user32.dll", _
> EntryPoint:="IsIconic", _
> CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall, _
> CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
> Private Function _
> IsIconic(ByVal hWnd As IntPtr) As Boolean
> End Function
>
>
> Public Sub pbenmin()
> Dim clsProc As New clsProcesses
> Dim p As Process
> p = clsProc.ProcessExtra()
> Dim IsNormal As Boolean
>
> 'Dim HWND As Integer
> Dim hwnd As IntPtr
> hwnd = p.Handle

'p#Handle' will return a /process/ handle, you need a /window/ handle.
Use 'p.MainWindowHandle' instead.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Re: How to see if another application/Window is minimized? by DraguVaso

DraguVaso
Fri Jul 16 07:16:28 CDT 2004

Thanks a lot!!! It works Great! I never thought it would be possible, hehe
:-)
I finally did it like this:

Public Const GW_HWNDPREV = 3
Private Const SW_SHOW = 5
Private Const SW_RESTORE = 9

<System.Runtime.InteropServices.DllImport("user32.dll", _
EntryPoint:="SetForegroundWindow", _
CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Public Shared Function SetForegroundWindow(ByVal handle As IntPtr) As
Boolean
' Leave function empty
End Function

<System.Runtime.InteropServices.DllImport("user32.dll", _
EntryPoint:="ShowWindow", _
CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Private Shared Function ShowWindow(ByVal handle As IntPtr, ByVal nCmd As
Int32) As Boolean
' Leave function empty
End Function

<System.Runtime.InteropServices.DllImport("user32.dll", _
EntryPoint:="IsIconic", _
CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Private Shared Function IsIconic(ByVal hWnd As IntPtr) As Boolean
' Leave function empty
End Function

<System.Runtime.InteropServices.DllImport("user32.dll", _
EntryPoint:="IsIconic", _
CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall, _
CharSet:=Runtime.InteropServices.CharSet.Unicode, SetLastError:=True)> _
Private Shared Function IsZoomed(ByVal hWnd As IntPtr) As Boolean
' Leave function empty
End Function


Public Shared Sub SetToForGround(ByVal hwnd As IntPtr)
Dim strStatus As String
'Dim hwnd As IntPtr
'hwnd = p.MainWindowHandle

If IntPtr.Zero.Equals(hwnd) Then
strStatus = ""
Exit Sub
End If
If IsIconic(hwnd) Then
strStatus = "MIN"
End If
'If IsZoomed(hwnd) Then
' IsNormal = True
'End If
'If IsIconic(hwnd) And IsZoomed(hwnd) Then
' IsNormal = True
'End If

If strStatus = "MIN" Then
'mimized
ShowWindow(hwnd, SW_RESTORE)
SetForegroundWindow(hwnd)
Else
'maximzed or restored
SetForegroundWindow(hwnd)
End If
End Sub



"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:%23SPRXWyaEHA.1732@TK2MSFTNGP09.phx.gbl...
> * "DraguVaso" <pietercoucke@hotmail.com> scripsit:
> > I tried it, but unfortunately it didn't work :-(
> > This is the code I used:
> >
> > <System.Runtime.InteropServices.DllImport("user32.dll", _
> > EntryPoint:="IsIconic", _
> >
CallingConvention:=Runtime.InteropServices.CallingConvention.StdCall, _
> > CharSet:=Runtime.InteropServices.CharSet.Unicode,
SetLastError:=True)> _
> > Private Function _
> > IsIconic(ByVal hWnd As IntPtr) As Boolean
> > End Function
> >
> >
> > Public Sub pbenmin()
> > Dim clsProc As New clsProcesses
> > Dim p As Process
> > p = clsProc.ProcessExtra()
> > Dim IsNormal As Boolean
> >
> > 'Dim HWND As Integer
> > Dim hwnd As IntPtr
> > hwnd = p.Handle
>
> 'p#Handle' will return a /process/ handle, you need a /window/ handle.
> Use 'p.MainWindowHandle' instead.
>
> --
> Herfried K. Wagner [MVP]
> <URL:http://dotnet.mvps.org/>