From: RAN on
On 8 dec, 23:39, RAN <nijenh...(a)wish.nl> wrote:
> On 8 dec, 23:13, "Drew" <d...(a)dam.com> wrote:
>
>
>
>
>
> > // XP TESTDlg.h : header file
> > //
>
> > #pragma once
> > #include "chessactivectrl1.h"
> > #include "PromotionDlg.h"
>
> > #define _UDM_TEST WM_USER + 100
>
> > // CXPTESTDlg dialog
> > class CXPTESTDlg : public CDialog
> > {
> > // Construction
> > public:
> > CXPTESTDlg(CWnd* pParent = NULL); // standard constructor
>
> > // Dialog Data
> > enum { IDD = IDD_XPTEST_DIALOG };
>
> > protected:
> > virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
>
> > // Implementation
> > protected:
> > HICON m_hIcon;
>
> > // Generated message map functions
> > virtual BOOL OnInitDialog();
> > afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
> > afx_msg void OnPaint();
> > afx_msg HCURSOR OnQueryDragIcon();
> > DECLARE_MESSAGE_MAP()
> > public:
> > CChessactivectrl1 o_ChessActive;
> > DECLARE_EVENTSINK_MAP()
> > void OnPromotion();
> > CPromotionDlg o_PromotionDlg;
> > afx_msg void OnBnClickedButton1();
> > LRESULT OnTest(WPARAM wParam, LPARAM lParam);
>
> > };
>
> > 4) if i click the break button after the debug assertion failed box it
> > jumps to file:
> > f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dlgcore.cpp      (line 492)
>
> > HWND CDialog::PreModal()
> > {
> > // cannot call DoModal on a dialog already constructed as modeless
> > ASSERT(m_hWnd == NULL);
>
> > // allow OLE servers to disable themselves
> > CWinApp* pApp = AfxGetApp();
> > if (pApp != NULL)
> > pApp->EnableModeless(FALSE);
>
> > // find parent HWND
> > HWND hWnd = CWnd::GetSafeOwner_(m_pParentWnd->GetSafeHwnd(),
> > &m_hWndTop);
>
> > // hook for creation of dialog
> > AfxHookWindowCreate(this);
>
> > // return window to use as parent for dialog
> > return hWnd;
>
> > }
>
> > the first ASSERT() failes.
>
> > 5) i also tried :
>
> > void CXPTESTDlg::OnPromotion()
> > {
> > // TODO: Add your message handler code here
>
> > CDialog o_Test;
>
> > o_Test.Create (IDD_PROMOTION);
>
> > // This call causes a debug assertion failed
> > o_Test.DoModal();
>
> > }
>
> > Why isn't this:
>
> > void CXPTESTDlg::OnPromotion()
> > {
> >    o_PromotionDlg.DoModal();
>
> > }
>
> > ?
>
> > Drew
>
> HWND CDialog::PreModal()
> {
> // cannot call DoModal on a dialog already constructed as modeless
> ASSERT(m_hWnd == NULL);
>
> I dont understand the comment. which dialog ? modeless ?- Tekst uit oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

The first thing i tried using a local was wrong because i used Create
(), but below also does noet work because i can not move or close the
dialog shown after DoModal()

void CXPTESTDlg::OnPromotion()
{
// TODO: Add your message handler code here

// This call causes a debug assertion failed
//CPromotionDlg o_Test(this);
//o_Test.DoModal ();
//PostMessage(_UDM_TEST);

CPromotionDlg o_Test;
o_Test.DoModal ();

}
From: Scott McPhillips [MVP] on
"RAN" <nijenhuis(a)wish.nl> wrote in message news:8666f3cf-6ac7-4858-b20e-> //
cannot call DoModal on a dialog already constructed as modeless
> ASSERT(m_hWnd == NULL);
>
> I dont understand the comment. which dialog ? modeless ?- Tekst uit
> oorspronkelijk bericht niet weergeven -
>
> - Tekst uit oorspronkelijk bericht weergeven -

The assert means that the dialog you are creating has already been created
elsewhere. It has an m_hWnd. This can be caused by calling the dialog
Create function.

>
>// This call causes a debug assertion failed
>//CPromotionDlg o_Test(this);
>//o_Test.DoModal ();
>

This is the correct way to create and display a modal dialog. If it causes
a problem then you have more than one problem. But keep this code. As Joe
tried to tell you, we can't help much without knowing the details of the
assertion. Telling us that an assertion failed conveys very little
information, while the details of the assertion usually tell us a lot.

--
Scott McPhillips [VC++ MVP]

From: RAN on
On 9 dec, 01:55, "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp>
wrote:
> "RAN" <nijenh...(a)wish.nl> wrote in message news:8666f3cf-6ac7-4858-b20e-> //
>
> cannot call DoModal on a dialog already constructed as modeless
>
> > ASSERT(m_hWnd == NULL);
>
> > I dont understand the comment. which dialog ? modeless ?- Tekst uit
> > oorspronkelijk bericht niet weergeven -
>
> > - Tekst uit oorspronkelijk bericht weergeven -
>
> The assert means that the dialog you are creating has already been created
> elsewhere.  It has an m_hWnd.  This can be caused by calling the dialog
> Create function.
>
>
>
> >// This call causes a debug assertion failed
> >//CPromotionDlg o_Test(this);
> >//o_Test.DoModal ();
>
> This is the correct way to create and display a modal dialog.  If it causes
> a problem then you have more than one problem.  But keep this code.  As Joe
> tried to tell you, we can't help much without knowing the details of the
> assertion.  Telling us that an assertion failed conveys very little
> information, while the details of the assertion usually tell us a lot.
>
> --
> Scott McPhillips [VC++ MVP]

Hi,

Thanks so far.
I created a new ActiveX control project with only one event called
OnTryMe() and a methode called Test() that calls this event.
I created a new CDialog project and inserted the ActiveX.
I call this event like so:

void CTestEventDlg::OnBnClickedCallEvent()
{
// TODO: Add your control notification handler code here
m_TestCtrl.Test ();
}
BEGIN_EVENTSINK_MAP(CTestEventDlg, CDialog)
ON_EVENT(CTestEventDlg, IDC_TESTOCXCTRL1, 1, CTestEventDlg::OnTryMe,
VTS_NONE)
END_EVENTSINK_MAP()

void CTestEventDlg::OnTryMe()
{
// TODO: Add your message handler code here
CPromotionDlg m_PromDlg;
m_PromDlg.DoModal();
}

The modal dialog is now displayed and works perfectly.
There must be something wrong with my Chess ActiveX control because
its not working there.
I must look in to it more to figure out what i am doing wrong.
I will find out, but thanks for now and for the advise on programming.
From: Joseph M. Newcomer on
See below...
On Tue, 8 Dec 2009 13:11:18 -0800 (PST), RAN <nijenhuis(a)wish.nl> wrote:

>On 8 dec, 21:32, Joseph M. Newcomer <newco...(a)flounder.com> wrote:
>> See below...
>>
>> On Tue, 8 Dec 2009 09:36:13 -0800 (PST), RAN <nijenh...(a)wish.nl> wrote:
>> >Hi,
>>
>> >I use VS2008Pro.
>> >I have created an ActiveX control dat shows a chessboard etc,
>> >I have created an ActiveX event called OnPromotion();
>> >I created a standard CDialog project and inserted the chess activex
>> >control.
>> >I added the activex event OnPromotion() and want to show a second
>> >CDailog using DoModal() inside of this OnPromotion() event.
>> >The second (promotion dialog) is shown, but when i click it i get a
>> >debug assertion failed message. Can i not call a DoModal() inside an
>> >activex event in my dialog?
>>
>> ****
>> I am absolutely certain you do not get "a" debug assertion message. �I have a great
>> confidence that you get a VERY SPECIFIC assertion failure, that specifies a file, and
>> line, and you can supply a backtrace from that location to your code. �Be sure to tell us
>> what version of VS you are using so we know how to correlate the file/line with actual
>> source code.
>> ****
>>
>>
>>
>>
>>
>> >BEGIN_EVENTSINK_MAP(CXPTESTDlg, CDialog)
>> > � �ON_EVENT(CXPTESTDlg, IDC_CHESSACTIVECTRL1, 1,
>> >CXPTESTDlg::OnPromotion, VTS_NONE)
>> >END_EVENTSINK_MAP()
>>
>> >void CXPTESTDlg::OnPromotion()
>> >{
>> > � �// TODO: Add your message handler code here
>>
>> > � �// This call causes a debug assertion failed
>> > � �//o_PromotionDlg.DoModal();
>>
>> > � �::PostMessage (this->m_hWnd ,_UDM_TEST,0,0);
>>
>> ****
>> Why such a clumsy method? �Would't it be easier to write
>> � � � � PostMessage(_UDM_TEST);
>> ?
>> ****>}
>>
>> >void CXPTESTDlg::OnBnClickedButton1()
>>
>> ****
>> One of the VERY FIRST things you should do when you add a control is change the ID from
>> the useless IDC_BUTTON1 to something that makes sense.
>> ****>{
>> > � �// TODO: Add your control notification handler code here
>> > � �o_PromotionDlg.DoModal ();
>> >}
>>
>> >LRESULT CXPTESTDlg::OnTest(WPARAM wParam, LPARAM lParam)
>> >{
>> > � �o_PromotionDlg.DoModal ();
>> > � �return 0;
>> >}
>>
>> ****
>> There isn't enough information here. �Lacking any description of the assertion failure,
>> there's nothing to try but psychic vibrations, and they don't work too well.
>> ****
>>
>> >If i use PostMessage instead to call the DoModal() it works fine.
>> >I dont know why this happens.
>> >Could someone help please?
>>
>> ****
>> First, give us complete information.
>>
>> Second, where is o_PromotionDlg declared? �It should be a local variable in the function,
>> since there is no reason for it to exist outside the scope of the function that does the
>> DoModal. �If you are inventing new notational conventions, such as a prefix "o_", it is
>> important that you explain what it means.
>> � � � � � � � � � � � � � � � � joe
>> ****
>>
>> >Thanks.
>>
>> Joseph M. Newcomer [MVP]
>> email: newco...(a)flounder.com
>> Web:http://www.flounder.com
>> MVP Tips:http://www.flounder.com/mvp_tips.htm- Tekst uit oorspronkelijk bericht niet weergeven -
>>
>> - Tekst uit oorspronkelijk bericht weergeven -
>
>1) I use Microsoft Visual Studio 2008, version 9.0.21022.8 RTM
>2) i use the notational convention prefix _o for anything that is a
>class or object.
>3) the declaration of o_PromotionDlg is in class CXPTESTDlg:
>
>// XP TESTDlg.h : header file
>//
>
>#pragma once
>#include "chessactivectrl1.h"
>#include "PromotionDlg.h"
>
>#define _UDM_TEST WM_USER + 100
****
First, when defining a value which involves an expression, you should use parentheses
#define _UDM_TEST (WM_USER + 100)

It is a Really Bad Idea to ever use a WM_USER-based message for an existing control class;
you have no idea if it is already being used. You should use WM_APP-based messages for
message which are sent to an existing class, or better still, use a Registered Window
Message. See my essay on message management on my MVP Tips site
****
>
>// CXPTESTDlg dialog
>class CXPTESTDlg : public CDialog
>{
>// Construction
>public:
> CXPTESTDlg(CWnd* pParent = NULL); // standard constructor
>
>// Dialog Data
> enum { IDD = IDD_XPTEST_DIALOG };
>
> protected:
> virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
>
>
>// Implementation
>protected:
> HICON m_hIcon;
>
> // Generated message map functions
> virtual BOOL OnInitDialog();
> afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
> afx_msg void OnPaint();
> afx_msg HCURSOR OnQueryDragIcon();
> DECLARE_MESSAGE_MAP()
>public:
> CChessactivectrl1 o_ChessActive;
> DECLARE_EVENTSINK_MAP()
> void OnPromotion();
> CPromotionDlg o_PromotionDlg;
****
Standard prefix for a class member is "m_". There is no reason to have declared this as a
class member; since the dialog is modal, it should be declared as a local variable in the
function that invokes the dialog.
****
> afx_msg void OnBnClickedButton1();
> LRESULT OnTest(WPARAM wParam, LPARAM lParam);
>};
>
>
>4) if i click the break button after the debug assertion failed box it
>jumps to file:
>f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\dlgcore.cpp (line 492)
>
>HWND CDialog::PreModal()
>{
> // cannot call DoModal on a dialog already constructed as modeless
> ASSERT(m_hWnd == NULL);
>
> // allow OLE servers to disable themselves
> CWinApp* pApp = AfxGetApp();
> if (pApp != NULL)
> pApp->EnableModeless(FALSE);
>
> // find parent HWND
> HWND hWnd = CWnd::GetSafeOwner_(m_pParentWnd->GetSafeHwnd(),
>&m_hWndTop);
>
> // hook for creation of dialog
> AfxHookWindowCreate(this);
>
> // return window to use as parent for dialog
> return hWnd;
>}
>
>the first ASSERT() failes.
****
Probably because the variable declared as a class member has something left over in it
that was not re-initialized. Since I find the whole notion of making it a class member
suspicious, the first thing you should do is make it a local variable in the function that
calls the DoModal. Until you can demonstrate a failure when it is a local variable, we
can assume that it was caused by making it a class member.

Note also that if you EVER did a call of the form o_Test.Create(IDD_PROMOTION) then you
have created a modeless dialog, and therefore, as the code indicates, DoModal would be
inappropriate.
****
>
>5) i also tried :
>
>void CXPTESTDlg::OnPromotion()
>{
> // TODO: Add your message handler code here
>
> CDialog o_Test;
>
> o_Test.Create (IDD_PROMOTION);
****
That doesn't make any sense at all. This creates an instance of a modeless dialog, and
should have been done as
CPromotionDlg o_Test;
(which again is an inconsistent use of a previously unknown prefix) and NOT "CDialog", but
of course, as a modeless dialog, it needs to exist beyond the scope of the function, so
declaring it as a local variable makes no sense either; so it would have to be done as
CPromotionDlg * o_Test = new CPromotionDlg;
Now, THIS could be done as a class member, e.g.,
CPromotionDlg * m_Test;
and if you want to create a modeless dialog, you would, at the point of creation, do
m_Test = new CPromotionDlg;
m_Test->Create(IDD_PROMOTION);
but then it would completely inappropriate to call DoModal, because, as indicated by the
PreModal assert, you ALREADY have a modeless dialog.

Note that for modeless dialogs, you need to add a PostNcDestroy handler:

CPromotionDlg::PostNcDestroy()
{
CDialog::PostNcDestroy();
delete this;
}
****
>
> // This call causes a debug assertion failed
> o_Test.DoModal();
****
It had better cause that assertion, because in that case your code is incorrect
****
>}
>
>I get the same error.
>
>I hope i have send you some information you can use.
>Thanks.
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Joseph M. Newcomer on
See below...
On Wed, 9 Dec 2009 04:11:03 -0800 (PST), RAN <nijenhuis(a)wish.nl> wrote:

>On 9 dec, 01:55, "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp>
>wrote:
>> "RAN" <nijenh...(a)wish.nl> wrote in message news:8666f3cf-6ac7-4858-b20e-> //
>>
>> cannot call DoModal on a dialog already constructed as modeless
>>
>> > ASSERT(m_hWnd == NULL);
>>
>> > I dont understand the comment. which dialog ? modeless ?- Tekst uit
>> > oorspronkelijk bericht niet weergeven -
>>
>> > - Tekst uit oorspronkelijk bericht weergeven -
>>
>> The assert means that the dialog you are creating has already been created
>> elsewhere. �It has an m_hWnd. �This can be caused by calling the dialog
>> Create function.
>>
>>
>>
>> >// This call causes a debug assertion failed
>> >//CPromotionDlg o_Test(this);
>> >//o_Test.DoModal ();
>>
>> This is the correct way to create and display a modal dialog. �If it causes
>> a problem then you have more than one problem. �But keep this code. �As Joe
>> tried to tell you, we can't help much without knowing the details of the
>> assertion. �Telling us that an assertion failed conveys very little
>> information, while the details of the assertion usually tell us a lot.
>>
>> --
>> Scott McPhillips [VC++ MVP]
>
>Hi,
>
>Thanks so far.
>I created a new ActiveX control project with only one event called
>OnTryMe() and a methode called Test() that calls this event.
>I created a new CDialog project and inserted the ActiveX.
>I call this event like so:
>
>void CTestEventDlg::OnBnClickedCallEvent()
>{
> // TODO: Add your control notification handler code here
> m_TestCtrl.Test ();
>}
>BEGIN_EVENTSINK_MAP(CTestEventDlg, CDialog)
> ON_EVENT(CTestEventDlg, IDC_TESTOCXCTRL1, 1, CTestEventDlg::OnTryMe,
>VTS_NONE)
>END_EVENTSINK_MAP()
>
>void CTestEventDlg::OnTryMe()
>{
> // TODO: Add your message handler code here
> CPromotionDlg m_PromDlg;
****
Even as a test program this shows you should not be using any kind of prefix notation; m_
is widely accepted as meaning "class member" and it is totally inappropriate to use it as
a prefix on a local variable.

The easiest way to avoid using prefixes incorrectly is not to use them at all. If you do
use them, you must use them correctly. This means you should not invent your own notation
that makes your usage inconsistent with widely-accepted practice, and if you use standard
notation, you must use it in the established fashion.
****
> m_PromDlg.DoModal();
>}
>
>The modal dialog is now displayed and works perfectly.
>There must be something wrong with my Chess ActiveX control because
>its not working there.
>I must look in to it more to figure out what i am doing wrong.
>I will find out, but thanks for now and for the advise on programming.
****
I think there is more going on than you showed us. Make sure you have no Create calls
anywhere on that class.
joe
****
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm