显示 HBITMAP
我预先道歉;我是c语言新手,我真的不知道我在做什么。
我正在尝试使用 Windows 7 和 c 捕获并显示屏幕截图。我知道这听起来很愚蠢,最终我将需要在不同的程序中使用这些功能,捕获屏幕的功能会将图像发送到显示它的功能,但现在我只是想让它们在一个程序中工作。以下是我迄今为止整理的代码:
#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?
更新:我添加了 DrawBitmap 但它不起作用...我收到以下输出,但不确定如何处理它:
'win_screenshot.exe': Loaded '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: Native”已退出,代码为 0 (0x0)。
I apologize upfront; I'm new to c and I really don't know what I'm doing.
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");
}
I just haven't been able to find any way to display the HBITMAP. How do I display the HBITMAP?
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': 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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显示
HBITMAP
需要将其传输(例如通过BitBlt
)到另一个DC
。以类似于您已经在做的方式,只是到另一个 DC,例如可能是窗口的 DC,请参阅GetDC
。MSDN 为您提供了示例代码:缩放图像< /a>,请参阅
DrawBitmap
函数。Displaying a
HBITMAP
would involve blitting it (e.g. viaBitBlt
) into anotherDC
. In a way similar to what you are already doing, just to another DC, which might be for example window's DC, seeGetDC
.MSDN provides you with sample code: Scaling an Image, see
DrawBitmap
function.