CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2009

    yet another ASSERT(::IsWindow(...)) problem

    Hi folks,

    I'm quite new to VC++ and I'm having a problem this morning that is driving me nuts. I'll try to explain it short and clear:

    I have a dialog in my app. with just a CRichEditCtrl to make some testing stuff. The goal here is to get the CHARFORMAT from another rich edit view in the app. and set it to this control. I just need to see this test stuff working to get somewhere else, I'll spare you the details.
    So I have a class called CTestRtfDialog with a typical TestRtfDialog.h declaration

    class CTestRtfDialog : public CDialog
    // Construction
    CTestRtfDialog(CWnd* pParent = NULL); // standard constructor

    // Dialog Data
    enum { IDD = IDD_TEST_RTF };
    CRichEditCtrl m_TestRtf;

    // Overrides
    // ClassWizard generated virtual function overrides
    virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
    Plus some event handlers I don't want to bore you with

    Then in my CWinApp class' InitInstance method I have some typical things like DocTemplate, ParseCommandLine and at this point where evrything is supposed to be initialized (I've spent pretty enough time tracing to check it out) I have this lines to get the CHARFORMAT from that rich edit view I mentioned before:

    CMainFrame * pFrame = (CMainFrame *)(AfxGetApp()->m_pMainWnd);
    CExpertView * pView = (CExpertView *)pFrame->GetActiveView();
    CHARFORMAT cf = pView->GetCharFormatSelection();

    Everything is cool up to this point. Now the problems:
    Right after these lines I put those:

    CTestRtfDialog *pTestRtfDlg = (CTestRtfDialog *)pFrame->GetTestRtfDlg();

    This GetTestRtfDlg is a method in my CMainFrame that just returns a reference to the dialog with the CRichEditCtrl. SetDefaultFormat(CHARFORMAT &cf) is a method in CTestRtfDialog:

    void CTestRtfDialog::SetDefaultFormat(CHARFORMAT &cf)

    As you can figure out at this point I get my assertion fail as >>ASSERT(::IsWindow(m_hWnd));
    inside >>BOOL CRichEditCtrl::SetDefaultCharFormat(CHARFORMAT &cf) is not satisfied.

    So I said well, let's keep a copy of this CHARFORMAT in a member of my dialog at this point and set it later when the component compies the assertion:

    // 1. Redefine this method
    void CTestRtfDialog::SetDefaultFormat(CHARFORMAT &cf)
    m_DefaultCharFormat = cf;

    // 2. Give InitDialogEvent a try
    BOOL CTestRtfDialog::OnInitDialog()
    m_TestRtf.SetDefaultCharFormat(m_DefaultCharFormat); // (!!!)
    return TRUE;

    Hum... doesn't crash but the format in the edit control and in the view don't match... why?

    Some more tracing to check it out and I discover that OnInitDialog is triggered BEFORE the point where I call my SetDafaultFormat method, thus m_DefaultCharFormat has some random content.
    To be some specific the event is triggered somewhere inside the

    if (!ProcessShellCommand(cmdInfo))
    return FALSE;

    that is in InitInstance method and right before my code!

    What doesn't make any sense to me is that inside the event handler the assertion complies but LATER in my SetDefaultFormat method IT DOESN'T!

    Could someone explainme what's the problem here?

    Thanks in advance
    Last edited by fotw; February 2nd, 2009 at 09:47 AM. Reason: misspeling

  2. #2
    Join Date
    Jan 2002
    Houston, TX

    Re: yet another ASSERT(::IsWindow(...)) problem

    Perhaps you haven't called AfxInitRichEdit before trying to use that control?
    Be sure to rate those who help!
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

  3. #3
    Join Date
    Feb 2009

    Re: yet another ASSERT(::IsWindow(...)) problem

    yes, I did. otherwise as I've experienced the program doesn't run.

    thanx krmed

  4. #4
    Join Date
    Feb 2009

    Re: yet another ASSERT(::IsWindow(...)) problem


    No mistery at all. I was making a big mistake in the main App when picking a reference of my CTestRtfDialog instance. I don't want to bore you with the details but just for the record:

    The dialog is wrapped inside something called CCoolDialogBar (for docking and so on) and I was taking the instance of this thing instead of my dialog (and by the way casting it). So when I called SetDefaultCharFormat method of this fake instance, its components were indeed not initialized... unexisting to be true.
    Seen in the code:

    // The declaration:
    // [...] some declaration here
    CTestRtfDialog m_pDialog;
    CCoolDialogBar m_wndTestRtf;
    // [...] more declaration here

    // The object "wrapping" in a dockable window
    if (!m_wndTestRtf.Create(this, &m_pDialog, CString("Test RTF"), IDD_TEST_RTF))
    // [...] do whatever
    DockControlBar(&m_wndTestRtf,AFX_IDW_DOCKBAR_BOTTOM );
    // [...] blah, blah, blah

    So as I said, I was taking by mistake a reference to m_wndTestRtf instead of m_pDialog that is actually my dialog.

    Thanks to all the readers who took a minute to consider my problem

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width