Home All Groups Group Topic Archive Search About

Force form to foreground?

Author
13 Nov 2007 3:58 PM
M O J O
Hi,

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

Thanks!

M O J O

Author
13 Nov 2007 4:03 PM
rowe_newsgroups
On Nov 13, 10:58 am, M O J O <m...@nospam.nospam> wrote:
> 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
Author
13 Nov 2007 4:35 PM
M O J O
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:
Show quoteHide quote
> On Nov 13, 10:58 am, M O J O <m...@nospam.nospam> wrote:
>> 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
>
Author
13 Nov 2007 4:39 PM
M O J O
Like the Outlook reminder window ... it steals the foreground without
being topmost.

????

Thanks!
M O J O

M O J O skrev:
Show quoteHide quote
> 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.nospam> wrote:
>>> 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
>>
Author
13 Nov 2007 5:17 PM
Tom Shelton
On Nov 13, 9:39 am, M O J O <m...@nospam.nospam> wrote:
Show quoteHide quote
> 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.nospam> wrote:
> >>> 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 SetForegroundWindow - 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 AttachThreadInput.
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
Author
13 Nov 2007 6:40 PM
M O J O
Hi Tom,

It is already VB. :o)

Well When I try this...

Call ForceForegroundWindow(CLng(myWindowsForm.Handle))

....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:
Show quoteHide quote
> On Nov 13, 9:39 am, M O J O <m...@nospam.nospam> wrote:
>> 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.nospam> wrote:
>>>>> 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 SetForegroundWindow - 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 AttachThreadInput.
> 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
>
Author
13 Nov 2007 6:45 PM
rowe_newsgroups
> 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
Author
13 Nov 2007 8:29 PM
Tom Shelton
On Nov 13, 11:45 am, rowe_newsgroups <rowe_em***@yahoo.com> wrote:
Show quoteHide quote
> > 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
Author
14 Nov 2007 3:16 AM
Jeffrey Tan[MSFT]
Hi MOJO,

Yes, jsut as Tom stated, calling AttachThreadInput with SetForegroundWindow
will definitely bring your window to foreground. But this is not a
recommended design on Windows, normally, you should just call
SetForegroundWindow. 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 AttachThreadInput.

Furthermore, SetForegroundWindow Win32 API is encapsulated in the .Net
Framework Form.Activate() method.
Public Sub Activate()
    IntSecurity.ModifyFocus.Demand
    If (MyBase.Visible AndAlso MyBase.IsHandleCreated) Then
        If Me.IsMdiChild Then
            Me.MdiParentInternal.MdiClient.SendMessage(&H222,
MyBase.Handle, 0)
        Else
            UnsafeNativeMethods.SetForegroundWindow(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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Author
14 Nov 2007 4:53 AM
Tom Shelton
On Nov 13, 8:16 pm, je***@online.microsoft.com ("Jeffrey Tan[MSFT]")
wrote:
Show quoteHide quote
> Hi MOJO,
>
> Yes, jsut as Tom stated, calling AttachThreadInput with SetForegroundWindow
> will definitely bring your window to foreground. But this is not a
> recommended design on Windows, normally, you should just call
> SetForegroundWindow. 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 AttachThreadInput.
>
> Furthermore, SetForegroundWindow Win32 API is encapsulated in the .Net
> Framework Form.Activate() method.
> Public Sub Activate()
>     IntSecurity.ModifyFocus.Demand
>     If (MyBase.Visible AndAlso MyBase.IsHandleCreated) Then
>         If Me.IsMdiChild Then
>             Me.MdiParentInternal.MdiClient.SendMessage(&H222,
> MyBase.Handle, 0)
>         Else
>             UnsafeNativeMethods.SetForegroundWindow(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
"recommended", but there times when it makes sense - like the Outlook
notification type windows as the OP mentioned.  So, could you call
AttachThreadInput and then call Form.Activate?  I might have to try
taht :)

--
Tom Shelton
Author
14 Nov 2007 5:40 AM
Jeffrey Tan[MSFT]
Hi Tom,

Yes, if you really have such requirement, you may p/invoke
AttachThreadInput and then call Form.Activate.

Additionally, I am not sure if Outlook calls AttachThreadInput internally,
but I do not think so. Because while I am performing daily works, the
Outlook Reminder or New Item Alert dialogs will just flash in the task. It
seems that they will not jump to the foreground rudely. Anyway, this is my
usage experience of Outlook :-).

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Author
14 Nov 2007 6:24 AM
Cor Ligthert[MVP]
HI guys,

Do you both make anti spam software to sell as everybody is setting there
spam on top of all other applications and make with that using the computer
impossible.

Please don't support this so much?

:-)

Cor
Author
14 Nov 2007 11:48 AM
Cor Ligthert [MVP]
I forgot to tell the reason not to support it to much, now this thread has
almost every search word in it to search how to do it on Internet.

Cor
Author
14 Nov 2007 6:53 AM
Tom Shelton
On Nov 13, 10:40 pm, je***@online.microsoft.com ("Jeffrey Tan[MSFT]")
wrote:
> Hi Tom,
>
> Yes, if you really have such requirement, you may p/invoke
> AttachThreadInput and then call Form.Activate.
>
> Additionally, I am not sure if Outlook calls AttachThreadInput internally,
> but I do not think so. Because while I am performing daily works, the
> Outlook Reminder or New Item Alert dialogs will just flash in the task. It
> seems that they will not jump to the foreground rudely. Anyway, this is my
> usage experience of Outlook :-).
>
> Thanks.

Your probably right thinking about it...  When an outlook popup
occurs, it does show up on top, and then fades out if ignored - but it
doesn't steal the focus.

--
Tom Shelton
Author
14 Nov 2007 9:21 AM
M O J O
Hi Tom,

I'm not talking about the Outlook new message popup - I'm talking about
the reminder popup. On my PC the reminder popup steals focus.

:o)

M O J O

Tom Shelton skrev:
Show quoteHide quote
> On Nov 13, 10:40 pm, je***@online.microsoft.com ("Jeffrey Tan[MSFT]")
> wrote:
>> Hi Tom,
>>
>> Yes, if you really have such requirement, you may p/invoke
>> AttachThreadInput and then call Form.Activate.
>>
>> Additionally, I am not sure if Outlook calls AttachThreadInput internally,
>> but I do not think so. Because while I am performing daily works, the
>> Outlook Reminder or New Item Alert dialogs will just flash in the task. It
>> seems that they will not jump to the foreground rudely. Anyway, this is my
>> usage experience of Outlook :-).
>>
>> Thanks.
>
> Your probably right thinking about it...  When an outlook popup
> occurs, it does show up on top, and then fades out if ignored - but it
> doesn't steal the focus.
>
> --
> Tom Shelton
>
Author
14 Nov 2007 2:32 PM
Tom Shelton
On Nov 14, 2:21 am, M O J O <m...@nospam.nospam> wrote:
Show quoteHide quote
> Hi Tom,
>
> I'm not talking about the Outlook new message popup - I'm talking about
> the reminder popup. On my PC the reminder popup steals focus.
>
> :o)
>
> M O J O
>
> Tom Shelton skrev:
>
>
>
> > On Nov 13, 10:40 pm, je***@online.microsoft.com ("Jeffrey Tan[MSFT]")
> > wrote:
> >> Hi Tom,
>
> >> Yes, if you really have such requirement, you may p/invoke
> >> AttachThreadInput and then call Form.Activate.
>
> >> Additionally, I am not sure if Outlook calls AttachThreadInput internally,
> >> but I do not think so. Because while I am performing daily works, the
> >> Outlook Reminder or New Item Alert dialogs will just flash in the task. It
> >> seems that they will not jump to the foreground rudely. Anyway, this is my
> >> usage experience of Outlook :-).
>
> >> Thanks.
>
> > Your probably right thinking about it...  When an outlook popup
> > occurs, it does show up on top, and then fades out if ignored - but it
> > doesn't steal the focus.
>
> > --
> > Tom Shelton- Hide quoted text -
>
> - Show quoted text -

Ok, those definately do....

--
Tom Shelton
Author
14 Nov 2007 11:43 AM
rowe_newsgroups
On Nov 14, 1:53 am, Tom Shelton <tom_shel***@comcast.net> wrote:
Show quoteHide quote
> On Nov 13, 10:40 pm, je***@online.microsoft.com ("Jeffrey Tan[MSFT]")
> wrote:
>
> > Hi Tom,
>
> > Yes, if you really have such requirement, you may p/invoke
> > AttachThreadInput and then call Form.Activate.
>
> > Additionally, I am not sure if Outlook calls AttachThreadInput internally,
> > but I do not think so. Because while I am performing daily works, the
> > Outlook Reminder or New Item Alert dialogs will just flash in the task. It
> > seems that they will not jump to the foreground rudely. Anyway, this is my
> > usage experience of Outlook :-).
>
> > Thanks.
>
> Your probably right thinking about it...  When an outlook popup
> occurs, it does show up on top, and then fades out if ignored - but it
> doesn't steal the focus.
>
> --
> Tom Shelton

IIRC for showing an application without stealing the focus, you have
to override the sort-of "hidden" property ShowWithoutActivation to
always return True. I used this a few years ago when I wrote a
reminder program that operated like the Outlook reminder (fading in
with a message unobtrusively, and then fading out if ignored by the
user). Oh, the memories.... :-)

Thanks,

Seth Rowe
Author
14 Nov 2007 6:07 AM
M O J O
Hi guys,

Thank you all for helping me out here!!

I REALLY appriciate it.

:o))

M O J O

M O J O skrev:
Show quoteHide quote
> Hi,
>
> How can I force a form to the foreground no matter what application is
> in front?
>
> Thanks!
>
> M O J O