CreateCompatibleBitmap()返回黑色HBITMAP [英] CreateCompatibleBitmap() returns black HBITMAP

查看:81
本文介绍了CreateCompatibleBitmap()返回黑色HBITMAP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Stack Overflow用户.似乎我在以下代码中没有正确使用CreateCompatibleBitmap():

Hello Stack Overflow users. It seems that I am not using CreateCompatibleBitmap() properly in the following code:

#include <windows.h>
using namespace std;
int main() {HDC hdc=GetDC(HWND_DESKTOP); HDC MemDC=CreateCompatibleDC(hdc);
    HBITMAP hBit=CreateCompatibleBitmap(hdc,1366,768);
    SelectObject(MemDC,hBit);
    BitBlt(hdc,0,0,1366,768,MemDC,0,0,SRCCOPY); //Screen turns black
    DeleteObject(hBit);
    ReleaseDC(HWND_DESKTOP,hdc);
    ReleaseDC(NULL,MemDC);
    DeleteDC(MemDC);
    DeleteDC(hdc);
}

我认为CreateCompatibleBitmap()将返回Desktop DC的1366x768部分,但是在BitBlt()之后显示黑屏.我没有使用CreateCompatibleBitmap而是将位图文件加载到hBit中,并且一切都按需进行,所以我想问题出在仅CreateCompatibleBitmap()上.我是否正确使用此功能?我有没有做的事应该做​​吗?

I thought CreateCompatibleBitmap() was to return a 1366x768 section of the Desktop DC, but a black screen is displayed after BitBlt(). Instead of using CreateCompatibleBitmap I load an bitmap file into hBit and everything is as desired, so I guess the problem is with CreateCompatibleBitmap() only. Am I using this function properly? Is there something I am not doing that I am supposed to do?

推荐答案

CreateCompatibleBitmap 为您创建了位图,但不应使用桌面或其他任何东西对其进行初始化.您无需初始化即可将其涂抹到桌面上,因此黑色并非意外.如果要保留桌面图像,则需要反向旋转,即从桌面DC变为选中了创建的位图的DC.

CreateCompatibleBitmap created bitmap for you, but it's not supposed to be initialized with a part of desktop or anything else. You blit it into desktop without initializing, hence blackness is not something unexpected. If you want it to hold desktop image, you need to blit in reverse direction, from desktop DC into DC with the created bitmap selected.

这篇关于CreateCompatibleBitmap()返回黑色HBITMAP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆