Solved

Window Focus Issue

Posted on 2002-07-19
6
191 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

895 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

14 Experts available now in Live!

Get 1:1 Help Now