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

Bring another Window to Front

P: n/a
Hi,

My application has some interaction with an other application. I sometimes
need to put the other application to the front. The problem is that I'm not
able to get a nice solution to work in every case. I tryed two ways: one way
it disn't maximazi the Windowd when it was Minimized, in the other way it
resized the application when it was maximzed.

First I take a Handle to the other Window with the
"Process.GetProcessesByName("EXTRA")" and with the "Dim handle As IntPtr =
Process.MainWindowHandle"

First 'solution':
SetForegroundWindow(handle)
This gives me the problem with Mimized Window that gets the focus, but

Second 'solution':
ShowWindow(handle, SW_RESTORE) 'SW_RESTORE = 9
SetForegroundWindow(handle)
This gives me the problem with the Maximized Window that is suddenly
resized.

What I actually need is a solution that works always:
When the Windowd is Maximized, it has to keep Maximized. When it is Resized
it has to stay Resized. When it is Minimized it should be Restored (to the
last Status: Maxmimized or Resized).
I found some stuff about the IsIconic-API, but it didn't seem to work.

Does anybody knows a solution for my problem? I'm really stuck with it :-/

thanks a lot in advance,

Pieter


Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You should not be playing with focus... you should be
setting .Activate = True
-----Original Message-----
Hi,

My application has some interaction with an other application. I sometimesneed to put the other application to the front. The problem is that I'm notable to get a nice solution to work in every case. I tryed two ways: one wayit disn't maximazi the Windowd when it was Minimized, in the other way itresized the application when it was maximzed.

First I take a Handle to the other Window with the
"Process.GetProcessesByName("EXTRA")" and with the "Dim handle As IntPtr =Process.MainWindowHandle"

First 'solution':
SetForegroundWindow(handle)
This gives me the problem with Mimized Window that gets the focus, but
Second 'solution':
ShowWindow(handle, SW_RESTORE) 'SW_RESTORE = 9
SetForegroundWindow(handle)
This gives me the problem with the Maximized Window that is suddenlyresized.

What I actually need is a solution that works always:
When the Windowd is Maximized, it has to keep Maximized. When it is Resizedit has to stay Resized. When it is Minimized it should be Restored (to thelast Status: Maxmimized or Resized).
I found some stuff about the IsIconic-API, but it didn't seem to work.
Does anybody knows a solution for my problem? I'm really stuck with it :-/
thanks a lot in advance,

Pieter


.

Nov 20 '05 #2

P: n/a
Thanks for the input, but how do I do that?
It's the way you should do that with a Form in the Application itself, but
how about doing this with another Windowd? for exemple a Word-document that
is opened? How do you set an Activate on that???

<an*******@discussions.microsoft.com> wrote in message
news:2c*****************************@phx.gbl...
You should not be playing with focus... you should be
setting .Activate = True
-----Original Message-----
Hi,

My application has some interaction with an other

application. I sometimes
need to put the other application to the front. The

problem is that I'm not
able to get a nice solution to work in every case. I

tryed two ways: one way
it disn't maximazi the Windowd when it was Minimized, in

the other way it
resized the application when it was maximzed.

First I take a Handle to the other Window with the
"Process.GetProcessesByName("EXTRA")" and with the "Dim

handle As IntPtr =
Process.MainWindowHandle"

First 'solution':
SetForegroundWindow(handle)
This gives me the problem with Mimized Window that gets

the focus, but

Second 'solution':
ShowWindow(handle, SW_RESTORE) 'SW_RESTORE = 9
SetForegroundWindow(handle)
This gives me the problem with the Maximized Window that

is suddenly
resized.

What I actually need is a solution that works always:
When the Windowd is Maximized, it has to keep Maximized.

When it is Resized
it has to stay Resized. When it is Minimized it should be

Restored (to the
last Status: Maxmimized or Resized).
I found some stuff about the IsIconic-API, but it didn't

seem to work.

Does anybody knows a solution for my problem? I'm really

stuck with it :-/

thanks a lot in advance,

Pieter


.

Nov 20 '05 #3

P: n/a
I found it! Thanks to Herfried!

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
"DraguVaso" <pi**********@hotmail.com> wrote in message
news:Oy*************@TK2MSFTNGP09.phx.gbl...
Hi,

My application has some interaction with an other application. I sometimes
need to put the other application to the front. The problem is that I'm not able to get a nice solution to work in every case. I tryed two ways: one way it disn't maximazi the Windowd when it was Minimized, in the other way it
resized the application when it was maximzed.

First I take a Handle to the other Window with the
"Process.GetProcessesByName("EXTRA")" and with the "Dim handle As IntPtr =
Process.MainWindowHandle"

First 'solution':
SetForegroundWindow(handle)
This gives me the problem with Mimized Window that gets the focus, but

Second 'solution':
ShowWindow(handle, SW_RESTORE) 'SW_RESTORE = 9
SetForegroundWindow(handle)
This gives me the problem with the Maximized Window that is suddenly
resized.

What I actually need is a solution that works always:
When the Windowd is Maximized, it has to keep Maximized. When it is Resized it has to stay Resized. When it is Minimized it should be Restored (to the
last Status: Maxmimized or Resized).
I found some stuff about the IsIconic-API, but it didn't seem to work.

Does anybody knows a solution for my problem? I'm really stuck with it :-/

thanks a lot in advance,

Pieter


Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.