显示HBITMAP [英] Displaying HBITMAP

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

问题描述

我先向您道歉;我是c的新手,我真的不知道自己在做什么.

I apologize upfront; I'm new to c and I really don't know what I'm doing.

我正在尝试使用Windows 7和c捕获并显示屏幕截图.我知道这听起来很愚蠢,最终我将需要在不同的程序中使用这些功能,捕获屏幕的功能会将图像发送到显示它的功能,但现在我只是想让它们都在一个程序中工作.到目前为止,这是我整理的代码:

I am trying to capture and display a screen shot using Windows 7 and c. I know it sounds dumb, eventually I will need each of these functions in different programs, the one that captures the screen will send the image to the one that displays it but for now I am just trying to get them both to work in one program. Here is the code I've put together so far:

     #include <windows.h>

bool ScreenCapture(int x, int y, int width, int height){
// get a DC compat. w/ the screen
HDC hDc = CreateCompatibleDC(0);

// make a bmp in memory to store the capture in
HBITMAP hBmp = CreateCompatibleBitmap(GetDC(0), width, height);

// join em up
SelectObject(hDc, hBmp);

// copy from the screen to my bitmap
BitBlt(hDc, 0, 0, width, height, GetDC(0), x, y, SRCCOPY);

HDC myhDc = GetDC(hBitmap, sizeof(BITMAP), (LPSTR)&Bitmap);

BitBlt(myhDc, 0, 0, width, height, hDc, x, y, SRCCOPY);

//Display bitmap
DrawBitmap(myhDC,0,0,hBmp,SRCCOPY);

//GetDC(hBitmap, sizeof(BITMAP), (LPSTR)&Bitmap);

// free the bitmap memory
DeleteObject(hBmp);

return 0;
}

int main(){
ScreenCapture(500, 200, 300, 300);
system("pause");
}

我只是无法找到任何显示HBITMAP的方法.如何显示HBITMAP?

I just haven't been able to find any way to display the HBITMAP. How do I display the HBITMAP?

更新:我添加了DrawBitmap,但是它不起作用...我得到以下输出,并且不确定如何处理它:

Update: I added DrawBitmap but it isn't working... I am getting the following output and am not sure how to process it:

'win_screenshot.exe':已加载'C:\ Users \ mbrooker \ Documents \ Visual Studio 2010 \ Projects \ win_screenshot \ Debug \ win_screenshot.exe',已加载符号. 'win_screenshot.exe':已加载'C:\ Windows \ SysWOW64 \ ntdll.dll',找不到或打开PDB文件 'win_screenshot.exe':已加载'C:\ Windows \ SysWOW64 \ kernel32.dll',找不到或打开PDB文件 'win_screenshot.exe':已加载'C:\ Windows \ SysWOW64 \ KernelBase.dll',找不到或打开PDB文件 'win_screenshot.exe':已加载'C:\ Windows \ SysWOW64 \ user32.dll',找不到或打开PDB文件 'win_screenshot.exe':已加载'C:\ Windows \ SysWOW64 \ gdi32.dll',找不到或打开PDB文件 'win_screenshot.exe':已加载'C:\ Windows \ SysWOW64 \ lpk.dll',找不到或打开PDB文件 'win_screenshot.exe':已加载'C:\ Windows \ SysWOW64 \ usp10.dll',找不到或打开PDB文件 'win_screenshot.exe':已加载'C:\ Windows \ SysWOW64 \ msvcrt.dll',找不到或打开PDB文件 'win_screenshot.exe':已加载'C:\ Windows \ SysWOW64 \ advapi32.dll',找不到或打开PDB文件 'win_screenshot.exe':已加载'C:\ Windows \ SysWOW64 \ sechost.dll',找不到或打开PDB文件 'win_screenshot.exe':已加载'C:\ Windows \ SysWOW64 \ rpcrt4.dll',找不到或打开PDB文件 'win_screenshot.exe':已加载'C:\ Windows \ SysWOW64 \ sspicli.dll',找不到或打开PDB文件 'win_screenshot.exe':已加载'C:\ Windows \ SysWOW64 \ cryptbase.dll',找不到或打开PDB文件 'win_screenshot.exe':已加载'C:\ Windows \ SysWOW64 \ msvcr100d.dll',已加载符号. 'win_screenshot.exe':已加载'C:\ Windows \ SysWOW64 \ imm32.dll',找不到或打开PDB文件 'win_screenshot.exe':已加载'C:\ Windows \ SysWOW64 \ msctf.dll',找不到或打开PDB文件 'win_screenshot.exe':已加载'C:\ Windows \ SysWOW64 \ apphelp.dll',找不到或打开PDB文件 'win_screenshot.exe':已加载'ImageAtBase0x4ab60000',已通过包含/排除设置禁用加载. 'win_screenshot.exe':已卸载'ImageAtBase0x4ab60000' 程序"[1480] win_screenshot.exe:本机"已退出,代码为0(0x0).

'win_screenshot.exe': Loaded 'C:\Users\mbrooker\Documents\Visual Studio 2010\Projects\win_screenshot\Debug\win_screenshot.exe', Symbols loaded. 'win_screenshot.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file 'win_screenshot.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file 'win_screenshot.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file 'win_screenshot.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file 'win_screenshot.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file 'win_screenshot.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file 'win_screenshot.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file 'win_screenshot.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file 'win_screenshot.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file 'win_screenshot.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file 'win_screenshot.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file 'win_screenshot.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file 'win_screenshot.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file 'win_screenshot.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded. 'win_screenshot.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file 'win_screenshot.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file 'win_screenshot.exe': Loaded 'C:\Windows\SysWOW64\apphelp.dll', Cannot find or open the PDB file 'win_screenshot.exe': Loaded 'ImageAtBase0x4ab60000', Loading disabled by Include/Exclude setting. 'win_screenshot.exe': Unloaded 'ImageAtBase0x4ab60000' The program '[1480] win_screenshot.exe: Native' has exited with code 0 (0x0).

推荐答案

显示HBITMAP会涉及将其(例如,通过BitBlt)拖到另一个DC中.以与您正在执行的操作类似的方式,仅连接到另一个DC,例如可能是窗口的DC,请参见GetDC.

Displaying a HBITMAP would involve blitting it (e.g. via BitBlt) into another DC. In a way similar to what you are already doing, just to another DC, which might be for example window's DC, see GetDC.

MSDN为您提供示例代码:缩放图片,请参见DrawBitmap功能.

MSDN provides you with sample code: Scaling an Image, see DrawBitmap function.

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

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