windows api编程问题我从网上转载了一段加载位图代码并按照他的方法把图片放在工程文件夹内但却显示不出
由于字数限制,只能给出以下部分代码!#include"stdafx.h"HINSTANCEhInst;HBITMAPhbmp;HDCmdc;ATOMMyRegisterC...
由于字数限制,只能给出以下部分代码!
#include "stdafx.h"
HINSTANCE hInst;
HBITMAP hbmp;
HDC mdc;
ATOM MyRegisterClass (HINSTANCE hInstance);
BOOL InitInstance (HINSTANCE, int);LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
void MyPaint (HDC hdc);
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{ HWND hWnd; //窗口句柄
HDC hdc;
hInst = hInstance;
hWnd = CreateWindow("canvas", "绘图窗口" , WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd) { return FALSE; }
MoveWindow(hWnd,10,10,800,600,true);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
hdc = GetDC(hWnd);
mdc = CreateCompatibleDC(hdc);
hbmp =(HBITMAP)LoadImage(NULL,"bg.bmp",IMAGE_BITMAP,800,600,LR_LOADFROMFILE);
SelectObject(mdc,hbmp);
MyPaint(hdc);
ReleaseDC(hWnd,hdc);
return TRUE;
}//****自定义绘图函数*********************************
void MyPaint(HDC hdc)
{
BitBlt(hdc,0,0,800,600,mdc,0,0,SRCCOPY); //采用BitBlt函数贴图
}//****消息处理函数**********************************
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)//wParam的值为按下按键的虚拟键码//lParam则储存按键的相关状态信息
{ PAINTSTRUCT ps; HDC hdc; switch (message)
{ case WM_PAINT: //窗口重绘消息
hdc = BeginPaint(hWnd, &ps);
MyPaint(hdc);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY: //窗口结束消息
DeleteDC(mdc);
DeleteObject(hbmp);
PostQuitMessage(0);
break;
default: //其他消息
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
} 展开
#include "stdafx.h"
HINSTANCE hInst;
HBITMAP hbmp;
HDC mdc;
ATOM MyRegisterClass (HINSTANCE hInstance);
BOOL InitInstance (HINSTANCE, int);LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
void MyPaint (HDC hdc);
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{ HWND hWnd; //窗口句柄
HDC hdc;
hInst = hInstance;
hWnd = CreateWindow("canvas", "绘图窗口" , WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd) { return FALSE; }
MoveWindow(hWnd,10,10,800,600,true);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
hdc = GetDC(hWnd);
mdc = CreateCompatibleDC(hdc);
hbmp =(HBITMAP)LoadImage(NULL,"bg.bmp",IMAGE_BITMAP,800,600,LR_LOADFROMFILE);
SelectObject(mdc,hbmp);
MyPaint(hdc);
ReleaseDC(hWnd,hdc);
return TRUE;
}//****自定义绘图函数*********************************
void MyPaint(HDC hdc)
{
BitBlt(hdc,0,0,800,600,mdc,0,0,SRCCOPY); //采用BitBlt函数贴图
}//****消息处理函数**********************************
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)//wParam的值为按下按键的虚拟键码//lParam则储存按键的相关状态信息
{ PAINTSTRUCT ps; HDC hdc; switch (message)
{ case WM_PAINT: //窗口重绘消息
hdc = BeginPaint(hWnd, &ps);
MyPaint(hdc);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY: //窗口结束消息
DeleteDC(mdc);
DeleteObject(hbmp);
PostQuitMessage(0);
break;
default: //其他消息
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
} 展开
若以下回答无法解决问题,邀请你更新回答
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询