Solved

SetForegroundWindow problem

Posted on 2002-07-19
5
909 Views
Last Modified: 2012-05-04
This is my sample code:
...
...
SetForegroundWindow(hwnd);
status = MessageBox(NULL, "Please enter password ..",
"Smart Card Reader", MB_OKCANCEL | MB_ICONEXCLAMATION |MB_TASKMODAL);
...
...

This piece of code runs fine in WIN 95/98/NT but not in Win2K. In Win2K the messagebox will prompted behind my active dialog. Please advice me on how to solve this? I'm using Visual C++ 5
0
Comment
Question by:edwardlts
5 Comments
 
LVL 6

Accepted Solution

by:
DrDelphi earned 30 total points
ID: 7165044
Change the parameters to MessageBox to:

SetForegroundWindow(hwnd);
status = MessageBox(NULL, "Please enter password ..",
"Smart Card Reader", MB_OKCANCEL | MB_ICONEXCLAMATION |MB_SYSTEMMODAL);



Good luck!!


0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7166115
I don't quite understand why you are calling SetForegroundWindow before displaying your message box. Are you trying to change the way the message box is displayed through this function call? Also, I'd recommend you call MessageBox( hwnd, ... ); instead of specifying NULL as the owner.
0
 

Author Comment

by:edwardlts
ID: 7168977
Is there any other alternative besides setting to MB_SYSTEMMODAL? I mean when you set to SYSTEMMODAL the OS will treat it as higher priority, right?
0
 
LVL 8

Expert Comment

by:fl0yd
ID: 7169978
BringWindowToTop( hwnd ) instead of SetForegroundWindow( hwnd ).
0
 
LVL 8

Expert Comment

by:milindsm
ID: 25502250
Try using MB_TOPMOST flag in MessageBox API and let me know
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

816 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

14 Experts available now in Live!

Get 1:1 Help Now