Link to home
Start Free TrialLog in
Avatar of andla
andla

asked on

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_
Avatar of andla
andla

ASKER

test
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.
Avatar of andla

ASKER

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;
      }
};
Debug it and check all the return values.
Avatar of andla

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of chensu
chensu
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andla

ASKER

Thanks!

:-)