Board index » Visual Studio » SetFocus problem.

SetFocus problem.

Visual Studio160
My application has a hidden main display window that is never used. The

application hangs out in the system tray and has a couple of configuration

windows that can be opened from the system tray menu. The program has a

couple of odd-ball fatal error scenarios. When these happen, the program

displays a fatal error message using AfxMessageBox and it shuts down normal

processing. This includes stopping the system menu so that the config

windows can't be opened.



Here's the problem:



If the AfxMessageBox window is covered by some other program, I want the

action of right clicking my system tray icon to pop the AfxMessageBox window

to the top of the display priority so that the operator can see it. Is there

a way to tell the AfxMessageBox to come to the top?



My main program window is hidden and not used. I thought maybe setting focus

to that window would somehow cause the AfxMessageBox window to pop up. It

doesn't work.



Specifically I tried: ((CMainFrame *)AfxGetMainWnd())->SetFocus();



Any ideas?


-
 

Re:SetFocus problem.

Have you tried calling SetForegroundWindow() or BringWindowToTop() with your

main window. I think the message box will follow it if you bring your window

to the top of the stack.



Tom



"Paco" <paco_beams@gmail.com>wrote in message

Quote
My application has a hidden main display window that is never used. The

application hangs out in the system tray and has a couple of configuration

windows that can be opened from the system tray menu. The program has a

couple of odd-ball fatal error scenarios. When these happen, the program

displays a fatal error message using AfxMessageBox and it shuts down

normal processing. This includes stopping the system menu so that the

config windows can't be opened.



Here's the problem:



If the AfxMessageBox window is covered by some other program, I want the

action of right clicking my system tray icon to pop the AfxMessageBox

window to the top of the display priority so that the operator can see it.

Is there a way to tell the AfxMessageBox to come to the top?



My main program window is hidden and not used. I thought maybe setting

focus to that window would somehow cause the AfxMessageBox window to pop

up. It doesn't work.



Specifically I tried: ((CMainFrame *)AfxGetMainWnd())->SetFocus();



Any ideas?





-

Re:SetFocus problem.

See below...

On Tue, 10 Apr 2007 13:51:50 GMT, "Paco" <paco_beams@gmail.com>wrote:



Quote
My application has a hidden main display window that is never used. The

application hangs out in the system tray and has a couple of configuration

windows that can be opened from the system tray menu. The program has a

couple of odd-ball fatal error scenarios. When these happen, the program

displays a fatal error message using AfxMessageBox and it shuts down normal

processing. This includes stopping the system menu so that the config

windows can't be opened.

****

Are you talking about AfxMessageBox calls you are issuing or something that is coming from

the MFC runtime?

****

Quote


Here's the problem:



If the AfxMessageBox window is covered by some other program, I want the

action of right clicking my system tray icon to pop the AfxMessageBox window

to the top of the display priority so that the operator can see it. Is there

a way to tell the AfxMessageBox to come to the top?

*****

MB_SETFOREGROUND? MB_TOPMOST? Did you read the AfxMessageBox documentation? Take a look

at my Message Box Explorer.

****

Quote


My main program window is hidden and not used. I thought maybe setting focus

to that window would somehow cause the AfxMessageBox window to pop up. It

doesn't work.

*****

Setting the focus does not move a window to the top.

****

Quote


Specifically I tried: ((CMainFrame *)AfxGetMainWnd())->SetFocus();

****

Given that SetFocus is a method of CWnd, and AfxGetMainWnd returns a CWnd *, the cast is

pointless. In fact, if the symbol CMainFrame is defined in any context other than the

mainfrm.cpp, there's some design error. You didn't say what context this is defined in.



However, since SetFocus has nothing to do with bringing the window to the top, it serves

no useful purpose except distracting the focus from whereever it is supposed to be.

joe

*****

Quote


Any ideas?



Joseph M. Newcomer [MVP]

email: newcomer@flounder.com

Web: www.flounder.com">www.flounder.com

MVP Tips: www.flounder.com/mvp_tips.htm">www.flounder.com/mvp_tips.htm

-

Re:SetFocus problem.

Hi Joe,



You say that as though those are actually listed in the AfxMessageBox

documentation.

"Joseph M. Newcomer" <newcomer@flounder.com>wrote in message



Quote
MB_SETFOREGROUND? MB_TOPMOST? Did you read the AfxMessageBox

documentation? Take a look

at my Message Box Explorer.



-

Re:SetFocus problem.

Speaking of undocumented stuff, why does MB_DEFAULT_DESKTOP_ONLY break the

messagebox? If you add that flag to a message box it doesn't display the

message box.



AliR.





"Tom Serface" <tom.nospam@camaswood.com>wrote in message

Quote
Hi Joe,



You say that as though those are actually listed in the AfxMessageBox

documentation.

"Joseph M. Newcomer" <newcomer@flounder.com>wrote in message

news:gt6n13peu9mspcrmcaeqhm7ffpv6nfrmtg@4ax.com...



>MB_SETFOREGROUND? MB_TOPMOST? Did you read the AfxMessageBox

>documentation? Take a look

>at my Message Box Explorer.







-

Re:SetFocus problem.

Thank you! SetForegroundWindow() works great.



I'm learning... I'm looking into what everyone else said.



Thanks again.



"Tom Serface" <tom.nospam@camaswood.com>wrote in message

Quote
Have you tried calling SetForegroundWindow() or BringWindowToTop() with

your main window. I think the message box will follow it if you bring your

window to the top of the stack.



Tom



"Paco" <paco_beams@gmail.com>wrote in message

news:WDMSh.7012$Kd3.2280@newssvr27.news.prodigy.net...

>My application has a hidden main display window that is never used. The

>application hangs out in the system tray and has a couple of

>configuration windows that can be opened from the system tray menu. The

>program has a couple of odd-ball fatal error scenarios. When these

>happen, the program displays a fatal error message using AfxMessageBox

>and it shuts down normal processing. This includes stopping the system

>menu so that the config windows can't be opened.

>

>Here's the problem:

>

>If the AfxMessageBox window is covered by some other program, I want the

>action of right clicking my system tray icon to pop the AfxMessageBox

>window to the top of the display priority so that the operator can see

>it. Is there a way to tell the AfxMessageBox to come to the top?

>

>My main program window is hidden and not used. I thought maybe setting

>focus to that window would somehow cause the AfxMessageBox window to pop

>up. It doesn't work.

>

>Specifically I tried: ((CMainFrame *)AfxGetMainWnd())->SetFocus();

>

>Any ideas?

>







-

Re:SetFocus problem.

Ah, I see they aren't. My aplogies. The MFC documentation is out-of-sync with the API

documentation.

joe



On Tue, 10 Apr 2007 07:36:15 -0700, "Tom Serface" <tom.nospam@camaswood.com>wrote:



Quote
Hi Joe,



You say that as though those are actually listed in the AfxMessageBox

documentation.

"Joseph M. Newcomer" <newcomer@flounder.com>wrote in message

news:gt6n13peu9mspcrmcaeqhm7ffpv6nfrmtg@4ax.com...



>MB_SETFOREGROUND? MB_TOPMOST? Did you read the AfxMessageBox

>documentation? Take a look

>at my Message Box Explorer.

Joseph M. Newcomer [MVP]

email: newcomer@flounder.com

Web: www.flounder.com">www.flounder.com

MVP Tips: www.flounder.com/mvp_tips.htm">www.flounder.com/mvp_tips.htm

-

Re:SetFocus problem.

Now we'll have to explain all the idiosyncrasies of the broken

SetForegroundWindow() behavior WinME+... I don't even know what would work

reliably.



"Tom Serface" <tom.nospam@camaswood.com>wrote in message

Quote
Have you tried calling SetForegroundWindow() or BringWindowToTop() with

your main window. I think the message box will follow it if you bring your

window to the top of the stack.



Tom



"Paco" <paco_beams@gmail.com>wrote in message

news:WDMSh.7012$Kd3.2280@newssvr27.news.prodigy.net...

>My application has a hidden main display window that is never used. The

>application hangs out in the system tray and has a couple of

>configuration windows that can be opened from the system tray menu. The

>program has a couple of odd-ball fatal error scenarios. When these

>happen, the program displays a fatal error message using AfxMessageBox

>and it shuts down normal processing. This includes stopping the system

>menu so that the config windows can't be opened.

>

>Here's the problem:

>

>If the AfxMessageBox window is covered by some other program, I want the

>action of right clicking my system tray icon to pop the AfxMessageBox

>window to the top of the display priority so that the operator can see

>it. Is there a way to tell the AfxMessageBox to come to the top?

>

>My main program window is hidden and not used. I thought maybe setting

>focus to that window would somehow cause the AfxMessageBox window to pop

>up. It doesn't work.

>

>Specifically I tried: ((CMainFrame *)AfxGetMainWnd())->SetFocus();

>

>Any ideas?

>







-

Re:SetFocus problem.

That surprises you :o)



Tom



"Joseph M. Newcomer" <newcomer@flounder.com>wrote in message

Quote
Ah, I see they aren't. My aplogies. The MFC documentation is out-of-sync

with the API

documentation.

joe



On Tue, 10 Apr 2007 07:36:15 -0700, "Tom Serface"

<tom.nospam@camaswood.com>wrote:



>Hi Joe,

>

>You say that as though those are actually listed in the AfxMessageBox

>documentation.

>"Joseph M. Newcomer" <newcomer@flounder.com>wrote in message

>news:gt6n13peu9mspcrmcaeqhm7ffpv6nfrmtg@4ax.com...

>

>>MB_SETFOREGROUND? MB_TOPMOST? Did you read the AfxMessageBox

>>documentation? Take a look

>>at my Message Box Explorer.

Joseph M. Newcomer [MVP]

email: newcomer@flounder.com

Web: www.flounder.com">www.flounder.com

MVP Tips: www.flounder.com/mvp_tips.htm">www.flounder.com/mvp_tips.htm



-