windows窗体应用背景图片设置和窗口一样大,提示错误?

 我来答
在晴天的雨伞
2016-05-25 · TA获得超过6868个赞
知道大有可为答主
回答量:5761
采纳率:86%
帮助的人:1157万
展开全部
#include <windows.h>
HBITMAP hbg;
BITMAP bm;
int w,h;
HDC memdc;
char *filename="pic.bmp";//位图文件名
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
switch(Message) {

case WM_DESTROY: {
PostQuitMessage(0);
break;
}
case WM_CREATE:
{
hbg=(HBITMAP)LoadImage(GetModuleHandle(0),filename,IMAGE_BITMAP,0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
GetObject(hbg,sizeof(BITMAP),(LPVOID)&bm);//获取位图尺寸
HDC hdc=GetDC(hwnd); //获取设备环境
memdc=CreateCompatibleDC(hdc); //获取内存设备环境
ReleaseDC(hwnd,hdc); //释放设备环境
}
case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint(hwnd,&ps);
SelectObject(memdc,hbg);
BitBlt(ps.hdc,0,0,bm.bmWidth,bm.bmHeight,memdc,0,0,SRCCOPY);
EndPaint(hwnd,&ps);
}
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
WNDCLASSEX wc;
HWND hwnd;
MSG msg;

memset(&wc,0,sizeof(wc));
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);

wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = "WindowClass";
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

if(!RegisterClassEx(&wc)) {
MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
return 0;
}

hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","Caption",WS_VISIBLE|WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
480,
NULL,NULL,hInstance,NULL);

if(hwnd == NULL) {
MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
return 0;
}

while(GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式