2

我正在尝试显示一个图像,我通过GetOpenFilename. 这本身不是问题,我还尝试简单地将现有图像的 URL 从资源文件复制并粘贴到LoadBitmap函数中,并且我分配的 HBITMAP 为 NULL。我怎样才能使这项工作?

void GetUserSprite(HWND hwnd, HBITMAP &Image, HBITMAP &Mask)
{
using namespace std;
OPENFILENAME ofn;
char szFileName[MAX_PATH + 1];
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFilter = "Bitmaps (*.JPG, *.BMP, *.DIB, *.gif, *.JPEG, *.jpe, *.png)\0*.jpg;*.bmp;*.jpeg;*.png";
ofn.lpstrFile = szFileName;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
ofn.lpstrDefExt = "bmp";
if(GetOpenFileName(&ofn))
{
    bDefaultSprite = false;
    strImageURL = szFileName;
    Image = LoadBitmap(GetModuleHandle(NULL), strImageURL.c_str());
    if (Image == NULL)
    {
        MessageBox(hwnd, "Well, that sucks...", "", NULL);
    }
    Mask = CreateBitmapMask(Image, RGB(0,0,0));
    InvalidateRect(hwnd, NULL, TRUE);
    UpdateWindow(hwnd);
}
}
4

0 回答 0