Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Never Losing the Focus

Posted on 2001-07-10
10
Medium Priority
?
374 Views
Last Modified: 2013-11-20
Simple question.

I have an MFC Application.

When the user clicks outside the application (for example on another application's window or on the desktop), I want to reactivate my application's main window.

I screwed around a little with SetForegroundWindow() and the WM_ACTIVATE messages, catching them in WindowProc(), etc., but got no luck. In Windows 2000, the best I can do is to have the application's icon BLINK on the taskbar (I can never have it come to the front).

So... Do I suck or does Windows 2000 suck?
Thanks for your help!
0
Comment
Question by:gaggio
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 2

Expert Comment

by:exelrud
ID: 6270951
0
 
LVL 2

Expert Comment

by:exelrud
ID: 6270953
Do this app is a window or a dialog ? If it is a dialog you can try using a system modal one.
0
 
LVL 4

Expert Comment

by:aponcealbuerne
ID: 6270978
Some code will useful.
but, are you usign
ShowWindow(SW_RESTORE);
before SetForegroundWindow()

hope helps
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:tvanceplus
ID: 6271092
Can you use SetCapture() to take away all of the system messages and use ReleaseCapture() when you're finished?

These names may be off a little bit but it's close. They are in the SDK.
0
 
LVL 86

Expert Comment

by:jkr
ID: 6271303
Use 'SetWindowPos()' with the 'WS_EX_TOPMOST' style.

Quote from the docs:

"With Windows versions 3.1 and later, windows can be moved to the top of the Z-order and locked there by setting their WS_EX_TOPMOST styles. Such a topmost window maintains its topmost position even when deactivated. For example, selecting the WinHelp Always On Top command makes the Help window topmost, and it then remains visible when you return to your application.

To create a topmost window, call SetWindowPos with the pWndInsertAfter parameter equal to &wndTopMost, or set the WS_EX_TOPMOST style when you create the window."

See also

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_cwnd.3a3a.setwindowpos.asp('CWnd::SetWindowPos')

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcemfc/htm/cwnd_17.asp ('CWnd::CreateEx')

http://support.microsoft.com/support/kb/articles/Q108/3/15.asp ('HOWTO: Keep an MDI Window Always on Top')
0
 
LVL 1

Author Comment

by:gaggio
ID: 6273333
I am sorry jkr, but this is not exactly what I would like to do. So let me refine the question. I got some ideas with the other posts, but could not solve my problem.

I would like my window to be able to be deactivated. Let's say that I catch the deactivation message in WindowProc. At this time, I am launching a thread, which waits 2 seconds and then reactivate the window.

How do I do this?
Currently, it works only the first time. The "bring it back to front" thread does (just and) exactly this:

Sleep(2000);
mywindow->PostMessage(WM_ACTIVATE,WA_ACTIVE,save);

"save" is the LPARAM of the WM_ACTIVATE/WA_INACTIVE that I catch in WindowProc like this:

LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
     if(message==WM_ACTIVATE && wParam==WA_INACTIVE)
     {
          save = lParam;
          mybringbacktofrontthread.Execute();
          return TRUE;
     }
     return CFrameWnd::WindowProc(message, wParam, lParam);
}

when I put a breakpoint on PostMessage in the thread function, I see that the thread is executed each time mywindow looses focus/activation, but mywindow is brought to front only the first time.

any thought?
Thanks a lot for your help.
0
 
LVL 1

Author Comment

by:gaggio
ID: 6277850
I have found something that looks like exactly what I need - it is a function in the platform SDK called "LockSetForegroundWindow."  This function prevents other applications from stealing the foreground status and thereby interrupting user interaction.  The function is documented on the MSDN website, but my compiler does not recognize it.  I think I have included all of the necessary headers and libs, but still no luck.  Has anyone heard of or successfully used this function before?  If so, I'd love to hear about it!
0
 
LVL 1

Author Comment

by:gaggio
ID: 6277915
I have found something that looks like exactly what I need - it is a function in the platform SDK called "LockSetForegroundWindow."  This function prevents other applications from stealing the foreground status and thereby interrupting user interaction.  The function is documented on the MSDN website, but my compiler does not recognize it.  I think I have included all of the necessary headers and libs, but still no luck.  Has anyone heard of or successfully used this function before?  If so, I'd love to hear about it!
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9490293
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ'd and pts refunded

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 9537279
PAQed, with points refunded (100)

Computer101
E-E Admin
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question