描述:
我需要在控件的一个方法中向控件自身发送WM_DRAWITEM消息 调用OnDraw 但是我不知道该控件的句柄 请问 如何在ATL编写的控件中向控件自身发送消息? 也就是如何获取控件的句柄?
还有 在创建ATL的向导里 Miscellaneous页中 Windowed Only 这个选项 有什么作用? 书上说可以提供HWND 但是我不知道如何获取!
解决方案1:
都有
class your_Miscellaneous :
public CAxDialogImpl<CSBaseCodeEdit>,
.........
CAxDialogImpl derives from CDialogImplBaseT, which in turn derives from TBase (by default, CWindow) and CMessageMap.
class ATL_NO_VTABLE your_Ctl :
public CComObjectRootEx<CComSingleThreadModel>,
public CStockPropImpl<CPolyCtl, IPolyCtl, &IID_IPolyCtl, &LIBID_POLYGONLib>,
public CComControl<your_Ctl>,
........
CComControl is a set of useful control helper functions and essential data members for ATL controls. When you create a standard control or a DHTML control using the ATL Control Wizard, the wizard will automatically derive your class from CComControl. CComControl derives most of its methods from CComControlBase.
ATL Library Reference
CComControlBase::FireViewChangeSee Also
CComControlBase Overview | Class Members
Call this method to tell the container to redraw the control, or notify the registered advise sinks that the control's view has changed.
HRESULT FireViewChange( );
Return Value
One of the standard HRESULT values.
Remarks
If the control is active (the control class data member CComControlBase::m_bInPlaceActive is TRUE), notifies the container that you want to redraw the entire control. If the control is inactive, notifies the control's registered advise sinks (through the control class data member CComControlBase::m_spAdviseSink) that the control's view has changed.
Example
STDMETHODIMP CSomeCtrl::put_Shape(short newVal)
{
// store newVal in m_nShape user-defined member
m_nShape = newVal;
// notify container to redraw control
FireViewChange();
return S_OK;
}
See Also
CComControlBase Overview | Class Members
--------------------------------------------------------------------------------
Send feedback on this topic to Microsoft
© Microsoft Corporation. All rights reserved.
1. FireViewChange()
2.
CWindow::operator HWND
operator HWND( ) const;
Remarks
Converts a CWindow object to an HWND.
CWindow Overview | Class Members
你的控件没有m_hWnd吗?这个就是hwnd
解决方案4:::m_hWnd就直接可用,可以在方法中直接调用::FireViewChange()来让OnDraw()重绘