admin管理员组文章数量:1123143
I'm reviving some really old Win32 API based code, and having a little trouble with images. The code below was derived from Microsoft's Hello World sample program at
I added lines 47 – 50 to test access to resource files. PlaySoundA works fine, it will play the sound whether yeow2.wav is located in the project directory OR in the Debug directory below it. But LoadImageA is not working for me no matter where Laser3.bmp is located. hh always comes out NULL, with GetLastError always returning zero. Really? Oh isn't that helpful!
Can anyone see something that I'm lacking, perhaps some prerequisite that needed to happen first? Or is there more than one .BMP format? I’ve tried this with multiple BMP files, which open just fine in Paint. So they’re not corrupted.
Visual Studio 17.11.4, Windows 11, 64-bit ARM, not using wide characters
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
// Register the window class.
const wchar_t CLASS_NAME[] = L"Sample Window Class";
WNDCLASS wc = { };
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
// Create the window.
HWND hwnd = CreateWindowEx(
0, // Optional window styles.
CLASS_NAME, // Window class
L"Learn to Program Windows", // Window text
WS_OVERLAPPEDWINDOW, // Window style
// Size and position
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, // Parent window
NULL, // Menu
hInstance, // Instance handle
NULL // Additional application data
);
if (hwnd == NULL)
{
return 0;
}
ShowWindow(hwnd, nCmdShow);
// test code
bool ok = PlaySoundA("yeow2.wav", NULL, SND_FILENAME | SND_ASYNC);
HBITMAP hh = (HBITMAP)LoadImageA(hInstance, "Laser3.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
DWORD err = GetLastError();
// Run the message loop.
MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
// All painting occurs here, between BeginPaint and EndPaint.
FillRect(hdc, &ps.rcPaint, (HBRUSH)(COLOR_GRAYTEXT + 1));
EndPaint(hwnd, &ps);
}
return 0;
}
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
本文标签: imageWhat does LoadImageA actually requireStack Overflow
版权声明:本文标题:image - What does LoadImageA actually require? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736551989a1944523.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论