qq_30907999
qq_30907999
2015-11-29 05:40

关于windows窗口加载图片 为什么我用LoadImage函数加载总是不成功

  • 图片
  • windows

#include
HBITMAP hbg;
BITMAP bm;
int w,h;
HDC memdc;
TCHAR *filename=L"1.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;

}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

0条回答