为什么我无法在窗口上显示位图? [英] Why I'm not able to display a bitmap on a window ?
本文介绍了为什么我无法在窗口上显示位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想在我的win32应用程序的主窗口中添加一个背景。
我正在使用resedit来管理资源,而我已经添加了一个位图并将其设置为主窗口。
现在我有问题要显示它,这是我的资源文件中的位图(由resedit生成):
Hi all,
I'd like to add a background to the main window of my win32 app.
I'm using resedit to manage resources, and I've already added a bitmap and set it to the main window.
Now I'm having issues to display it, here is the bitmap in my resource file (generated by resedit):
CONTROL IDB_BG, 0, WC_STATIC, SS_BITMAP, 0, 0, 517, 252, WS_EX_LEFT
以下是我试图显示位图的方法:
Here is how I'm trying to display the bitmap:
case WM_INITDIALOG:
bg = (HBITMAP) LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_BG));
break;
case WM_PAINT:
PAINTSTRUCT ps;
HDC hdc;
BITMAP bitmap;
HDC hdcMem;
HGDIOBJ oldBitmap;
hdc = BeginPaint(hwndDlg, &ps);
hdcMem = CreateCompatibleDC(hdc);
oldBitmap = SelectObject(hdcMem, bg);
GetObject(bg, sizeof(bitmap), &bitmap);
BitBlt(hdc, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, oldBitmap);
DeleteDC(hdcMem);
EndPaint(hwndDlg, &ps);
break;
程序编译但不显示位图。
感谢您的帮助!
The program compiles but the bitmap isn't displayed.
Thanks for the help!
推荐答案
在 WM_ERASEBKGND 处理程序。
检查其他所有内容:返回码。 hwndDlg是绘图的正确窗口。或者您在不可见的位置(0,0)上绘制位图。
Drawing the background is better done in the WM_ERASEBKGND handler.
Check everything else: the return codes. Is hwndDlg the right window for the drawing. Or you draw the bitmap on a invisible position (0,0).
这篇关于为什么我无法在窗口上显示位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文