当前位置: 代码迷 >> VC >> VC6里边这样加载位图有错么?
  详细解决方案

VC6里边这样加载位图有错么?

热度:240   发布时间:2016-05-05 00:04:04.0
VC6里面这样加载位图有错么???
#include <AFXWIN.H>
#include "resource.h"
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ){
WNDCLASS wnd;
wnd.cbClsExtra=0;
wnd.cbWndExtra=0;
wnd.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wnd.hCursor=LoadCursor(hInstance,(LPCTSTR)IDC_CURSOR2);
wnd.hIcon=LoadIcon(hInstance,IDI_APPLICATION);
wnd.hInstance=hInstance;
wnd.lpfnWndProc=WndProc;
wnd.lpszClassName="window";
wnd.lpszMenuName=NULL;
wnd.style=CS_HREDRAW|CS_VREDRAW;

RegisterClass(&wnd);

HWND hwnd;
hwnd=CreateWindow("window","MyWindow",WS_OVERLAPPEDWINDOW,100,100,400,300,NULL,NULL,hInstance,NULL);

ShowWindow(hwnd,nShowCmd);

MSG msg;
while(GetMessage(&msg,NULL,0,0)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
HDC hdc;
PAINTSTRUCT ps;
HDC MemDC;
HBITMAP bmp=LoadBitmap(NULL,(LPCSTR)IDB_BITMAP1);
RECT r={10,10,500,500};

switch(uMsg){
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);//设备描述表
MemDC=CreateCompatibleDC(hdc);//内存DC
CreateCompatibleBitmap(MemDC,500,500);
SelectObject(MemDC,bmp);//在内存DC内加载位图
BitBlt(hdc,10,10,400,400,MemDC,0,0,SRCCOPY);
DeleteDC(MemDC);
EndPaint(hwnd,&ps);
break;
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}

为什么总是显示不了?
------解决方案--------------------
bitmap有load进来吗?
  相关解决方案