问题描述
我正在实现一个使用 GDI+
WinAPI
在屏幕上显示图像的简单程序。
这是我到目前为止的代码:
#include <windows.h>
#include <objidl.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")
void Example_DrawImage9(HDC hdc) {
Graphics graphics(hdc);
Image image(L"C:/test.bmp");
graphics.DrawImage(&image,0);
}
LRESULT CALLBACK WindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE,LPSTR pCmdLine,int nCmdShow) {
ULONG_PTR token;
GdiplusStartupInput input = { 0 };
input.GdiplusVersion = 1;
GdiplusStartup(&token,&input,NULL);
const wchar_t CLASS_NAME[] = L"Sample Window Class";
WNDCLASS wc = {};
wc.lpfnWndProc = &WindowProc;
wc.hInstance = hInstance;
wc.lpszClassName = CLASS_NAME;
RegisterClass(&wc);
HWND hwnd = CreateWindowEx(0,CLASS_NAME,L"Learn to Program Windows",WS_POPUP,190,110,NULL,hInstance,NULL);
if (hwnd != NULL) {
ShowWindow(hwnd,nCmdShow);
MSG msg;
while (GetMessage(&msg,0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
GdiplusShutdown(token);
return 0;
}
LRESULT CALLBACK WindowProc(HWND hwnd,LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
PostQuitMessage(0);
return 0;
case WM_PAINT: {
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd,&ps);
FillRect(hdc,&ps.rcPaint,(HBRUSH)(COLOR_WINDOW + 1));
Example_DrawImage9(hdc);
EndPaint(hwnd,&ps);
return 0;
}
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
因为我只想显示图像本身(没有非客户区),所以我对创建的窗口使用 WS_POPUP
样式。
但显然有……窗口有问题 - 当我将鼠标移到应用程序窗口上时,我得到“正在加载/忙碌”(动画蓝色圆圈)。而且我不能移动窗口。当我将样式更改为例如 WS_CAPTION
时一切正常 - 鼠标光标是“正常”(通常只是箭头),我可以移动/拖动窗口。我如何使用 WS_POPUP
样式而不会有我描述的这种奇怪的副作用?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)