简体   繁体   English

如何在MFC对话框的静态区域中绘制图像?

[英]How can I draw an image in a static area in an MFC dialog?

In an MFC dialog I have a static area and assigned an id: IDC_STATIC . 在MFC对话框中,我有一个静态区域并分配了一个ID: IDC_STATIC How can I connect this IDC_STATIC id with the handler ( HWND ) such that my image will draw inside the static text area? 如何将IDC_STATIC ID与处理程序( HWND )连接起来,以便图像可以在静态文IDC_STATIC绘制?

HWND   g_hWnd3      = NULL;
HDC    g_hDC3       = NULL;

g_hDC3 = ::GetDC( g_hWnd3 );

How can I pass the static text id as a GetDC() argument? 如何传递静态文本ID作为GetDC()参数?

You should consider deriving your own class from CStatic. 您应该考虑从CStatic派生自己的类。 The advantage to this approach is that you can control all of the rendering to the control from one self contained class. 这种方法的优点是,您可以从一个自包含类控制向控件的所有渲染。 In particular, if you define the static control with the SS_OWNERDRAW style, you will be able to handle its rendering in CStatic::DrawItem . 特别是,如果您使用SS_OWNERDRAW样式定义静态控件,则可以在CStatic :: DrawItem中处理其呈现。 When DrawItem is called, you will receive a pointer to the DrawItemStruct, which has embedded in it, a handle to the control's DC that you can use to render into the control. 调用DrawItem时,您将收到一个指向DrawItemStruct的指针,该指针已嵌入其中,它是控件DC的句柄,可用于渲染到控件中。

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

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