【发布时间】:2015-03-08 04:28:56
【问题描述】:
我正在尝试用 C++ 构建键盘记录器。
我的键盘记录器的一部分是捕获屏幕。
经过大量搜索后,我决定尝试构建一个来立即了解它是如何工作的。
这是我的屏幕截图代码:
HDC hdc = GetDC(NULL); // get the desktop device context
HDC hDest = CreateCompatibleDC(hdc); // create a device context to use yourself
// get the height and width of the screen
int height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
int width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
// create a bitmap
HBITMAP hbDesktop = CreateCompatibleBitmap(hdc, width, height);
// use the previously created device context with the bitmap
SelectObject(hDest, hbDesktop);
// copy from the desktop device context to the bitmap device context
// call this once per 'frame'
BitBlt(hDest, 0, 0, width, height, hdc, 0, 0, SRCCOPY);
/*CImage image; // from this code i tried to understand how to save the bitmap
image.Attach(hbDesktop);
image.Save(pathname, Gdiplus::ImageFormatBMP);*/
CImage image;//this code is what I came up with eventually
image.Attach(hbDesktop);
CHAR buffer[100] = _T("this is a literal string"); // THIS IS WHERE MY PROBLEM STARTS
sprintf(buffer,_T("this is a literal string"), 1);
image.Save(_T(buffer), Gdiplus::ImageFormatBMP);
我试图让程序每次都用不同的名称保存位图文件。
问题是最后一行不起作用,除非我使用_T 符号,并且当我放置_T 时,它不会占用缓冲区并显示“标识符“Lbuffer”未定义”。这是什么意思?我需要把这个 L 符号放在哪里,为什么?
另外,有没有更好的方法在不使用_T 符号的情况下将位图保存到文件中?
我试着查了一下,https://msdn.microsoft.com/en-us/library/dybsewaf.aspx 他们说这是关于 Unicode 的。为什么这个功能需要 Unicode?p>
【问题讨论】:
-
对不起,即使看了链接还是没看懂题目,如果有人能用我带来的代码示例给我解释一下,我会很高兴非常感谢各位助手
标签: c++