Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

OnDraw

94 views
Skip to first unread message

Brian Burgess

unread,
Dec 31, 2002, 3:02:17 AM12/31/02
to
Hi all,

Is there any great secret to getting 'OnDraw' to be called in a
Composite Control?

thanks in advance...

-BB

Igor Tandetnik

unread,
Dec 31, 2002, 10:03:53 AM12/31/02
to
You need to override the method with the correct signature, and you need
to make sure CHAIN_MSG_MAP(baseClass) entry is somewhere at the bottom
of your message map. IIRC ATL Wizard puts the correct entry there.
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken

"Brian Burgess" <bburg...@hotmail.com> wrote in message
news:amj21vs53egi874b0...@4ax.com...

Brian Burgess

unread,
Jan 1, 2003, 3:15:13 AM1/1/03
to
Yes the CHAIN_MSG_MAP is in there .. but it was at the top of the
map..
My OnDraw looks like this:
HRESULT OnDraw(ATL_DRAWINFO& di);

Any other ideas?

thanks

-BB

Igor Tandetnik

unread,
Jan 2, 2003, 9:21:51 AM1/2/03
to
Move CHAIN_MSG_MAP to the bottom, otherwise you may have problems with
other message entries that come after it. Essentially, CHAIN_MSG_MAP
says that you are done with all the messages you are interested in and
want the rest to be handled by your base class. This is probably not the
cause of your problem though.

Do you, by any chance, have an entry for WM_PAINT in the message map?
OnDraw is called (among other places) from WM_PAINT handler in
CComControl class. If you intercept the message before it gets to
CHAIN_MSG_MAP, you won't get OnDraw.

Show the complete declaration of your class.


--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken

"Brian Burgess" <bburg...@hotmail.com> wrote in message

news:mo851v0thusflf1kf...@4ax.com...


> Yes the CHAIN_MSG_MAP is in there .. but it was at the top of the
> map..
> My OnDraw looks like this:
> HRESULT OnDraw(ATL_DRAWINFO& di);
>

Brian Burgess

unread,
Jan 2, 2003, 9:56:55 PM1/2/03
to

Ya I had moved the CHAIN_MSG_MAP, but still nothing...
I dont have a WM_PAINT handler, but I do have WM_CREATE and
WM_INITDIALOG handlers before the CHAIN_MSG_MAP...

at any rate, here is the complete class declaration:
******************************************************************
// FormDlg.h : Declaration of the CFormDlg

#ifndef __FORMDLG_H_
#define __FORMDLG_H_

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


/////////////////////////////////////////////////////////////////////////////
// CFormDlg
class ATL_NO_VTABLE CFormDlg :
public CComObjectRootEx<CComSingleThreadModel>,
public CStockPropImpl<CFormDlg, IFormDlg, &IID_IFormDlg,
&LIBID_FORMFILLERCTRLLib>,
public CComCompositeControl<CFormDlg>,
public IPersistStreamInitImpl<CFormDlg>,
public IOleControlImpl<CFormDlg>,
public IOleObjectImpl<CFormDlg>,
public IOleInPlaceActiveObjectImpl<CFormDlg>,
public IViewObjectExImpl<CFormDlg>,
public IOleInPlaceObjectWindowlessImpl<CFormDlg>,
public IConnectionPointContainerImpl<CFormDlg>,
public IPersistStorageImpl<CFormDlg>,
public ISpecifyPropertyPagesImpl<CFormDlg>,
public IQuickActivateImpl<CFormDlg>,
public IDataObjectImpl<CFormDlg>,
public IProvideClassInfo2Impl<&CLSID_FormDlg,
&DIID__IFormDlgEvents, &LIBID_FORMFILLERCTRLLib>,
public IPropertyNotifySinkCP<CFormDlg>,
public CComCoClass<CFormDlg, &CLSID_FormDlg>
{
public:
CFormDlg();
~CFormDlg();

DECLARE_REGISTRY_RESOURCEID(IDR_FORMDLG)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CFormDlg)
COM_INTERFACE_ENTRY(IFormDlg)
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(CFormDlg)
PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
PROP_ENTRY("Appearance", DISPID_APPEARANCE, CLSID_NULL)
PROP_ENTRY("AutoSize", DISPID_AUTOSIZE, CLSID_NULL)
PROP_ENTRY("BackColor", DISPID_BACKCOLOR,
CLSID_StockColorPage)
PROP_ENTRY("BackStyle", DISPID_BACKSTYLE, CLSID_NULL)
PROP_ENTRY("BorderColor", DISPID_BORDERCOLOR,
CLSID_StockColorPage)
PROP_ENTRY("BorderStyle", DISPID_BORDERSTYLE, CLSID_NULL)
PROP_ENTRY("BorderVisible", DISPID_BORDERVISIBLE, CLSID_NULL)
PROP_ENTRY("BorderWidth", DISPID_BORDERWIDTH, CLSID_NULL)
PROP_ENTRY("Caption", DISPID_CAPTION, CLSID_NULL)
PROP_ENTRY("Enabled", DISPID_ENABLED, CLSID_NULL)
PROP_ENTRY("FillColor", DISPID_FILLCOLOR,
CLSID_StockColorPage)
PROP_ENTRY("FillStyle", DISPID_FILLSTYLE, CLSID_NULL)
PROP_ENTRY("ForeColor", DISPID_FORECOLOR,
CLSID_StockColorPage)
PROP_ENTRY("Picture", DISPID_PICTURE, CLSID_StockPicturePage)
PROP_ENTRY("TabStop", DISPID_TABSTOP, CLSID_NULL)
PROP_ENTRY("Text", DISPID_TEXT, CLSID_NULL)
PROP_ENTRY("Valid", DISPID_VALID, CLSID_NULL)
// Example entries
// PROP_ENTRY("Property Description", dispid, clsid)
// PROP_PAGE(CLSID_StockColorPage)
END_PROP_MAP()

BEGIN_CONNECTION_POINT_MAP(CFormDlg)
CONNECTION_POINT_ENTRY(IID_IPropertyNotifySink)
END_CONNECTION_POINT_MAP()

BEGIN_MSG_MAP(CFormDlg)
MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUP)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
CHAIN_MSG_MAP(CComCompositeControl<CFormDlg>)
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);

BEGIN_SINK_MAP(CFormDlg)
//Make sure the Event Handlers have __stdcall calling
convention
///SINK_ENTRY(IDC_FormImage, DISPID_MOUSEDOWN,
OnMouseDownImageCtrl)
///SINK_ENTRY(IDC_FormImage, DISPID_MOUSEUP,
OnMouseUpFormImageCtrl)
END_SINK_MAP()

STDMETHOD(OnAmbientPropertyChange)(DISPID dispid)
{
if (dispid == DISPID_AMBIENT_BACKCOLOR)
{
SetBackgroundColorFromAmbient();
FireViewChange();
}
return
IOleControlImpl<CFormDlg>::OnAmbientPropertyChange(dispid);
}

// IViewObjectEx
DECLARE_VIEW_STATUS(1)

// IFormDlg
public:
HRESULT OnDraw(ATL_DRAWINFO &di);
LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam,
BOOL& bHandled);
LRESULT CFormDlg::OnLButtonDown(UINT uMsg, WPARAM wParam,
LPARAM lParam, BOOL& bHandled);
LRESULT CFormDlg::OnLButtonUP(UINT uMsg, WPARAM wParam, LPARAM
lParam, BOOL& bHandled);

short m_nAppearance;
OLE_COLOR m_clrBackColor;
LONG m_nBackStyle;
OLE_COLOR m_clrBorderColor;
LONG m_nBorderStyle;
BOOL m_bBorderVisible;
LONG m_nBorderWidth;
CComBSTR m_bstrCaption;
BOOL m_bEnabled;
HWND m_hHWND;
OLE_COLOR m_clrFillColor;
LONG m_nFillStyle;
CComPtr<IFontDisp> m_pFont;
OLE_COLOR m_clrForeColor;
CComPtr<IPictureDisp> m_pPicture;
BOOL m_bTabStop;
CComBSTR m_bstrText;
BOOL m_bValid;

enum { IDD = IDD_FORMDLG };

private:
LRESULT OnCreate(UINT uMsg, WPARAM wParam,
LPARAM lParam, BOOL& bHandled);
};

#endif //__FORMDLG_H_
******************************************************************

Igor Tandetnik

unread,
Jan 3, 2003, 10:14:36 AM1/3/03
to
Now I see. CComCompositeControl does not chain messages to its base
class, CComControl. It is CComControl that has WM_PAINT entry and calls
OnDraw from its handler. The workaround is as follows:

typedef CComControl<CMyCtl, CAxDialogImpl<CMyCtl> > comControlBase;
BEGIN_MSG_MAP(CMyCtl)
// Add your regular message handlers here

CHAIN_MSG_MAP(CComCompositeControl<CMyCtl>)
CHAIN_MSG_MAP(comControlBase)
END_MSG_MAP()

--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken

"Brian Burgess" <bburg...@hotmail.com> wrote in message

news:ket91v4qr96hmdjm8...@4ax.com...

Brian Burgess

unread,
Jan 4, 2003, 1:07:18 AM1/4/03
to
Thanks Igor, that is working great!.. :-)

-BB

0 new messages