Solved

Modal Dialog on Top

Posted on 1997-02-20
13
682 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 

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

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
Show shut-down message as Windows 8 shuts down. 9 99
not able to insert into temp table 68 169
abstract class with all non abstract mentods 6 80
noX challenge 17 129
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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