Solved

SetForegroundWindow problem

Posted on 2002-07-19
5
894 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

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

18 Experts available now in Live!

Get 1:1 Help Now