Solved

Window Focus Issue

Posted on 2002-07-19
6
188 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
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

705 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now