Solved

very easy question...

Posted on 2002-07-29
7
309 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 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 member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

760 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

23 Experts available now in Live!

Get 1:1 Help Now