gpt4 book ai didi

c - 无效到 HBITMAP 转换问题

转载 作者:太空宇宙 更新时间:2023-11-04 08:34:06 27 4
gpt4 key购买 nike

我一直在第 123 行收到错误:

123 C:\Dev-Cpp\Window_main_2.c invalid conversion from `void*' to `HBITMAP__*'

我不知道这是怎么回事,它让我发疯。

void DrawBitmap(HDC hdcDest, char *filename, int x, int y)
{
HBITMAP image;
BITMAP bm;
HDC hdcMem;

// This is the line that brings about the issue (just ask me if more code is required because
// there is a lot more. Essentially this whole function points to a file and I call this
// function in another function that will compile a windows screen filled with the following
// image path. But I cant get this HBITMAP to agree with the image datatype. Please let me
// know if more info is required and thank you.) The line is below.
image = LoadImage(0, "C:\\Users\\Lillian\\Pictures\\c.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

GetObject(image, sizeof(BITMAP), &bm);

hdcMem = CreateCompatibleDC(global_hdc);
SelectObject(hdcMem, image);

BitBlt(
global_hdc,
x,
y,
bm.bmWidth,
bm.bmHeight,
hdcMem,
0,
0,
SRCCOPY);

DeleteDC(hdcMem);
DeleteObject((HBITMAP)image);
}

最佳答案

LoadImage() 返回一个 HANDLE。将结果分配给变量时需要强制转换:

image = (HBITMAP) LoadImage(0, "C:\\Users\\Lillian\\Pictures\\c.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

另外,在你DeleteDC()之前,你需要选择原来的HBITMAP回到hdcMem - 你需要在你的时候保存它提前调用 SelectObject()

关于c - 无效到 HBITMAP 转换问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27005959/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com