Modal Dialog on Top

I would like to create a modal dialog, and place it as the topmost window. However, the form view which created this dialog must stay in the same Z-order position (ie if it is hidden by another window it must remain hidden).

I have tried to call SetWindowPos in the OnInitDialog handler of the modal dialog, with the 'Modal dialog' flag set. However, I find that although the modal dialog does appear (the title bar shows as inactive), whenever you click on it the formview appears behind it. I have used  &wndTop for the first parameter to SetWindowPos(). Is there anything else I need to do?

rjohnstonAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mbhaktaCommented:
Your question sounds like a patent MFC problem. Modal Dialog boxes in MFC don't work the way they work in a generic C manner. DoModal() call actually resets window styles for that dialog and overwrites it with its own stuff.

Now if you are working on 95 or NT 4.0 and Vc++ 4.x you should be able to do the following.

After you create your resource in VC++. Set the two check boxes  'System Modal' and 'Set foreground' styles. This will bring your dialog box to the top most position to all other windows.
0
rjohnstonAuthor Commented:
I have tried this solution in the past, and I get the same problem. The modal dialog box does indeed come to the foreground, but it also 'pulls' the form view that created it into the foreground as well (actually, just behind the modal dialog box). I need the form view to stay where it is, and not be displayed.
0
mbhaktaCommented:
I think you are doing something wrong somewhere. I have this code ready for you which is a formview based SDI app. If I click on the formview, I get a CDialog based modal dialog based application which remains on top without bringing the view on top no matter where you are. Get me your e-mail address and I will mail you the solution.
0
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

rjohnstonAuthor Commented:
I do not click on the formview, its an external event (a message sent by TAPI) which causes the form view to create the dialog box.
(johnston_r@telsci.co.uk)
0
mbhaktaCommented:
Shouldn't really matter, as long as it is a modal Dialog box. Anyway, i am mailing you the code as it is. Might be of help to you.
0
mbhaktaCommented:
Something wrong with you e-mail address. I am getting an error if I send you the code. Please check...
0
rjohnstonAuthor Commented:
Sorry, rjohnston@telsci.co.uk
0
mbhaktaCommented:
Sorry, mate I tried mailing you the reply to your second query. I got problems with the above e-mail address. If you haven't received any mail please reply back with a stable e-mail address.

Thanks
0
mbhaktaCommented:
I think there looks to be some real problem with your IProvider. I have been trying to mail you a reply for your OnCancel query. But no luck.

Anyway here is a copy of the same :


Yes, this is possible. This is where the pParent of the constructor comes into picture. Also you can approach the problem another way. You have the call AfxGetMainWnd(). You can use this handle to call the following in your OnOK()/OnCancel();

           
AfxGetMainWnd()->ShowWindow();
if that is a problem
AfxGetMainWnd()->SetWindowPos( &CWnd::wndTop, ....);
should work.

0
rjohnstonAuthor Commented:
I actually received your reply. I've been trying to answer it but I've had no luck!

Basically, I don't want to do anything in my OnCancel(). I want the parent to stay where it is (somewhere in the background). However, in my app, and in your test app, the parent automatically moves up the Z-order to the foreground. It is this behaviour I want to get rid of.
0
rjohnstonAuthor Commented:
I haven't received any reply. Are you still having problems with your ISP? I will repost this question to everyone at the end of the week if I don't hear from you as I really need a solution.

0
rjohnstonAuthor Commented:
mbhakta hasn't got in touch with me concerning my last point.
0
sapekCommented:
I'm not sure if understand everythink from your discusion (especially that some of it went through e-mail as I understand).
I understand that you can set your dialog to be top most window and all you need is to stop window that created the dialog to popup then the dialog is activated. I think that you will achive this when you create your dialog with owner window set to NULL. Because MFC normally won't allow you to do this you must overwrite DoModal (luckily it is virtual), copy original MFC's code, and in the call to CreateDlgIndirect (yes! modal dialogs are modless in MFC) replace the parameter CWnd::FromHandle(hWndParent) with NULL.

Adam
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.