本文介绍了Cclientdc和dc没有在chtmleditctrl上绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

大家好我正在使用MFC中的CHtmlEditCtrl。我想在处理右键单击事件的函数中绘制一些随机矩形和线条。



我尝试过:



使用此片段从静态创建ChtmlEditCtrl控件:

Hi all I am working with a CHtmlEditCtrl in MFC. I want to draw some random rectangles and lines inside a function handling right click event.

What I have tried:

The ChtmlEditCtrl control is created from static using this snippet:

    bool CHtmlEditCtrlEx::CreateFromStatic( UINT nID, CWnd* pParent ) {
    	CStatic wndStatic;
    	if ( !wndStatic.SubclassDlgItem(nID, pParent)) {
    		return false;
    	}
    	CRect rc;
    	wndStatic.GetWindowRect( &rc );
    	pParent->ScreenToClient( &rc );
    	if (Create( 0, (WS_CHILD | WS_VISIBLE), rc, pParent, nID, 0 )) {
    		...
    }

Then I override the CWnd::pretranslate() function as thus:


      CClientDC dcc(this);
        switch (pMsg->message) {

        	case WM_RBUTTONUP:	// Right-click
                // Just some dummy values
        		DrawSquigly(dcc, 600, 240, 20);
                break;

        }

the DrawSquigly() function is defined as thus:

    void CHtmlEditCtrlEx::DrawSquigly(CDC &dcc, int iLeftX, int iWidth, int iY)
    {
    	CAMTrace trace;
    	trace.Trace("Drawing Squiggly");
    	//dcc.TextOut(10, 10, CString(_T("I used a client DC!")));

    	CPen * oldPen;
    	CBrush * oldBrush;
    	oldPen = (CPen *) dc.SelectStockObject(WHITE_PEN);
    	dcc.MoveTo(5,10);
    	dcc.LineTo(80, 10);
    	dcc.SelectObject(oldPen);

    	//GDI 002_2: Create custom pen with different Line thickness.
    	CPen thick_pen(PS_SOLID, 3, RGB(0,255,0));
    	oldPen = dc.SelectObject(&thick_pen);
    	dcc.MoveTo(5, 20);
    	dcc.LineTo(80,20);
    	dcc.SelectObject(oldPen);

    	//GDI 002_3: Create a Rectangle now
    	dcc.Draw3dRect(5,30,80,70, RGB(25,25,255), RGB(120,120,120));

    	//GDI 002_4: Create a Brush that we can use for filling the 
    	// closed surfaces
    	CBrush brush(RGB(255,0,255));
    	oldBrush = dc.SelectObject(&brush);
    	dcc.Rectangle(5,110,80,140);
    	dcc.SelectObject(oldBrush);

    	//GDI 002_5: Hatch Brush is useful to apply a pattern in stead 
    	//of solid fill color
    	CBrush* hatBrush = new CBrush();
    	hatBrush->CreateHatchBrush(HS_CROSS, RGB(255,0,255));
    	oldBrush = dc.SelectObject(hatBrush);
    	dcc.FillRect(new CRect(5,160,80,190), hatBrush);
    	dcc.SelectObject(oldBrush);
    }



但是当我点击右键时没有画出来。我想我错过了一些特别是因为我是MFC的新手。



我已经在事件处理程序的顶部添加了一条跟踪以确保该函数正在获取叫它,它是。



任何人都可以指出正确的方向吗?


but no drawing happens when I right click. I think I am missing something especially because I am new to MFC.

I have added a trace to the top of the event handler to be sure that the function is getting called and it is.

Can anyone please point me the right direction?

推荐答案

void CHtmlEditCtrlEx::OnPaint()
{
  CWnd::OnPaint();

  //here comes your drawing code
  DrawSquigly(...);
}





为了控制绘图,你应该使用在WM_RBUTTONUP消息中激活的成员变量。



For controlling the drawing you should use a member variable activated in the WM_RBUTTONUP message.


这篇关于Cclientdc和dc没有在chtmleditctrl上绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 12:25