如题,图片在资源中定义,我的怎么也不显示
#include <stdAfx.h>
BOOL InitWindow(HINSTANCE hInstance, int nCmdShow);
LRESULT CALLBACK WinProc(HWND hWnd,
UINT message,
WPARAM wParam, LPARAM lParam );
HWND hWnd; //窗口句柄
int x,y;//窗口宽与高
HINSTANCE hInstance;
HBITMAP hBm;
BITMAP bm;
int PASCAL WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
if ( !InitWindow( hInstance, nCmdShow ) ) return FALSE;
MSG msg;
::hInstance =hInstance;
for (;;)//消息循环1
{
if(PeekMessage(&msg,NULL, 0, 0, PM_REMOVE))
{
if(msg.message== WM_QUIT) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}//消息循环1
return msg.wParam;
}
static BOOL InitWindow(HINSTANCE hInstance, int nCmdShow )
{
WNDCLASS wc;
wc.style=NULL;
wc.lpfnWndProc=(WNDPROC)WinProc;
wc.cbClsExtra=0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = NULL;
wc.hbrBackground = CreateSolidBrush (RGB(192,192,192)); //暗红色的背景
wc.lpszMenuName = NULL;
wc.lpszClassName = "My_Test";
RegisterClass(&wc);//注册窗口
//按所给参数创造窗口
hWnd = CreateWindow("My_Test",
"My first program",
WS_POPUP|WS_MAXIMIZE,
0,0,
x=400, //GetSystemMetrics( SM_CXSCREEN )此函数返回屏幕宽度
y=400, //GetSystemMetrics( SM_CYSCREEN )此函数返回屏幕高度
NULL,NULL,hInstance,NULL);
if( !hWnd ) return FALSE;
ShowWindow(hWnd,nCmdShow);//显示窗口
UpdateWindow(hWnd);//刷新窗口
return TRUE;
}//end initWindows
LRESULT CALLBACK WinProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
HDC hdc,hdcmem;
HBRUSH hb1,hb2;
HPEN hPen;
LPPOINT lpPoint;
PAINTSTRUCT ps;
switch( message )
{
case WM_KEYDOWN://击键消息
switch( wParam )
{
case VK_ESCAPE:
MessageBox(hWnd,"ESC键按下了! 确定后退出!","Keyboard",MB_OK);
PostMessage(hWnd, WM_CLOSE, 0, 0);//给窗口发送WM_CLOSE消息
break;
}
return 0; //处理完一个消息后返回0
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
hBm=LoadBitmap(hInstance,"IDB_BITMAP3");
hdcmem=CreateCompatibleDC(hdc);
SelectObject(hdcmem,hBm);
BitBlt(hdc,x/10,y/10,21,22,hdcmem,0,0,SRCCOPY);
//图片不显示
// DeleteDC(hdcmem);
ValidateRect(hWnd,NULL);
EndPaint(hWnd,&ps);
break;
case WM_CLOSE: //准备退出
DestroyWindow( hWnd ); //释放窗口
return 0;
case WM_RBUTTONDOWN:
MessageBox(hWnd,"鼠标右键按下了!","Mouse",MB_OK);
return 0;
case WM_DESTROY: //如果窗口被人释放…
PostQuitMessage( 0 ); //给窗口发送WM_QUIT消息
return 0;
}
//调用缺省消息处理过程
return DefWindowProc(hWnd,message,wParam,lParam);
}