Reputation: 35
I develop an application in C++ on Windows CE 2013.
I want to load a bitmap from file and show it on-screen.
The problem is the LoadImage()
function always returns NULL
.
HDC hdcOkno;
hdcOkno = GetDC(hWnd);
HBITMAP hbmObraz;
hbmObraz = (HBITMAP)LoadImage(NULL, L"C:\\Users\\tykab\\OneDrive\\Pulpit\\bitmapy\\background_blue.bmp", IMAGE_BITMAP, 0, 0, NULL);
BITMAP bmInfo;
GetObject(hbmObraz, sizeof(bmInfo), &bmInfo);
BitBlt(hdcOkno, 50, 50, bmInfo.bmWidth, bmInfo.bmHeight, hdcOkno, 0, 0, SRCCOPY);
Upvotes: 0
Views: 738
Reputation: 6103
Update:
Since you are working on Windows CE platform, LoadImage()
can not load bitmaps from files. You should use SHLoadDIBitmap()
instead.
Original Answer:
From the LoadImage
documentation:
name
Type:
LPCTSTR
...
If the
hinst
parameter is NULL and thefuLoad
parameter omits theLR_LOADFROMFILE
value, thelpszName
specifies the OEM image to load......
If the
fuLoad
parameter includes theLR_LOADFROMFILE
value,lpszName
is the name of the file that contains the stand-alone resource (icon, cursor, or bitmap file). Therefore, sethinst
to NULL.
You are not specifying the LR_LOADFROMFILE
flag in the fuLoad
parameter. The last parameter should be set to the following when loading a file:
LR_DEFAULTSIZE | LR_LOADFROMFILE
As mentioned in the comments, it's always a good idea to check GetLastError()
on errors.
Upvotes: 3