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

x
?
Solved

Window Focus Issue

Posted on 2002-07-19
6
Medium Priority
?
200 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
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

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

618 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