PC Review


Reply
Thread Tools Rate Thread

Bring another Window to Front

 
 
DraguVaso
Guest
Posts: n/a
 
      13th Jul 2004
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






 
Reply With Quote
 
 
 
 
Guest
Posts: n/a
 
      13th Jul 2004
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
>
>
>
>
>
>
>.
>

 
Reply With Quote
 
DraguVaso
Guest
Posts: n/a
 
      13th Jul 2004
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???

<(E-Mail Removed)> wrote in message
news:2c84001c468e5$ea7ce670$(E-Mail Removed)...
> 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
> >
> >
> >
> >
> >
> >
> >.
> >



 
Reply With Quote
 
DraguVaso
Guest
Posts: n/a
 
      16th Jul 2004
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.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


"DraguVaso" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can not bring IE6 window to front Terry Locke Windows XP Internet Explorer 7 28th Nov 2005 04:24 PM
How do I bring a <a TARGET=xxx> window to front if it's already op =?Utf-8?B?QnJpYW4gS2l0dA==?= Microsoft Dot NET 4 25th Aug 2005 03:37 AM
Bring another Window to Front DraguVaso Microsoft Dot NET 1 16th Jul 2004 01:17 PM
Bring another Window to Front DraguVaso Microsoft Dot NET Framework Forms 1 16th Jul 2004 01:17 PM
Problem: Clicking on window doesn't bring window to front jinman@uwf.edu Windows XP General 2 13th Nov 2003 06:57 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:17 PM.