473,765 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Force form to foreground?

Hi,

How can I force a form to the foreground no matter what application is
in front?

Thanks!

M O J O
Nov 13 '07 #1
17 12628
On Nov 13, 10:58 am, M O J O <m...@nospam.no spamwrote:
Hi,

How can I force a form to the foreground no matter what application is
in front?

Thanks!

M O J O
TopMost = True

Thanks,

Seth Rowe

Nov 13 '07 #2
Hi Seth,

No TopMost will not do. The form cannot be TopMost.

It's a hidden menu form and when he user presses Windows+I the menu form
must show and come to the foreground (steal the foreground) without
being topmost.

Any other idea?

Kind regards
M O J O

rowe_newsgroups skrev:
On Nov 13, 10:58 am, M O J O <m...@nospam.no spamwrote:
>Hi,

How can I force a form to the foreground no matter what application is
in front?

Thanks!

M O J O

TopMost = True

Thanks,

Seth Rowe
Nov 13 '07 #3
Like the Outlook reminder window ... it steals the foreground without
being topmost.

????

Thanks!
M O J O

M O J O skrev:
Hi Seth,

No TopMost will not do. The form cannot be TopMost.

It's a hidden menu form and when he user presses Windows+I the menu form
must show and come to the foreground (steal the foreground) without
being topmost.

Any other idea?

Kind regards
M O J O

rowe_newsgroups skrev:
>On Nov 13, 10:58 am, M O J O <m...@nospam.no spamwrote:
>>Hi,

How can I force a form to the foreground no matter what application is
in front?

Thanks!

M O J O

TopMost = True

Thanks,

Seth Rowe
Nov 13 '07 #4
On Nov 13, 9:39 am, M O J O <m...@nospam.no spamwrote:
Like the Outlook reminder window ... it steals the foreground without
being topmost.

????

Thanks!
M O J O

M O J O skrev:
Hi Seth,
No TopMost will not do. The form cannot be TopMost.
It's a hidden menu form and when he user presses Windows+I the menu form
must show and come to the foreground (steal the foreground) without
being topmost.
Any other idea?
Kind regards
M O J O
rowe_newsgroups skrev:
On Nov 13, 10:58 am, M O J O <m...@nospam.no spamwrote:
Hi,
>How can I force a form to the foreground no matter what application is
in front?
>Thanks!
>M O J O
TopMost = True
Thanks,
Seth Rowe- Hide quoted text -

- Show quoted text -
So, your trying to force a window to steal focus... Well, in the old
days you used to do that by calling SetForegroundWi ndow - the problem
is that this won't always work anymore. Microsoft "fixed" this
function in Windows98 timeframe to prevent exactly what your trying to
do - steal the focus...

Fortunately, there is a way around it. But, it involves a little more
work - you have to couple the call with a call to AttachThreadInp ut.
All-in-all your looking at several api calls. Here is an example in
classic VB, by the great Karl Peterson:

http://vb.mvps.org/samples/project.asp?id=ForceFore

If you need help converting this to VB.NET, let us know.

--
Tom Shelton

Nov 13 '07 #5
Hi Tom,

It is already VB. :o)

Well When I try this...

Call ForceForeground Window(CLng(myW indowsForm.Hand le))

....I get this exception:

"Attempted to read or write protected memory. This is often an
indication that other memory has been corrupted."
Any idea?

Thanks!

M O J O

Tom Shelton skrev:
On Nov 13, 9:39 am, M O J O <m...@nospam.no spamwrote:
>Like the Outlook reminder window ... it steals the foreground without
being topmost.

????

Thanks!
M O J O

M O J O skrev:
>>Hi Seth,
No TopMost will not do. The form cannot be TopMost.
It's a hidden menu form and when he user presses Windows+I the menu form
must show and come to the foreground (steal the foreground) without
being topmost.
Any other idea?
Kind regards
M O J O
rowe_newsgrou ps skrev:
On Nov 13, 10:58 am, M O J O <m...@nospam.no spamwrote:
Hi,
How can I force a form to the foreground no matter what application is
in front?
Thanks!
M O J O
TopMost = True
Thanks,
Seth Rowe- Hide quoted text -
- Show quoted text -

So, your trying to force a window to steal focus... Well, in the old
days you used to do that by calling SetForegroundWi ndow - the problem
is that this won't always work anymore. Microsoft "fixed" this
function in Windows98 timeframe to prevent exactly what your trying to
do - steal the focus...

Fortunately, there is a way around it. But, it involves a little more
work - you have to couple the call with a call to AttachThreadInp ut.
All-in-all your looking at several api calls. Here is an example in
classic VB, by the great Karl Peterson:

http://vb.mvps.org/samples/project.asp?id=ForceFore

If you need help converting this to VB.NET, let us know.

--
Tom Shelton
Nov 13 '07 #6
It is already VB. :o)

It may be VB, but it isn't VB.Net :-)

I didn't download the code, but judging by the timestamp it was last
updated while VB.NET was still pre-release. One thing you might need
to do is update the API calls to the .Net equivalents, and for that
you should see www.pinvoke.net

After the conversion, let us know if the error disappears.

Thanks,

Seth Rowe

Nov 13 '07 #7
On Nov 13, 11:45 am, rowe_newsgroups <rowe_em...@yah oo.comwrote:
It is already VB. :o)

It may be VB, but it isn't VB.Net :-)

I didn't download the code, but judging by the timestamp it was last
updated while VB.NET was still pre-release. One thing you might need
to do is update the API calls to the .Net equivalents, and for that
you should seewww.pinvoke. net

After the conversion, let us know if the error disappears.

Thanks,

Seth Rowe
Seth, you are correct - it's VB Classic. I'm fairly sure, that I
indicated that in my post :) If not, I apologize to the OP.

--
Tom Shelton

Nov 13 '07 #8
Hi MOJO,

Yes, jsut as Tom stated, calling AttachThreadInp ut with SetForegroundWi ndow
will definitely bring your window to foreground. But this is not a
recommended design on Windows, normally, you should just call
SetForegroundWi ndow. If the Windows finds that the end user is busy doing
operations, it will flash your window with blue colors in the taskbar. This
is a more recommended behavior than using AttachThreadInp ut.

Furthermore, SetForegroundWi ndow Win32 API is encapsulated in the .Net
Framework Form.Activate() method.
Public Sub Activate()
IntSecurity.Mod ifyFocus.Demand
If (MyBase.Visible AndAlso MyBase.IsHandle Created) Then
If Me.IsMdiChild Then
Me.MdiParentInt ernal.MdiClient .SendMessage(&H 222,
MyBase.Handle, 0)
Else
UnsafeNativeMet hods.SetForegro undWindow(New HandleRef(Me,
MyBase.Handle))
End If
End If
End Sub

So you may call me.Activate() to bring the form to the foreground.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 14 '07 #9
On Nov 13, 8:16 pm, je...@online.mi crosoft.com ("Jeffrey Tan[MSFT]")
wrote:
Hi MOJO,

Yes, jsut as Tom stated, calling AttachThreadInp ut with SetForegroundWi ndow
will definitely bring your window to foreground. But this is not a
recommended design on Windows, normally, you should just call
SetForegroundWi ndow. If the Windows finds that the end user is busy doing
operations, it will flash your window with blue colors in the taskbar. This
is a more recommended behavior than using AttachThreadInp ut.

Furthermore, SetForegroundWi ndow Win32 API is encapsulated in the .Net
Framework Form.Activate() method.
Public Sub Activate()
IntSecurity.Mod ifyFocus.Demand
If (MyBase.Visible AndAlso MyBase.IsHandle Created) Then
If Me.IsMdiChild Then
Me.MdiParentInt ernal.MdiClient .SendMessage(&H 222,
MyBase.Handle, 0)
Else
UnsafeNativeMet hods.SetForegro undWindow(New HandleRef(Me,
MyBase.Handle))
End If
End If
End Sub

So you may call me.Activate() to bring the form to the foreground.

Hmmm... Learns something new each day. I know it's not
"recommende d", but there times when it makes sense - like the Outlook
notification type windows as the OP mentioned. So, could you call
AttachThreadInp ut and then call Form.Activate? I might have to try
taht :)

--
Tom Shelton

Nov 14 '07 #10

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

Similar topics

2
2647
by: Kiteman - Canada | last post by:
Is there an event triggered when a form is dragged by its titlebar? I have two forms on screen - the main form is draggable and I need the secondary form to automatically reposition itself adjacent to the main form if the main form is relocated. Tom
2
4181
by: Mark B | last post by:
2nd post: Does anyone know how to set the height of a form passed the inbuilt limit? I want to set the height of a form so that it will fill a portrait page when printing. When the screen resolution is <= 1024x800, the fm.InsideHeight is capped by Access so that the height is reduced.
5
7276
by: Danny | last post by:
I am using a switchboard to load a form that I would like to display in datasheet view or table view. But it does not go into that mode when using the switchboard wizard to launche the form. is there a way to set this on the form's load property? Danny
7
2599
by: one2001boy | last post by:
Hello, I have an executable file lanuched from another application. is there a way to make thie executable file foreground if it is launched from other application? Thanks.
2
1294
by: BluDog | last post by:
Hi I have an interface and i want to impose that implementing classes inherit from Windows.Forms.Form. As there is no IForm and an interface cannot inherit from a non interface class, is there a sensible way of doing this? Cheers blu
3
1004
by: tantiboh | last post by:
I've got a program that is heavily processor intensive when it's being run. At seemingly random intervals, the program's foreground locks up and doesn't refresh until it has completed its processes. The lockup doesn't occur every time the program is run, though rest assured it will occur if the program is run long enough (usually about 45 secs). In addition, it always happens if I switch to a different application, whether I switch back or not....
6
5019
by: Jen | last post by:
I've implemented single-instance functionality in my .exe by using the mutex method. Works great. But when the .exe detects that it is not the first instance I want to bring the main window of the first instance to the foreground and set focus to it before the .exe exits. Is this possible using pure .NET calls or do I need Windows API calls and what are they?
0
1102
by: lyle fairfield | last post by:
Or I screwed up. I think that's it. BUT! This seems to work: With Form_Whatever .Modal = True .Visible = True End With
1
1936
by: Jesse Jones | last post by:
Anyone, I am using a log in form on my database. Along with the credentials, the employee table has a true/false box that defines if the user's password needs to be reset. The default value of this is true (so that when a new employee is added, the logon will require their password is changed). I have the LogOn form working perfectly. It sends the proper users (those who are marked as requiring a password reset by a true value in the...
0
9399
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9835
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6649
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.