我有一个名为 IDC_PICTURECONTROL
的图片控件,还有一个名为 lpPicutre
的 LPPICTURE
。
当我的窗口接收到 WM_PAINT
时,我调用我的函数 drawPicture(HWND, LPPICTURE)
如下:
drawPicture(GetDlgItem(hDlg, IDC_PICTURECONTROL), lpPicture);
现在这样写,控件周围的黑色边框就消失了,根本没有绘制图片。
如果我编辑该函数,使其不绘制到图片控件,而是绘制到对话框本身 (hDlg
),则它会正确地绘制在窗口客户区的背景上。 (不是我想要的)。
这是绘画函数中的代码:
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,但这并没有改变任何东西。
我做错了什么?
最佳答案
如果此代码与 hDlg 一起工作,则没有问题,问题可能出在静态控件本身。确保它具有 SS_BITMAP 样式。在 Visual Studio 资源编辑器中,它被称为 Type,默认设置为 SS_BLACKFRAME (Frame)。
关于c++ - 在优化校准中绘制图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8222836/