简体   繁体   English

使用Visual Studio 2005在C ++中绘图

[英]Drawing in C++ using Visual Studio 2005

I have a problem with drawing in C++ using Visual Studio 2005. After event handling on MouseMove the results of using DrawLine function appear in PictureBox but if some window overlap the part of PictureBox all pixels in this place dissapear after moving the window. 我在使用Visual Studio 2005的C ++中进行绘图时遇到问题。在MouseMove上进行事件处理后,在PictureBox中显示使用DrawLine函数的结果,但是如果某些窗口与PictureBox的一部分重叠,则移动窗口后此位置的所有像素都会消失。 How can I solve this problem? 我怎么解决这个问题?

In your MouseMove handler, you just want to store the points where you will draw the lines (but don't draw anything at that time). MouseMove处理程序中,您只想存储绘制线条的点(但那时不绘制任何东西)。 At the end of that handler, call InvalidateRect to tell Windows that your window needs re-painting. 在该处理程序的末尾,调用InvalidateRect告诉Windows您的窗口需要重新绘制。 Windows will (eventually) respond to that with a WM_PAINT message. Windows将(最终)使用WM_PAINT消息对此做出响应。 When you receive the WM_PAINT message, retrieve the points and do the actual drawing. 当您收到WM_PAINT消息时,检索点并进行实际绘图。

If you're doing anything other than bare Win32 programming, chances are that whatever framework you're using will handle a few bits and pieces of that for you, but the general structure normally remains roughly the same. 如果您要进行的不是Win32裸机编程,则很可能您正在使用的任何框架都可以为您处理其中的一些零碎工作,但总体结构通常保持大致相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM