【发布时间】:2013-02-06 10:31:50
【问题描述】:
我有一个名为IDC_PICTURECONTROL 的图片控件和一个名为LPPICTURE 的lpPicutre。
当我的窗口收到WM_PAINT 时,我像这样调用我的函数drawPicture(HWND, LPPICTURE):
drawPicture(GetDlgItem(hDlg, IDC_PICTURECONTROL), lpPicture);
现在的写法,控件周围的黑色边框刚刚消失,完全没有画图。
如果我编辑该函数,使其不绘制到图片控件,而是绘制到对话框本身 (hDlg),那么它会正确绘制在窗口客户区的背景上。 (不是我想要的)。
这是paint函数中的代码:
void drawPicture(HWND hWnd, LPPICTURE picture)
{
PAINTSTRUCT ps;
HDC hdc;
hdc = BeginPaint(hWnd, &ps);
//hdc = BeginPaint(hDlg, &ps); (works, but draws on window instead of control)
if (picture)
{
long hmWidth;
long hmHeight;
picture->get_Width(&hmWidth);
picture->get_Height(&hmHeight);
int nWidth = MulDiv(hmWidth, GetDeviceCaps(hdc, LOGPIXELSX), HIMETRIC_INCH);
int nHeight = MulDiv(hmHeight, GetDeviceCaps(hdc, LOGPIXELSY), HIMETRIC_INCH);
RECT rc;
GetClientRect(hWnd, &rc); // I have tried GetWindowRect() also
int w = 0, h = 0, x = 0, y = 0;
if (hmWidth == hmHeight)
{
// square
w = (rc.right - rc.left);
h = (rc.bottom - rc.top);
x = rc.left;
y = rc.top;
}
else if (hmWidth > hmHeight)
{
// wide
w = (rc.right - rc.left);
h = (w * hmHeight) / hmWidth;
x = rc.left;
y = (rc.bottom - rc.top - h) / 2;
}
else
{
//tall
h = (rc.bottom - rc.top);
w = (h * hmWidth) / hmHeight;
y = rc.top;
x = (rc.right - rc.left - w) / 2;
}
picture->Render(hdc, x, y, w, h, 0, hmHeight, hmWidth, -hmHeight, &rc);
}
EndPaint(hWnd, &ps);
//EndPaint(hDlg, &ps);
}
hWnd是图片控件的句柄,hDlg是对话框的句柄。
我想它可能是从某个地方拉出窗口,所以我将 x 和 y 设置为 0,将宽度和高度设置为 1000,但这并没有改变任何东西。
我做错了什么?
【问题讨论】: