From: Santi on
Hi All,

I have a MFC dialog based application and a COM component developed
using ATL with MFC support. The COM component exposes an interface
ISum that has a method called Add(). The Add() method displays an ATL
dialog that accepts numbers from the user on which addition is to be
performed and displays the result as well. The contents of the Add()
method are as given below:

STDMETHODIMP CSum::Add()
{
CAcceptInput dlg;
dlg.DoModal();
return S_OK;
}


On click of one of its buttons, the MFC dialog application,
instantiates the COM component and invokes the ISum::Add() method.
This displays the ATL dialog CAcceptInput. The ATL dialog appears in
the center of its parent window .i.e. the MFC dialog but if an
AFX_MANAGE_STATE() macro is introduced in the Add() method (as shown
below) then the ATL dialog does NOT appear in the center rather it is
LEFT aligned to its parent window .i.e. the MFC dialog.

STDMETHODIMP CSum::Add()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())

CAcceptInput dlg;
dlg.DoModal();
return S_OK;
}

I have verified that adding AFX_MANAGE_STATE() macro does NOT
1. Change the parent of the ATL dialog.
2. Change the window style & extended window style.

Also I debugged the OnInitDialog() method of the ATL dialog and
checked the position of the dialog, to my surprise in both the
scenarios the position was the same. Its only after the WM_INITDIALOG
and just before the display of the ATL dialog that the position gets
changed in case of the AFX_MANAGE_STATE() macro.

I am unable to understand why the ATL dialog is getting impacted with
the AFX_MANAGE_STATE() macro though there is no relationship between
them.

Can anybody provide any help on this?

Thanks,
Santosh.
From: Ajay Kalra on
I am not sure about your design but if CInputDlg is not MFC dialog(as
you seem to indicate), you dont need AFX_MANAGE_STATE macro. You need
this only in a MFC Regular DLL (is it the case for you?).

--
Ajay


>
> I have a MFC dialog based application and a COM component developed
> using ATL with MFC support. The COM component exposes an interface
> ISum that has a method called Add(). The Add() method displays an ATL
> dialog that accepts numbers from the user on which addition is to be
> performed and displays the result as well. The contents of the Add()
> method are as given below:
>
> STDMETHODIMP CSum::Add()
> {
>      CAcceptInput dlg;
>      dlg.DoModal();
>      return S_OK;
>
> }
>
> On click of one of its buttons, the MFC dialog application,
> instantiates the COM component and invokes the ISum::Add() method.
> This displays the ATL dialog CAcceptInput. The ATL dialog appears in
> the center of its parent window .i.e. the MFC dialog but if an
> AFX_MANAGE_STATE() macro is introduced in the Add() method (as shown
> below) then the ATL dialog does NOT appear in the center rather it is
> LEFT aligned to its parent window .i.e. the MFC dialog.
>
> STDMETHODIMP CSum::Add()
> {
>      AFX_MANAGE_STATE(AfxGetStaticModuleState())
>
>      CAcceptInput dlg;
>      dlg.DoModal();
>      return S_OK;
>
> }
>
> I have verified that adding AFX_MANAGE_STATE() macro does NOT
>      1.  Change the parent of the ATL dialog.
>      2.  Change the window style & extended window style.
>
> Also I debugged the OnInitDialog() method of the ATL dialog and
> checked the position of the dialog, to my surprise in both the
> scenarios the position was the same. Its only after the WM_INITDIALOG
> and just before the display of the ATL dialog that the position gets
> changed in case of the AFX_MANAGE_STATE() macro.
>
> I am unable to understand why the ATL dialog is getting impacted with
> the AFX_MANAGE_STATE() macro though there is no relationship between
> them.
>
> Can anybody provide any help on this?
>
> Thanks,
> Santosh.

From: David Ching on
"Santi" <santoshpill(a)gmail.com> wrote in message
news:0e33157b-c1bf-4a9b-ba3c-dc313e824266(a)o28g2000yqh.googlegroups.com...
> On click of one of its buttons, the MFC dialog application,
> instantiates the COM component and invokes the ISum::Add() method.
> This displays the ATL dialog CAcceptInput. The ATL dialog appears in
> the center of its parent window .i.e. the MFC dialog but if an
> AFX_MANAGE_STATE() macro is introduced in the Add() method (as shown
> below) then the ATL dialog does NOT appear in the center rather it is
> LEFT aligned to its parent window .i.e. the MFC dialog.
>
> STDMETHODIMP CSum::Add()
> {
> AFX_MANAGE_STATE(AfxGetStaticModuleState())
>
> CAcceptInput dlg;
> dlg.DoModal();
> return S_OK;
> }
>
> I have verified that adding AFX_MANAGE_STATE() macro does NOT
> 1. Change the parent of the ATL dialog.
> 2. Change the window style & extended window style.
>

If the parent window to the dialog is not specified, MFC assumes it is
CWinApp::m_pMainWnd. Apparently that is being changed with
AFX_MANAGE_STATE. Why don't you try to specify the parent window to
CAcceptInput by:

CAcceptInput dlg(pParentWindow); // <-- will this work?



> Also I debugged the OnInitDialog() method of the ATL dialog and
> checked the position of the dialog, to my surprise in both the
> scenarios the position was the same. Its only after the WM_INITDIALOG
> and just before the display of the ATL dialog that the position gets
> changed in case of the AFX_MANAGE_STATE() macro.
>
> I am unable to understand why the ATL dialog is getting impacted with
> the AFX_MANAGE_STATE() macro though there is no relationship between
> them.
>
> Can anybody provide any help on this?
>

MFC accomplishes the centering by using a hook (WH_CBT, I believe).


-- David