For Programmers: Free Programming Magazines  


Home > Archive > Smartphone Developer Forum > May 2005 > Problems with SetForegroundWindow and Modal Dialog









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Problems with SetForegroundWindow and Modal Dialog
Chris

2005-05-23, 3:59 pm

Dear All,

I have been struggling with this problems for the past days.

My application has been developped over the .Net Compact Framework
(C#). That application is minimized and runs on the background. From
time to time, it needs to send some notification to the user. To
perform such notification, I simply use a form.

My problem occurs, when prior to performing this notification, a
windows Message Box is on focus. My application needs to bring my
notification to the foreground and to appear on top of that Message
Box. To do so, I use the following code in event handler of the load
event of my notification form.

private void Notification_Load(object sender, System.EventArgs e)
{
this.Capture = true;

IntPtr hwnd = GetCapture();

this.Capture = false;

//hwnd = FindWindow(null, "MyApplication");

if (hwnd != System.IntPtr.Zero)
{
SetForegroundWindow(hwnd);
}

//this.Invalidate();

}


When my notification is brought to front, over the Message Box, the
Message Box title changes to my notification's, i.e. the Message Box
Title becomes "MyApplication". But the content of the Message Box stays
in focus, and the soft key buttons still refer to the MessageBox
Buttons. However, clicking on one of those softkeys (althought it
appears as being one of the softkeys of the Message Box), will actually
trigger an event handled by my Notification Form.

Althought my notification seems to be in focus, my form is not drawn
over the Message Box. Can someone clear me up on what is going on here?


Christopher

Peter Foot [MVP]

2005-05-23, 8:58 pm

Is the MessageBox created within your own code? or is it a separate
application? You could programmatically close the message box if it
originates in another app, or you could use an alternative method of
displaying a notification to the user such as the shell notification APIs.

For MessageBoxes and other foremost popups, not only are they set to the
foreground but they also have the TOPMOST style so are effectively arranged
in another z-order above other windows, therefore you could make your form a
foreground window, and set it to the foreground and in theory it would show
infront of the messagebox.

If you can give a little more info on the origin and purpose of the
messagebox we can give a more precise answer.

Peter

--
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.peterfoot.net | www.opennetcf.org

"Chris" <christopher.gerlier@f-secure.com> wrote in message
news:1116862520.170354.23620@g43g2000cwa.googlegroups.com...
> Dear All,
>
> I have been struggling with this problems for the past days.
>
> My application has been developped over the .Net Compact Framework
> (C#). That application is minimized and runs on the background. From
> time to time, it needs to send some notification to the user. To
> perform such notification, I simply use a form.
>
> My problem occurs, when prior to performing this notification, a
> windows Message Box is on focus. My application needs to bring my
> notification to the foreground and to appear on top of that Message
> Box. To do so, I use the following code in event handler of the load
> event of my notification form.
>
> private void Notification_Load(object sender, System.EventArgs e)
> {
> this.Capture = true;
>
> IntPtr hwnd = GetCapture();
>
> this.Capture = false;
>
> //hwnd = FindWindow(null, "MyApplication");
>
> if (hwnd != System.IntPtr.Zero)
> {
> SetForegroundWindow(hwnd);
> }
>
> //this.Invalidate();
>
> }
>
>
> When my notification is brought to front, over the Message Box, the
> Message Box title changes to my notification's, i.e. the Message Box
> Title becomes "MyApplication". But the content of the Message Box stays
> in focus, and the soft key buttons still refer to the MessageBox
> Buttons. However, clicking on one of those softkeys (althought it
> appears as being one of the softkeys of the Message Box), will actually
> trigger an event handled by my Notification Form.
>
> Althought my notification seems to be in focus, my form is not drawn
> over the Message Box. Can someone clear me up on what is going on here?
>
>
> Christopher
>



Chris

2005-05-30, 4:00 pm

Hi Peter,

Thank you for your reply. The MessageBox I am referring to is actually
created by another application. To be more precise, we are working on
an Anti-Virus application for smartphone. To give you an example...
when we transfer a infected file via bluetooth to the device, 2
messages appear.
1) A MessageBox generated by the system asking the user whether or not
he wants to save the file that is being transferred to his device via
BlueTooth
2) Almost instantly, our application generates a notification that will
inform the user that the file being transferred is infected. For
obvious reasons this message needs to be brought to the foreground on
top of the MessageBox. But this, I can't manage so far.

Could you give me more information on how I could make this latter
notification a foreground window that would show in front on top of the
MessageBox?

I would really appreciate any type of help (sample code, ...).

Regards,

Christopher

Peter Foot [MVP] a =E9crit :
> Is the MessageBox created within your own code? or is it a separate
> application? You could programmatically close the message box if it
> originates in another app, or you could use an alternative method of
> displaying a notification to the user such as the shell notification APIs.
>
> For MessageBoxes and other foremost popups, not only are they set to the
> foreground but they also have the TOPMOST style so are effectively arrang=

ed
> in another z-order above other windows, therefore you could make your for=

m a
> foreground window, and set it to the foreground and in theory it would sh=

ow[color=darkred]
> infront of the messagebox.
>
> If you can give a little more info on the origin and purpose of the
> messagebox we can give a more precise answer.
>
> Peter
>
> --
> Peter Foot
> Windows Embedded MVP
> www.inthehand.com | www.peterfoot.net | www.opennetcf.org
>
> "Chris" <christopher.gerlier@f-secure.com> wrote in message
> news:1116862520.170354.23620@g43g2000cwa.googlegroups.com...

Chris

2005-05-31, 4:03 pm

Have also tried

IntPtr hwnd =3D GetCapture();
SetWindowPos(hwnd, HWND.TOPMOST, 0, 0, 0, 0,
SWP.NOMOVE | SWP.NOSIZE | SWP.SHOWWINDOW);

But the result is even worse.


Chris a =E9crit :[color=darkred]
> Hi Peter,
>
> Thank you for your reply. The MessageBox I am referring to is actually
> created by another application. To be more precise, we are working on
> an Anti-Virus application for smartphone. To give you an example...
> when we transfer a infected file via bluetooth to the device, 2
> messages appear.
> 1) A MessageBox generated by the system asking the user whether or not
> he wants to save the file that is being transferred to his device via
> BlueTooth
> 2) Almost instantly, our application generates a notification that will
> inform the user that the file being transferred is infected. For
> obvious reasons this message needs to be brought to the foreground on
> top of the MessageBox. But this, I can't manage so far.
>
> Could you give me more information on how I could make this latter
> notification a foreground window that would show in front on top of the
> MessageBox?
>
> I would really appreciate any type of help (sample code, ...).
>
> Regards,
>
> Christopher
>
> Peter Foot [MVP] a =E9crit :
Is.[color=darkred]
nged[color=darkred]
orm a[color=darkred]
show[color=darkred]
ys[color=darkred]
ly[color=darkred]
e?[color=darkred]

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com