0
void CCreateList::paintRowList(CDialogEx* CCurent, int wBeginX, int wBeginY)
{
    CPaintDC dc(CCurent);
    CDC *cdc,cc;
    cdc=CCurent->GetDC();
    HANDLE hbitmap;
    hbitmap = LoadImage(0,L"C:\\PIC.png",IMAGE_BITMAP,100,100,0x00000010);
    cc.CreateCompatibleDC(cdc);
    cc.SelectObject(hbitmap);
    dc.BitBlt(100,100,100,100,&cc,0,0,SRCCOPY);
}

我想在对话框中绘制带有图像的标题。不要使用优化校准请帮帮我。

4

2 回答 2

5

这是我用于加载其他图像格式的代码。它依赖于 GDI+,因此您需要在使用之前和之后进行初始化和关闭(每个程序一次就足够了)

加载程序:

// BMP, GIF, JPEG, PNG, TIFF, Exif, WMF, and EMF
HBITMAP mLoadImg(WCHAR *szFilename)
{
   HBITMAP result=NULL;

   Gdiplus::Bitmap* bitmap = new Gdiplus::Bitmap(szFilename,false);
   bitmap->GetHBITMAP(NULL, &result);
   delete bitmap;
   return result;
}

初始化/关闭

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
   static Gdiplus::GdiplusStartupInput gdiplusStartupInput;
   static ULONG_PTR gdiplusToken;

    // so we can load all the image formats that windows supports natively - (I'm using a transparent PNG on the main dialog)
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

    // make things look pretty
    InitCommonControls();

    // run the app
    //DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
    //
    // 
    //

    // clean-up stuff
    Gdiplus::GdiplusShutdown(gdiplusToken);

    return 0;
}

自然,这是针对基于对话框的应用程序(对话框在 resource.rc 中定义)——而不是基于框架的应用程序或 MFC 应用程序。关键是,您只需要在使用前进行初始化,然后关闭即可。

于 2012-11-11T19:29:29.097 回答
0

我是这样做的:

CString strFileName;
        strFileName="C:\\PIC.bmp";
        BITMAP bmpPro;
        HBITMAP bmpHandle=(HBITMAP)LoadImage(NULL,strFileName,IMAGE_BITMAP,0,0, LR_LOADFROMFILE| LR_CREATEDIBSECTION);

        CBitmap bmpPicture;
        CDC mdcPicture;
        bmpPicture.Attach(bmpHandle);
        bmpPicture.GetBitmap(&bmpPro);
        mdcPicture.CreateCompatibleDC( &dc);
        CBitmap * bmpPrevious = 
                mdcPicture.SelectObject(&bmpPicture);
                dc.BitBlt(wCurrent, wBeginY,
        header[i].getWidthOfHeader(), wHeight,
                    &mdcPicture, 0, 0, SRCCOPY);

我成功了:X 谢谢:X

于 2012-11-11T19:10:20.490 回答