画一个矩形 [英] Drawing a rectangle

查看:90
本文介绍了画一个矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用CFormView在doc-view拱中编写一个应用程序.在窗体上有一个图片窗口.当前,此图片窗口没有附加的类.

这可能很重要,有几个DialogBar(一个在顶部,一个在左侧).左侧的一个有一个PropertySheet,其中有2个PropertyPages.它始终显示,并将formview(和其中的图片)向右推.

应用程序中当前有2个线程(除了应用程序线程外)-一个线程获取图像并对其进行处理(两个从相机或从加载的文件),另一个线程获取处理后的图像并显示它.当前显示是使用 Blt 通过direct-draw7进行的,如下所示.

hr = pDDSDest-> Blt(& rcDest,pDDSSource,& rcSrc,DDBLT_WAIT | DDBLT_DDFX,& ddbltfx);

该视图具有鼠标回调.因此,OnMouseMove和buttondown/up回调在视图中处理,并且显示线程可以通过视图中的数据进行缩放.完成,这可能需要一些时间,最终我也想解决.)

现在,我需要在图像上绘制一个矩形.为此,我认为我将在视图中覆盖OnDraw.

我认为我将按以下方式进行操作:

无效 CRunnerView :: OnDraw(CDC * pDC)

{

//TODO:在此处添加您的专用代码和/或调用基类

LOGBRUSH * lpLogBrush = LOGBRUSH;

lpLogBrush-> lbStyle = BS_NULL;

CBrush * pBrush = CBrush();

pBrush-> CreateBrushIndirect(lpLogBrush);

CPen * pPen = CPen(PS_DASH,1,RGB(255,255,255));

CPen * pOldPen = pDC-> SelectObject(pPen);

CBrush * pOldBrush = pDC-> SelectObject(pBrush);

CRect rect(10,10,200,200);

pDC-> Rectangle(& rect);

InvalidateRect(& rect,0); << ---- ----请参阅有关此行的评论

pDC-> SelectObject(pOldPen);

pDC-> SelectObject(pOldBrush);

删除 pPen;

删除 lpLogBrush;

删除 pBrush;

}

如果我未放入InvalidateRect,则矩形未显示,就像直接绘图中的图像在其上绘制一样.如果我确实放入了Invalidate rect,我会看到rect,尽管在晃动,并且原始图像也位于对话框栏推过的部分上-不会刷新对话框栏.
如果我移动整个东西(刷新),矩形将再次消失.

我想到了在直接调用代码中绘制矩形的方法-但是它不了解MFC等CDC之类的东西.我在那里只有HDC,而没有CDC.

有没有办法在视图中做到这一点?我应该在直接抽奖的地方进行此操作吗?

在此我将不胜感激,因为我希望已经掌握了这一点并继续前进:)

如果需要更多数据,我可以提供...

谢谢,
Jeff

解决方案



我的两分钱...

在使用DirectDraw时,API正在与图形卡紧密通信,该图形卡将表面输出到屏幕.随着GDI命令最终显示在图形卡上之前,它正在经过另一层(现在已忘记).这就是为什么当您移动/刷新窗口时矩形消失的原因.您还可以通过点击alt-print屏幕或print-screen进行测试,捕获的图像将包含一个显示DirectDraw表面的黑色区域(如果禁用硬件加速并执行print-screen,则将得到所有结果,但Windows将会慢...).

我认为适合您的解决方案是在DirectDraw曲面上绘制矩形.这可以通过创建1x1白色图像(即BltBlt以适当的大小和颜色过滤器放置在表面上)来相对简单地完成.不确定确切的api命令,但肯定是可能的.

附带说明,mfc api与Windows sdk api紧密命名,即pWnd-> ShowWindow(SW_SHOW),映射到调用ShowWindow(GetSafeHwnd(),SW_SHOW),这与CDC到HDC相似(CDC是MFC类包装器采用带HDC的函数,即dc.MoveTo(10,10)映射到MoveToEx(hdc,x,y,& point).

谢谢,
Mike .


Hi,
 
I am writing an application in the doc-view arch with a CFormView. On the form there is a picture window. Currently this picture window does not have a class attached to it.

Also, and this might be important, there are a few DialogBars (one on the top and one on the left side). The one on the left side has a PropertySheet with 2 PropertyPages in it. It is always shown and it pushes the formview (and the picture within) to the right.

There are currently 2 threads in the app (besides the application thread) - one thread acquires the image and processes it (either from a camera or from a loaded file) and the other thread gets the processed image and displays it. The display currently is done through direct-draw7 using Blt as follows.

hr = pDDSDest->Blt(&rcDest, pDDSSource, &rcSrc, DDBLT_WAIT | DDBLT_DDFX, &ddbltfx);

The view has the mouse callbacks. So OnMouseMove and the buttondown/up callbacks are handled in the view, and the display thread can do zooms via the data in the view.

So far so good (except that the redraws are only handled when the processing is finished which could take time and I would like to deal with this as well eventually).

Now, I need to draw a rectangle on the image. For this, I thought that I would override OnDraw in the view.

I thought I would do this as follows:

void CRunnerView::OnDraw(CDC* pDC)

{

// TODO: Add your specialized code here and/or call the base class

LOGBRUSH *lpLogBrush = new LOGBRUSH;

lpLogBrush->lbStyle = BS_NULL;

CBrush *pBrush = new CBrush();

pBrush->CreateBrushIndirect(lpLogBrush);

CPen *pPen = new CPen(PS_DASH, 1, RGB(255,255,255));

CPen* pOldPen = pDC->SelectObject(pPen);

CBrush* pOldBrush = pDC->SelectObject(pBrush);

CRect rect(10,10,200,200);

 pDC->Rectangle(&rect);

InvalidateRect(&rect,0); <<<---- SEE COMMENTS ABOUT THIS LINE

pDC->SelectObject(pOldPen);

pDC->SelectObject(pOldBrush);

delete pPen;

delete lpLogBrush;

delete pBrush; 

}

If I don't put in the InvalidateRect, the rectangle is NOT SEEN, as if the image from the direct-draw draws over it. If I do put in the Invalidate rect, I see the rect, albeit shaking, and the original image also is over the part pushed over by the dialogbar- no refresh of the dialog bar.
If I move the whole thing (refresh) the rectangle goes away again.

I thought of drawing the rectangle in the code that calls the direct draw -- but it doesn't know about MFC things like CDC and stuff like that. I only get an HDC there and not a CDC.

Is there a way to do this in the view? Should I do this in the place that calls direct draw?

I would appreciate some help in this because I would like to get by this already and move on :)

If more data is needed, I can provide it...

Thanks,
Jeff

解决方案

Hi,

My two cents...

When you are using DirectDraw, the API is communicating closely with the graphics card which outputs the surface to the screen. Where as the GDI commands are going through another layer (forgot for now), before eventually been shown by the graphics card. This is why when you move/refresh your window the rectangle dissappears. You can also test this by hitting alt-print screen or print-screen, the image captured will contain a black area where the DirectDraw surface is displayed (if you disable hardware acceleration and do print-screen you will get everything, but windows will be slow...).

I think the solution for you is draw the rectangle on to the DirectDraw surface. This could be done relatively simply, by creating a 1x1 white image (that is BltBlt on to the surface at the appropriat size and color filter. Not sure on the exact api command but is certainly possible.

As a side note, the mfc api is closely named to the windows sdk api, i.e. pWnd->ShowWindow( SW_SHOW), maps to a call ShowWindow( GetSafeHwnd(), SW_SHOW). This is similar for CDC to HDC (CDC is a MFC class wrapper around functions that take a HDC), i.e. dc.MoveTo( 10, 10) maps to MoveToEx( hdc, x, y, &point).

Thanks,
Mike.


这篇关于画一个矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆