Link to home
Start Free TrialLog in
Avatar of edwardlts
edwardlts

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of DrDelphi
DrDelphi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fl0yd
fl0yd

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.
Avatar of edwardlts

ASKER

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?
BringWindowToTop( hwnd ) instead of SetForegroundWindow( hwnd ).
Try using MB_TOPMOST flag in MessageBox API and let me know