Solved

very easy question...

Posted on 2002-07-29
7
319 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
[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
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
Independent Software Vendors: 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 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

Technology Partners: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.net build a IF/Then Walkthrough Guide 1 320
C++ error cannot convert from std::string to const char * 6 373
Issues with C++ Class 19 121
C++ Code Issue 4 48
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
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…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…

752 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