在c ++线程中加载位图图像

时间:2017-03-28 10:09:01

标签: c++ winapi bitmap

我正在尝试加载选定的.bmp文件并将其显示在WM_PAINT中。该函数正在由代码运行,因此visual studio确实可以看到它。 这里的代码似乎不起作用:

case WM_PAINT:
{
    _hWindowDC = BeginPaint(_hwnd, &ps);

    if (g_bIsFileLoaded)
    {
        std::wstring wsFileName = g_vecImageFileNames.back();
        g_vecImageFileNames.pop_back();

        std::string File(wsFileName.length(), ' ');
        std::copy(wsFileName.begin(), wsFileName.end(), File.begin());

        HBITMAP h_BitMap = (HBITMAP)LoadImageA(g_hInstance, File.c_str(), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
        HDC h_HomeDC = CreateCompatibleDC(_hWindowDC);
        BITMAP BitMap;

        int i_Final = GetObject(reinterpret_cast<HGDIOBJ>(h_BitMap), sizeof(BITMAP), reinterpret_cast<LPVOID>(&BitMap));

        HBITMAP h_OldBit = (HBITMAP)::SelectObject(h_HomeDC, h_BitMap);

        SetStretchBltMode(_hWindowDC, HALFTONE);

        BOOL PaintBit = StretchBlt(_hWindowDC, 1, 1, 50, 50, h_HomeDC, 0, 0, BitMap.bmWidth, BitMap.bmHeight, SRCCOPY);

        ::SelectObject(h_HomeDC, h_OldBit);
        ::DeleteDC(h_HomeDC);
        ::DeleteObject(h_BitMap);

        InvalidateRect(_hwnd, NULL, NULL);

        g_bIsFileLoaded = false;
    }

    EndPaint(_hwnd, &ps);
    return (0);
}
break;

0 个答案:

没有答案