Solved

Window Focus Issue

Posted on 2002-07-19
6
196 Views
Last Modified: 2010-04-01
I'm creating an application that polls a server at set intervals for information.  The application starts minimized and then if there is information to display, the application shows it's main window always-on-top, not activated (so when it pops up it doesn't grab focus).  My problem is that when there isn't any more information to be shown, it minimizes itself.  When it minimizes, it grabs the focus from whatever window has it.  How can I programatically minimize my window without it taking focus?
0
Comment
Question by:SampsonC
[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
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 7165245
How do you minimize the window?

PostMessage(hWnd,WM_SYSCOMMAND,SC_MINIMIZE,0);

should work...
0
 
LVL 1

Author Comment

by:SampsonC
ID: 7165643
jkr- the code snippet worked to minimize the window, but it took focus from the window that currently had it. I put your code snippet in place of the Me.WindowState = 1

Is there another way to minimize or a different way of displaying window?

Here is the code that was used.  It's in VB but I'm looking for the straight C-API of doing it.


Const Openflags = SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOACTIVATE Or SWP_SHOWWINDOW

If (bMessage = True) Or (CallsWaiting > 0) Then
'keep window on top

        res = SetWindowPos(frmQueueWatcher.hwnd, HWND_TOPMOST, _

            0, 0, 0, 0, Openflags)

       

        Me.WindowState = 0

else

        'turn off processing that keeps widow on top

        Me.WindowState = 1

End If

 
0
 
LVL 86

Expert Comment

by:jkr
ID: 7165660
Ahh, got it - the problem is that to 'minimize' a window, it has to be activated. The following workaround should do it:

HWND hActiveWnd = GetForegroundWindow (); // remember active wnd

PostMessage(hWnd,WM_SYSCOMMAND,SC_MINIMIZE,0);

SetForegroundWindow ( hActiveWnd); // bring focus back again

0
Independent Software Vendors: 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

Author Comment

by:SampsonC
ID: 7174622
jkr-

That still doesn't work.  It successfully minimized the window, but doesn't return focus to the window that previously had it.
0
 
LVL 11

Expert Comment

by:griessh
ID: 7378266
Dear SampsonC

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to

     "refund the points and PAQ at zero points"

since nobody had a satisfying answer for you.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Accepted Solution

by:
Mindphaser earned 0 total points
ID: 7419943
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maze travler 6 66
Move constructor only called if marked noexcept? 6 114
c++ syntax question 9 58
How to remove Recent Projects from Embarcadero C++ builder XE10. Berlin 2 78
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

726 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