Solved

Window Focus Issue

Posted on 2002-07-19
6
194 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Prototype for MessageDlg in Embacadero XE 2 2 37
SetCurrentDirectory path limit 7 121
What is the real difference between C++ and Visual C++.NET? 7 114
Getting IP address 8 77
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

785 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