在C++窗口中绘制图形
问题描述:
我想在窗口中绘制简单函数/坐标集合之外的图形。我知道C++ win32的基础知识,我可以用按钮和其他控制对象制作一个简单的窗口。但是,哪一个是最快和最简单的图库来绘制我的程序图?在C++窗口中绘制图形
答
我希望你使用的是Win32 API(不是CLR)。
理论很简单,您需要使用WM_PAINT消息来获取设备上下文。 您可以在主窗口中使用主窗口或任何子窗口(控制 - 静态,按钮)。
下面是一些有用的链接: http://www.codeproject.com/Articles/2078/Guide-to-WIN32-Paint-for-Intermediates
http://www.codeproject.com/Articles/66250/BeginPaint-EndPaint-or-GetDC-ReleaseDC.aspx
如:
case WM_PAINT:
BeginPaint(hWnd, &ps);
LineTo(ps.hDC, 30,30);
EndPaint(hWnd, &ps);
return 0;
这将画线从0,0到30,30
感谢您的快速和有益的答案!我做到了。现在我只需要找到一种方法在绘制线的地方制作一个矩形。 – Janman 2012-03-10 11:57:37
嗨@Janman,没问题,看看这里:http://msdn.microsoft.com/en-us/library/dd162898%28v=vs.85%29.aspx在BeginPaint和EndPaint中使用它如下:Rectangle (ps.hDC,0,0,30,30) – rkosegi 2012-03-10 12:44:26