Solved

Modal Dialog on Top

Posted on 1997-02-20
13
669 Views
Last Modified: 2013-11-20
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?

0
Comment
Question by:rjohnston
  • 6
  • 6
13 Comments
 
LVL 4

Expert Comment

by:mbhakta
ID: 1300333
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
 

Author Comment

by:rjohnston
ID: 1300334
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
 
LVL 4

Expert Comment

by:mbhakta
ID: 1300335
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
 

Author Comment

by:rjohnston
ID: 1300336
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
 
LVL 4

Expert Comment

by:mbhakta
ID: 1300337
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
 
LVL 4

Expert Comment

by:mbhakta
ID: 1300338
Something wrong with you e-mail address. I am getting an error if I send you the code. Please check...
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:rjohnston
ID: 1300339
Sorry, rjohnston@telsci.co.uk
0
 
LVL 4

Expert Comment

by:mbhakta
ID: 1300340
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
 
LVL 4

Expert Comment

by:mbhakta
ID: 1300341
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
 

Author Comment

by:rjohnston
ID: 1300342
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
 

Author Comment

by:rjohnston
ID: 1300343
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
 

Author Comment

by:rjohnston
ID: 1300344
mbhakta hasn't got in touch with me concerning my last point.
0
 
LVL 2

Accepted Solution

by:
sapek earned 200 total points
ID: 1300345
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

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seveā€¦
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

10 Experts available now in Live!

Get 1:1 Help Now