mfc >> MFC: Switching Modeless Dlg on TOP

by sudhir.kulkarni » Wed, 03 Dec 2003 15:53:50 GMT

Hi Friends,

I have a MFC Dialog based application. Where I create one modal dialog
(say Dlg1) from my main dialog. On click of some button on Dlg1 I
create another Dlg2 which is again a modeless one. Now I want to make
the selected dialog on top of all other dialogs. If I select dlg1 it
gets selected but doesn't come up.

In order to make selected dialog topmost I have used following code:

void CDlg2::OnActivate( UINT nState, CWnd* pWndOther, BOOL bMinimized
)
{
CDialog::OnActivate(nState, pWndOther, bMinimized);

// TODO: Add your message handler code here
if(nState == WA_CLICKACTIVE )
SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}

void CDlg2::OnActivate( UINT nState, CWnd* pWndOther, BOOL bMinimized
)
{
CDialog::OnActivate(nState, pWndOther, bMinimized);

// TODO: Add your message handler code here
if(nState == WA_CLICKACTIVE )
SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}

But somehow this doesn't work. Can anybody help me finding what's
going wrong. I am working on Win2000 OS.

Thanks and regards,
Sudhir


Similar Threads

1. Switching Modeless Dlg on TOP

2. putting a modeless dlg on another dlg (or formview)

Hi,

Is it possible to put an entire dialog on top of another dialog or
form view?  I'm doing it right now by calling the following in the
container dialogs OnInitDlg function:

int nRet = childDlg.Create(IDD_DIALOG2, this);
childDlg.ShowWindow(SW_SHOWNORMAL);

In the OnPaint, I move it into the position I want (on top of a
disabled, invisible control) with:

m_btn2.GetWindowRect(pRect);
childDlg.MoveWindow(*pRect);

In the childDlg's OnPaint function, I take care to reposition all the
buttons, etcs within the childDlg.

I've also been successful transferring messages from the included
dialog to the parent dialog using PostMessage.  I then handle the
message in the containing dialog.  Thus, if my included dialog has
buttons etc., I can handle these messages in the containing dialog as
if they were just buttons directly on the containing dialog.

However, I'm still having trouble getting all the "glue" to work
correctly.  For instance, I'd like the background color of the
childDlg to match the containing dialog.  I haven't figured out how to
do that.  In general, I have the gut feel that this has all been done
before and there's probably some very good examples on the net
somewhere.  Can someone please point me to them?

I did consider making an ActiveX control that had my desired
combination of buttons, etc. and then slapping that on the parent
dialog.  For various reasons (perhaps not good!), I dimissed this
idea.

Thanks for your suggestions, hints, and help.

David

3. Re Switching modeless dialog on TOP

4. Modeless Dialog Boxes - Knowing when it terminates, Terminate without using delete Dlg and Getting input Focus

Hi,

I am using a Modeless dialog box.

1. When I launch the Dialog box, how does one know when it ends?
     Does it have to post a message back to the calling CWnd?
     Is that the standard method?

2. I am using Animate to close the Dialog.
    Instead of using delete dlg; I call a method CloseTheDialog(),  then dlg 
= NULL;
    After the Timer has expired for my nifty closing animation, I post a 
WM_CLOSE message to itself.
    I can see it going though the motions of closing, except for the 
destructor CDlg::~CDlg.
    When the App quits, I get memory leaks because the Dlg object is still 
hanging around.
    If I don't set dlg=NULL, and in my desctructor CView::~CView, I delete 
the dialog object
    if(Dlg != NULL){ delete Dlg; }
    I see it calling the destructor CDlg::~CDlg and I get no memory leaks.
    Am I to understand that closing a Dialog Box, doesn't necessarily delete 
the Dialog Object?
    I've tried adding delete this; to no avail.
    I could post a message back to the calling CWnd, but I am curious as to 
why the object is not getting deleted.

3. It's strange, but the mouse seems to be going to the background View,
    instead of the focus being on the Modeless Dialog.
   Shouldn't the Modeless Dialog automatically regain input focus?
   Do I have to add some Mouse Even for the Modeless Dialog Box to regain 
input focus?


Thanks again,
--  


5. creating modeless dlg in OCX causes msg pump shutout when keys pressed

6. Modeless Dlg Box

Hello all,

   What I would like to do is have a modeless dialog
box available to all classes in a project.
   So, what I've done is inserted a new dialog box 
resource with an ID of 'IDD_MSG_DIALOG' and using 
ClassWizard added a string variable of 'm_static_msg'. 
   The class name is CMsgDlg, and I moved the header
'#include MsgDlg.h' into the stdafx.h, thinking this would
now make it available to everybody who has the 
#include "stdafx.h"? 
   But when I build it, I get the error:
 "error C2065: 'IDD_MSG_DIALOG' : undeclared identifier"

The ''IDD_MSG_DIALOG' is part of the:
        // Dialog Data
	//{{AFX_DATA(CMsgDlg)
	enum { IDD = IDD_MSG_DIALOG };
	CString	m_static_msg;
	//}}AFX_DATA
in the header file.

OK, so where am I going off the track?  Can I do what I 
would like to do? Or do I have to include the dialog's 
header file in every class where I would like to use it?

TIA,

Ray K.

7. Positioning a modeless child dlg

8. Modeless dialog always on top/forefront of the screen

Is there a reason why a modeless dialog is on the top/forefront of the
screen? Is there a way to prevent this? Also is there a way to minimize
the modeless child dialog when the parent is minimized? code examples
would be greatly appreciated. Thanks.