Solved

very easy question...

Posted on 2002-07-29
7
312 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
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 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

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

Suggested Solutions

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…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
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 learn how to clear a vector as well as how to detect empty vectors in C++.

932 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

11 Experts available now in Live!

Get 1:1 Help Now