Solved

very easy question...

Posted on 2002-07-29
7
316 Views
Last Modified: 2008-02-01
how to activate a win32 app???
I start myapp, then start onother app, and I want to bring to front myapp after one minites...
I've tried SetForgroundWindow, but it only flashes the myapp's icon on the taskbar, but did not puts myapp to the front, and set the focus to it. How to do that?
0
Comment
Question by:cosie
7 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 7185683
Have you tried 'BringWindowToTop()'?
0
 
LVL 4

Expert Comment

by:mblat
ID: 7185795
or SetWindowPos(.....) ?
0
 
LVL 22

Accepted Solution

by:
ambience earned 100 total points
ID: 7187019
As far as i know the SetForegroundWindow function on Windows 2000 cannot force a window to the foreground while the user is working with another window. Instead, SetForegroundWindow will activate the window and call the FlashWindowEx function to notify the user.  You can use the following undocumented API to bring a window to front.

void SwitchToThisWindow (HWND hWnd, BOOL bRestore);
typedef void (WINAPI *PROC) (HWND, BOOL);

PROC SwitchToThisWindow = (PROC)GetProcAddress(GetModuleHandle("user32"), "SwitchToThisWindow");  

the second parameter specifies whether the window should restores its position if it is minimized:

SwitchToThisWindow(hWnd, TRUE);

hope this helps ...
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 8

Expert Comment

by:fl0yd
ID: 7187598
ambience,
    just out of curiosity: How did you come across that function? I mean, this is nothing that you do stumble into when doing 'normal' business. After all, it's undocumented probably for the reason to keep people from using it ;)
    kudos to those people that do not fear reverse engineering in this day and age of evergrowing complexity of computer systems and os's.

cosie,
    like ambience already said, the behaviour you are experiencing is meant to work this way. This is a security feature. If you read through the MSDN description that tells you what conditions have to be met to get SetForegroundWindow to work, you will quickly see why it is implemented the way it is. To give you an example: Let's assume your screen saver asks the user to enter the password when it returns, this could result in a potential security hazard. Some virus-like application running in the background could intercept that system message, call SetForegroundWindow to gain input focus, have the unsuspecting user type his/her password and save it. In general, the user should be in absolute control over which application has the input focus any given time. That's why the SetForegroundWindow-fxn has been 'disabled' on win nt systems >=5.0.
0
 
LVL 22

Expert Comment

by:ambience
ID: 7187752
i found a mention of it on web somewhere, but cant remember the link (was quite long ago) ...
0
 

Author Comment

by:cosie
ID: 7190168
W2k test results:
SwitchToThisWindow(hWnd, TRUE) for the app itself worked only with 2nd param set to false, anyway worked only, if the app was minimized. (So I had to add a SetWindowState and SetFocus)

If I called it from an outofprocess exe component, the same effect occured.

If I called it from another process, which had the focus, it worked regardless the second param...

Interesting, but who cares?

Thanx, pal.

0
 

Expert Comment

by:jrhk
ID: 7421035
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 how to clear a vector as well as how to detect empty vectors in C++.

809 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