ATL show dialogbox

When i run a control in internet explorer i crashes.

It is created with atl appwizard without MFC.

A dialobox was created with ATL Object wizard.

A Full control was created with ATL Objectwizard.

I show you the code below. I would be very gratefull if you could tell me why it's not working.

Your sincerely
andla.




// MyDialog.h : Declaration of the CMyDialog

#ifndef __MYDIALOG_H_
#define __MYDIALOG_H_

#include "resource.h"       // main symbols
#include <atlhost.h>

/////////////////////////////////////////////////////////////////////////////
// CMyDialog
class CMyDialog :
      public CAxDialogImpl<CMyDialog>
{
public:
      CMyDialog()
      {
      }

      ~CMyDialog()
      {
      }

      enum { IDD = IDD_MYDIALOG };

BEGIN_MSG_MAP(CMyDialog)
      MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
      COMMAND_ID_HANDLER(IDOK, OnOK)
      COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
END_MSG_MAP()
// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);

      LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
      {
            return 1;  // Let the system set the focus
      }

      LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
      {
            EndDialog(wID);
            return 0;
      }

      LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
      {
            EndDialog(wID);
            return 0;
      }
};

#endif //__MYDIALOG_H_


----------------------------------------
// AndyFull.h : Declaration of the CAndyFull

#ifndef __ANDYFULL_H_
#define __ANDYFULL_H_

#include "resource.h"       // main symbols
#include <atlctl.h>
#include "mydialog.h"

/////////////////////////////////////////////////////////////////////////////
// CAndyFull
class ATL_NO_VTABLE CAndyFull :
      public CComObjectRootEx<CComSingleThreadModel>,
      public CStockPropImpl<CAndyFull, IAndyFull, &IID_IAndyFull, &LIBID_MYNEWDRAGDROP3Lib>,
      public CComControl<CAndyFull>,
      public IPersistStreamInitImpl<CAndyFull>,
      public IOleControlImpl<CAndyFull>,
      public IOleObjectImpl<CAndyFull>,
      public IOleInPlaceActiveObjectImpl<CAndyFull>,
      public IViewObjectExImpl<CAndyFull>,
      public IOleInPlaceObjectWindowlessImpl<CAndyFull>,
      public IConnectionPointContainerImpl<CAndyFull>,
      public IPersistStorageImpl<CAndyFull>,
      public ISpecifyPropertyPagesImpl<CAndyFull>,
      public IQuickActivateImpl<CAndyFull>,
      public IDataObjectImpl<CAndyFull>,
      public IProvideClassInfo2Impl<&CLSID_AndyFull, &DIID__IAndyFullEvents, &LIBID_MYNEWDRAGDROP3Lib>,
      public IPropertyNotifySinkCP<CAndyFull>,
      public CComCoClass<CAndyFull, &CLSID_AndyFull>
{
public:
      CAndyFull()
      {
            m_bWindowOnly = TRUE;
      }

DECLARE_REGISTRY_RESOURCEID(IDR_ANDYFULL)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CAndyFull)
      COM_INTERFACE_ENTRY(IAndyFull)
      COM_INTERFACE_ENTRY(IDispatch)
      COM_INTERFACE_ENTRY(IViewObjectEx)
      COM_INTERFACE_ENTRY(IViewObject2)
      COM_INTERFACE_ENTRY(IViewObject)
      COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
      COM_INTERFACE_ENTRY(IOleInPlaceObject)
      COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
      COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
      COM_INTERFACE_ENTRY(IOleControl)
      COM_INTERFACE_ENTRY(IOleObject)
      COM_INTERFACE_ENTRY(IPersistStreamInit)
      COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
      COM_INTERFACE_ENTRY(IConnectionPointContainer)
      COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
      COM_INTERFACE_ENTRY(IQuickActivate)
      COM_INTERFACE_ENTRY(IPersistStorage)
      COM_INTERFACE_ENTRY(IDataObject)
      COM_INTERFACE_ENTRY(IProvideClassInfo)
      COM_INTERFACE_ENTRY(IProvideClassInfo2)
END_COM_MAP()

BEGIN_PROP_MAP(CAndyFull)
      PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
      PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
      PROP_ENTRY("AutoSize", DISPID_AUTOSIZE, CLSID_NULL)
      PROP_ENTRY("HWND", DISPID_HWND, CLSID_NULL)
      // Example entries
      // PROP_ENTRY("Property Description", dispid, clsid)
      // PROP_PAGE(CLSID_StockColorPage)
END_PROP_MAP()

BEGIN_CONNECTION_POINT_MAP(CAndyFull)
      CONNECTION_POINT_ENTRY(IID_IPropertyNotifySink)
END_CONNECTION_POINT_MAP()

BEGIN_MSG_MAP(CAndyFull)
      CHAIN_MSG_MAP(CComControl<CAndyFull>)
      DEFAULT_REFLECTION_HANDLER()
      MESSAGE_HANDLER(WM_CREATE, OnCreate)
END_MSG_MAP()
// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);



// IViewObjectEx
      DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)

// IAndyFull
public:

      HRESULT OnDraw(ATL_DRAWINFO& di)
      {
            RECT& rc = *(RECT*)di.prcBounds;
            Rectangle(di.hdcDraw, rc.left, rc.top, rc.right, rc.bottom);

            SetTextAlign(di.hdcDraw, TA_CENTER|TA_BASELINE);
            LPCTSTR pszText = _T("ATL 3.0 : AndyFull");
            TextOut(di.hdcDraw,
                  (rc.left + rc.right) / 2,
                  (rc.top + rc.bottom) / 2,
                  pszText,
                  lstrlen(pszText));

            return S_OK;
      }
      LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
      {
            // TODO : Add Code for message handler. Call DefWindowProc if necessary.
            CMyDialog mydialog;

            RECT rect;
            rect.left=0;
            rect.right=50;
            rect.top=0;
            rect.bottom=50;
            mydialog.Create(m_hWnd,rect);
            
            return 0;
      }
};

#endif //__ANDYFULL_H_
LVL 1
andlaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
chensuConnect With a Mentor Commented:
If you are creating a modal dialog box, use CDialogImpl::DoModal and CDialogImpl::EndDialog. If you are creating a modeless dialog box, use CDialogImpl::Create and CDialogImpl::DestroyWindow.
0
 
andlaAuthor Commented:
test
0
 
chensuCommented:
The mydialog object is created on the stack. It is destroyed when it goes out of scope. So, mydialog will be destroyed right after mydialog.Create. Define it as a member variable of CAndyFull.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
andlaAuthor Commented:
Well my program doesen't crash any more but the dialogbox doesn't show up?

new code:

public:
      CMyDialog m_mydialog;
      LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
      {
            // TODO : Add Code for message handler. Call DefWindowProc if necessary.
            

            RECT rect;
            rect.left=0;
            rect.right=50;
            rect.top=0;
            rect.bottom=50;
            m_mydialog.Create(m_hWnd,rect);
            
            return 0;
      }
};
0
 
chensuCommented:
Debug it and check all the return values.
0
 
andlaAuthor Commented:
I now know what went wrong. It's wrong to use create in combination with EndDialog(wID), but if i use create i also have to show the window like the ordinary win32 API. And probebly i have to use a function like destroy window? I'm not sure.

Your sincerely
andla.
0
 
andlaAuthor Commented:
Thanks!

:-)
0
All Courses

From novice to tech pro — start learning today.