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
Solved

SetForegroundWindow problem

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 115
C++ mouse_event mouse look 7 96
show out valin of json for debugging in visaul c++ 1 41
Need some help with mailto 16 20
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…
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

839 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