dragon中的光标绘制,个人更喜欢使用control开式的,也就是自己给画上去
class OwnerDrawCaret : public ICaret
{
public:
OwnerDrawCaret();
~OwnerDrawCaret();
virtual BOOL Create(IObject* pObj, HWND hWndParent, HBITMAP hbmp, int nWidth, int nHeight);
virtual void Destroy();
virtual void Show();
virtual void Hide();
virtual void SetPos(int x, int y);
virtual void OnControlPaint(IRenderTarget* p){};
// virtual void PreCommitWindowBuffer(HDC hMemDC){};
// virtual void PostCommitWindowBuffer(HDC hMemDC);
virtual CARET_TYPE GetType() { return CARET_TYPE_OWNERDRAW; }
void DoPaint();
protected:
void CreateTimer();
void DestroyTimer();
void SetPosBase(int x, int y);
private:
HWND m_hWnd;
IObject* m_pObject;
POINT m_ptLast;
SIZE m_sizeCaret;
CRect m_rcDraw;
UINT_PTR m_nTimerId;
bool m_bVisible;
};
void OwnerDrawCaret::DoPaint()
{
if (!m_hWnd)
return;
if (m_rcDraw.IsRectEmpty())
return;
HDC hDC = GetDC(m_hWnd);
HPEN hPen = CreatePen(PS_SOLID, 1, 0);
HPEN hOldPen = (HPEN)::SelectObject(hDC, hPen);
int nOld = ::SetROP2(hDC, R2_NOTXORPEN);
::MoveToEx(hDC, m_rcDraw.left, m_rcDraw.top, NULL);
::LineTo(hDC, m_rcDraw.left, m_rcDraw.bottom);
::SetROP2(hDC, nOld);
SelectObject(hDC, hOldPen);
DeleteObject(hPen);
::ReleaseDC(m_hWnd, hDC);
m_bVisible = !m_bVisible;
}
代码不难,在窗口的dc上进行了反色操作,但并没有画到内存图上边去