Discussion:
Modeless dialog box with CAxDialogImpl
(too old to reply)
Alain Dekker
2004-04-30 15:44:11 UTC
Permalink
Hi,

I've write a simple program using CDialog classes that implemented modeless
dialogs nicely. I also worked out how to find the windows and destroy them,
etc. However, I just cannot get this working with the CAxDialogImpl class I
have.

Can anyone let me know how this works, please?

Whenever I try and create the message box, the compiler complains that the
number of parameters are wrong.

Thanks,
Alain
Igor Tandetnik
2004-04-30 15:48:00 UTC
Permalink
Post by Alain Dekker
I've write a simple program using CDialog classes that implemented
modeless dialogs nicely. I also worked out how to find the windows
and destroy them, etc. However, I just cannot get this working with
the CAxDialogImpl class I have.
What exactly do you have problems with? What could you do with CDialog
that you cannot do with CAxDialogImpl

By CDialog, do you really mean CDialog class from MFC, or is it a typo
and you are talking about CDialogImpl from ATL?
Post by Alain Dekker
Can anyone let me know how this works, please?
How what works?
Post by Alain Dekker
Whenever I try and create the message box, the compiler complains
that the number of parameters are wrong.
Show the code and the compiler error.
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
Alain Dekker
2004-04-30 15:58:00 UTC
Permalink
OK.

1) I implement a dialog, IDD_MY_DIALOG.
2) I create a new class based on this dialog, lets say CTestDlg : public
CDialog
3) I add the header file for this class to my CAxDialogImpl calling class
(it will try to create the modeless dialog)
4) I use this code, which works fine if the calling class is CDialog):

CTestDlg* pDlg = new CTestDlg();
if (NULL != pDlg)
{
BOOL bRet = pDlg->Create(IDD_DIALOG1, this);
if (bRet)
{
pDlg->ShowWindow(SW_SHOW);
}
}

But get this comiler error:

: error C2664: 'int __thiscall CDialog::Create(const char *,class CWnd *)' :
cannot convert parameter 1 from 'const int' to 'const char *'
Conversion from integral type to pointer type requires
reinterpret_cast, C-style cast or function-style cast

I've tried all sorts of things, like getting my test message dialog to be
dereived from other base classes, etc. Nothing seems to work.

Can you give me an example of a modeless dialog from an CAxDialogImpl class?

Thanks,
Alain
Post by Igor Tandetnik
Post by Alain Dekker
I've write a simple program using CDialog classes that implemented
modeless dialogs nicely. I also worked out how to find the windows
and destroy them, etc. However, I just cannot get this working with
the CAxDialogImpl class I have.
What exactly do you have problems with? What could you do with CDialog
that you cannot do with CAxDialogImpl
By CDialog, do you really mean CDialog class from MFC, or is it a typo
and you are talking about CDialogImpl from ATL?
Post by Alain Dekker
Can anyone let me know how this works, please?
How what works?
Post by Alain Dekker
Whenever I try and create the message box, the compiler complains
that the number of parameters are wrong.
Show the code and the compiler error.
--
With best wishes,
Igor Tandetnik
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
Igor Tandetnik
2004-04-30 16:10:34 UTC
Permalink
Post by Alain Dekker
1) I implement a dialog, IDD_MY_DIALOG.
public CDialog
3) I add the header file for this class to my CAxDialogImpl calling
class (it will try to create the modeless dialog)
So you are saying you have a mixed MFC/ATL application, right? Any
reason for this? Or do you mean CDialogImpl and not CDialog after all?
Post by Alain Dekker
CTestDlg* pDlg = new CTestDlg();
if (NULL != pDlg)
{
BOOL bRet = pDlg->Create(IDD_DIALOG1, this);
if (bRet)
{
pDlg->ShowWindow(SW_SHOW);
}
}
Looks like MFC classes after all. You see, the second parameter of
CDialog::Create is CWnd* - a pointer to another MFC class. Of course
CAxDialogImpl, being an ATL class, is not derived from CWnd and has no
clue about CWnd. When the parent is an ATL window class, try this
instead:

pDlg->Create(IDD_DIALOG1, CWnd::FromHandle(m_hWnd));

Personally, I'd avoid mixing MFC and ATL like a plague, especially in UI
(there may be some merit in doing UI in MFC and non-UI COM work in ATL).
Post by Alain Dekker
Can you give me an example of a modeless dialog from an CAxDialogImpl class?
Why don't you use CDialogImpl - an ATL class for doing dialogs? Or drop
CAxDialogImpl and use MFC's CDialog thoughout - it can happily host
ActiveX controls.
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
Alain Dekker
2004-04-30 17:16:24 UTC
Permalink
Hi Igor,

Firstly, thank you very much. Your "CWnd::FromHandle" bit seems to work
fine.

Secondly, we are mixing MFC and ATL and I'm not sure of the historical
reasons for this, I must be honest with you. I'll investigate the
possiblilty of separating the two.

Thanks again,
Alain
Post by Igor Tandetnik
Post by Alain Dekker
1) I implement a dialog, IDD_MY_DIALOG.
public CDialog
3) I add the header file for this class to my CAxDialogImpl calling
class (it will try to create the modeless dialog)
So you are saying you have a mixed MFC/ATL application, right? Any
reason for this? Or do you mean CDialogImpl and not CDialog after all?
Post by Alain Dekker
CTestDlg* pDlg = new CTestDlg();
if (NULL != pDlg)
{
BOOL bRet = pDlg->Create(IDD_DIALOG1, this);
if (bRet)
{
pDlg->ShowWindow(SW_SHOW);
}
}
Looks like MFC classes after all. You see, the second parameter of
CDialog::Create is CWnd* - a pointer to another MFC class. Of course
CAxDialogImpl, being an ATL class, is not derived from CWnd and has no
clue about CWnd. When the parent is an ATL window class, try this
pDlg->Create(IDD_DIALOG1, CWnd::FromHandle(m_hWnd));
Personally, I'd avoid mixing MFC and ATL like a plague, especially in UI
(there may be some merit in doing UI in MFC and non-UI COM work in ATL).
Post by Alain Dekker
Can you give me an example of a modeless dialog from an CAxDialogImpl class?
Why don't you use CDialogImpl - an ATL class for doing dialogs? Or drop
CAxDialogImpl and use MFC's CDialog thoughout - it can happily host
ActiveX controls.
--
With best wishes,
Igor Tandetnik
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
Alain Dekker
2004-04-30 17:46:07 UTC
Permalink
Hi Igor,

Further to my previous emails, I'm having another problem that I'm curious
to solve. I can create the window with:

pDlg = new CTestDlg();
if (NULL != pDlg)
{
BOOL bRet = pDlg->Create(IDD_DIALOG1, CWnd::FromHandle(m_hWnd));
if (bRet)
{
pDlg->ShowWindow(SW_SHOW);
}
}

// do something else

HWND hWnd = FindWindow(NULL, _T("Test Message"));
if (NULL != hWnd)
{
BOOL bDestroyed = ::DestroyWindow(hWnd); // Returns TRUE
}

// Do something more - now display messag again...

pDlg = new CTestDlg();
if (NULL != pDlg)
{
BOOL bRet = pDlg->Create(IDD_DIALOG1, CWnd::FromHandle(m_hWnd));
if (bRet)
{
pDlg->ShowWindow(SW_SHOW);
}
// No! bRet is now FALSE
}

I can never display the message for a second time.

Any idea what I might bw doing wrong?
Thanks,
Alain
Post by Igor Tandetnik
Post by Alain Dekker
1) I implement a dialog, IDD_MY_DIALOG.
public CDialog
3) I add the header file for this class to my CAxDialogImpl calling
class (it will try to create the modeless dialog)
So you are saying you have a mixed MFC/ATL application, right? Any
reason for this? Or do you mean CDialogImpl and not CDialog after all?
Post by Alain Dekker
CTestDlg* pDlg = new CTestDlg();
if (NULL != pDlg)
{
BOOL bRet = pDlg->Create(IDD_DIALOG1, this);
if (bRet)
{
pDlg->ShowWindow(SW_SHOW);
}
}
Looks like MFC classes after all. You see, the second parameter of
CDialog::Create is CWnd* - a pointer to another MFC class. Of course
CAxDialogImpl, being an ATL class, is not derived from CWnd and has no
clue about CWnd. When the parent is an ATL window class, try this
pDlg->Create(IDD_DIALOG1, CWnd::FromHandle(m_hWnd));
Personally, I'd avoid mixing MFC and ATL like a plague, especially in UI
(there may be some merit in doing UI in MFC and non-UI COM work in ATL).
Post by Alain Dekker
Can you give me an example of a modeless dialog from an CAxDialogImpl class?
Why don't you use CDialogImpl - an ATL class for doing dialogs? Or drop
CAxDialogImpl and use MFC's CDialog thoughout - it can happily host
ActiveX controls.
--
With best wishes,
Igor Tandetnik
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
Igor Tandetnik
2004-04-30 18:04:22 UTC
Permalink
Post by Alain Dekker
// Do something more - now display messag again...
pDlg = new CTestDlg();
if (NULL != pDlg)
{
BOOL bRet = pDlg->Create(IDD_DIALOG1, CWnd::FromHandle(m_hWnd));
if (bRet)
{
pDlg->ShowWindow(SW_SHOW);
}
// No! bRet is now FALSE
}
I can never display the message for a second time.
What does GetLastError return right after the call fails?
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
Alexander Nickolov
2004-05-01 03:15:25 UTC
Permalink
I suspect your memory leak might be the reason for this.
MFC keeps track of its windows, not sure but your leaked
dialog class may interfere here... (hint: DestroyWindow
does not delete C++ class instances) You'd probably want
to ask this in an MFC-oriented group.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: ***@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
Post by Alain Dekker
Hi Igor,
Further to my previous emails, I'm having another problem that I'm curious
pDlg = new CTestDlg();
if (NULL != pDlg)
{
BOOL bRet = pDlg->Create(IDD_DIALOG1, CWnd::FromHandle(m_hWnd));
if (bRet)
{
pDlg->ShowWindow(SW_SHOW);
}
}
// do something else
HWND hWnd = FindWindow(NULL, _T("Test Message"));
if (NULL != hWnd)
{
BOOL bDestroyed = ::DestroyWindow(hWnd); // Returns TRUE
}
// Do something more - now display messag again...
pDlg = new CTestDlg();
if (NULL != pDlg)
{
BOOL bRet = pDlg->Create(IDD_DIALOG1, CWnd::FromHandle(m_hWnd));
if (bRet)
{
pDlg->ShowWindow(SW_SHOW);
}
// No! bRet is now FALSE
}
I can never display the message for a second time.
Any idea what I might bw doing wrong?
Thanks,
Alain
Post by Igor Tandetnik
Post by Alain Dekker
1) I implement a dialog, IDD_MY_DIALOG.
public CDialog
3) I add the header file for this class to my CAxDialogImpl calling
class (it will try to create the modeless dialog)
So you are saying you have a mixed MFC/ATL application, right? Any
reason for this? Or do you mean CDialogImpl and not CDialog after all?
Post by Alain Dekker
CTestDlg* pDlg = new CTestDlg();
if (NULL != pDlg)
{
BOOL bRet = pDlg->Create(IDD_DIALOG1, this);
if (bRet)
{
pDlg->ShowWindow(SW_SHOW);
}
}
Looks like MFC classes after all. You see, the second parameter of
CDialog::Create is CWnd* - a pointer to another MFC class. Of course
CAxDialogImpl, being an ATL class, is not derived from CWnd and has no
clue about CWnd. When the parent is an ATL window class, try this
pDlg->Create(IDD_DIALOG1, CWnd::FromHandle(m_hWnd));
Personally, I'd avoid mixing MFC and ATL like a plague, especially in UI
(there may be some merit in doing UI in MFC and non-UI COM work in ATL).
Post by Alain Dekker
Can you give me an example of a modeless dialog from an CAxDialogImpl class?
Why don't you use CDialogImpl - an ATL class for doing dialogs? Or drop
CAxDialogImpl and use MFC's CDialog thoughout - it can happily host
ActiveX controls.
--
With best wishes,
Igor Tandetnik
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
Loading...