我正在尝试显示图片,我通过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);
}
}