By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,239 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,239 IT Pros & Developers. It's quick & easy.

How to see if another application/Window is minimized?

P: n/a
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
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
[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" <pi**********@hotmail.com> wrote in message
news:eW**************@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

Nov 20 '05 #2

P: n/a
* "Shakir Hussain" <sh**@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/>
Nov 20 '05 #3

P: n/a
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.Calling Convention.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]" <hi***************@gmx.at> wrote in message
news:OT**************@tk2msftngp13.phx.gbl...
* "Shakir Hussain" <sh**@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/>

Nov 20 '05 #4

P: n/a
* "DraguVaso" <pi**********@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.Calling Convention.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/>
Nov 20 '05 #5

P: n/a
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.Calling Convention.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.Calling Convention.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.Calling Convention.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.Calling Convention.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]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
* "DraguVaso" <pi**********@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.Calling Convention.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/>

Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.