473,408 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Bring another Window to Front

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


Jul 21 '05 #1
1 16026
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


Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: zren | last post by:
Hi, I wonder if anyone knows how to programmatically make a python window get focus and bring it to front. Here a python window means the Tkinter Toplevel widget. Thanks. Zhen
0
by: DraguVaso | last post by:
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...
1
by: Charles A. Lackman | last post by:
Hello, I have created an application that searches to see if a process is running and if it is it maximizes it's window. i.e. For Each AProcess In AProcesses If...
2
by: Don | last post by:
I have two programs. One is supposed to bring the other (which is already running either minimized or at the bottom of the window z-order) to the front so that it becomes the foremost application....
2
by: JohnR | last post by:
Let's say I have an MDI parent form with a textbox. If I create an MDI child form and, at runtime, move the MDI child window over the textbox on the MDI parent, the textbox appears in front of the...
0
by: pavan377 | last post by:
Hi folks, I got a requirement in my project where in when my application is activated another window should get activated and upon it my application should be present. Both should be in restored...
5
by: Iain Bishop | last post by:
I have a simple form with 4 command buttons and 1 label. The label is sometimes visible and sometimes not. When it is visible I want it to be in front of the buttons. I've tried bringing the label...
1
by: Marcel Brekelmans | last post by:
Hello, I have an application with a notifyIcon. When my application's main form is hidden by some other window I would like to bring it in front by single-clicking the NotifyIcon. However, I...
0
by: SAL | last post by:
Hello, I'm having trouble bringing a window to the front of all windows in an application I'm building. Actually, it's two applications that communicate via .NET Remoting. I'm trying to get the...
2
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, I asked here yesterday about bringing a form to front with hotkey while using different application then mine (meaning, when i'm using outlook, and pressing ALT+T it will bring a form from...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.