在onPaint里调用DrawBK函数,未能正确显示图片,谢谢void DrawBMP(HDC hDstDC, CString strPath)
{
HDC hDC;
HBITMAP hBmp;
HBITMAP hOldBmp;
BITMAP bm;
hDC = CreateCompatibleDC(NULL); hBmp = (HBITMAP)LoadImage(NULL, strPath, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADFROMFILE | LR_CREATEDIBSECTION); hOldBmp = (HBITMAP)SelectObject(hDC ,hBmp); GetObject(hBmp, sizeof(BITMAP), &bm); BitBlt(hDstDC, 0, 0, bm.bmWidth, bm.bmHeight, hDC, 0, 0,SRCCOPY); SelectObject(hDC ,hOldBmp);
DeleteObject(hDC);
DeleteObject(hBmp);
}void DrawBK(CPaintDC& dc)
{
HDC hMemDC;
HDC hDC;
hMemDC = CreateCompatibleDC(NULL);
DrawBMP(hMemDC, L"D:\\1.BMP"); hDC = dc.GetSafeHdc(); BitBlt(hDC, 0, 0, 1000, 1000, hMemDC, 0, 0, SRCCOPY); DeleteObject(hMemDC);
// dc.BitBlt(330,30,5000,5000,&MemDC,0,0,SRCCOPY);
}

解决方案 »

  1.   

    CPaintDC& dc 这个dc有没有值
      

  2.   

    在onPaint里调用DrawBMP函数
    void DrawBMP(HDC hDstDC, CString strPath)
    hDstDC应该是CPaintDC& dc 
    函数里:
    HDC hDC;
    hDC = CreateCompatibleDC(NULL);
    这个NULL应该是CPaintDC& dc 
      

  3.   

    hMemDC = CreateCompatibleDC(&dc);
    试试
      

  4.   

    没有为 hMemDC 添加 HBITMAP (画布)
      

  5.   


    这个dc是有值的,CPaintDC dc(this);
    DrawBK(dc);
    CDialog::OnPaint();
      

  6.   

        hDC = CreateCompatibleDC(NULL);
    他们的意思是这个NULL应该是dc
      

  7.   

    BitBlt(hDC, 0, 0, 1000, 1000, hMemDC, 0, 0, SRCCOPY);这一句,4,5个参数,不能是具体的数值吧,应该是图片的宽窄吧,如果设定特定的数值,好像就是有问题的。你另外一个点到点拷贝 的函数试试。那个可以缩放。
      

  8.   

    和这个问题不大,NULL为创建与当前设备相兼容的设备DC,改dc的HDC,问题依旧
      

  9.   

    都说没有画布了
    void DrawBK(CPaintDC& dc)
    {
      HDC hDC = dc.GetSafeHdc();
      int nWidth = dc.GetDeviceCaps(HORZRES);
      int nHeight = dc.GetDeviceCaps(VERTRES);
      
      HDC hMemDC = CreateCompatibleDC(hDC);
      HBITMAP hBitmap = CreateCompatibleBitmap(hDC, nWidth, nHeight);  
      HBITMAP hOldBitamp = (HBITMAP)SelectObject(hMemDC, hBitmap);   
      
      DrawBMP(hMemDC, L"D:\\1.BMP");  BitBlt(hDC, 0, 0, nWidth, nHeight, hMemDC, 0, 0, SRCCOPY);  SelectObject(hMemDC, hOldBitamp);  
      DeleteObject(hBitmap);
      DeleteDC(hMemDC);
    }