?
Solved

Modal Dialog on Top

Posted on 1997-02-20
13
Medium Priority
?
710 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 

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 600 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

752 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