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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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
chensuCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andlaAuthor Commented:
Thanks!

:-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.