SetForegroundWindow problem

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
edwardltsAsked:
Who is Participating?
 
DrDelphiConnect With a Mentor Commented:
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
 
fl0ydCommented:
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
 
edwardltsAuthor Commented:
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
 
fl0ydCommented:
BringWindowToTop( hwnd ) instead of SetForegroundWindow( hwnd ).
0
 
milindsmCommented:
Try using MB_TOPMOST flag in MessageBox API and let me know
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.