C++控制台"屏幕捕获"问题
C++ console "Screen capture" issue
我有这个代码,屏幕捕获,它应该可以工作,但我不知道问题出在哪里它说"没有目标架构"我认为它是关于位的事情..IM 运行 Windows 7 32 位,IM 使用 Visual Studio 2012。提前谢谢堆栈溢出
#include <windef.h>
#include <wingdi.h>
#include <fileapi.h>
#include <Windows.h>
#include <handleapi.h>
#include <iostream>
using namespace std;
HWND Window;
int main()
{
char file[] = "c:\Users\MtDesktop\j.jpg";
if(Capture(file) == true)
cout << "Screen shot successful at " << file << endl;
else
cout << "Unknow Error " << endl;
}
HWND Window;
BOOL Capture(char *file)
{
HDC hdc;
HBITMAP bitmap;
BITMAPINFO bmpinfo;
LPVOID pBits;
HDC hdc2;
DWORD dwWidth, dwHeight, dwBPP, dwNumColors;
HGDIOBJ gdiobj;
HANDLE hfile;
DWORD dwBytes;
hdc=CreateDC("DISPLAY", NULL, NULL, NULL);
if(hdc==NULL) {
return FALSE;
}
dwWidth = GetDeviceCaps(hdc, HORZRES);
dwHeight = GetDeviceCaps(hdc, VERTRES);
dwBPP = GetDeviceCaps(hdc, BITSPIXEL);
if(dwBPP<=8) {
dwNumColors = GetDeviceCaps(hdc, NUMCOLORS);
dwNumColors = 256;
} else {
dwNumColors = 0;
}
hdc2=CreateCompatibleDC(hdc);
if(hdc2==NULL) {
DeleteDC(hdc);
return FALSE;
}
bmpinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpinfo.bmiHeader.biWidth = dwWidth;
bmpinfo.bmiHeader.biHeight = dwHeight;
bmpinfo.bmiHeader.biPlanes = 1;
bmpinfo.bmiHeader.biBitCount = (WORD) dwBPP;
bmpinfo.bmiHeader.biCompression = BI_RGB;
bmpinfo.bmiHeader.biSizeImage = 0;
bmpinfo.bmiHeader.biXPelsPerMeter = 0;
bmpinfo.bmiHeader.biYPelsPerMeter = 0;
bmpinfo.bmiHeader.biClrUsed = dwNumColors;
bmpinfo.bmiHeader.biClrImportant = dwNumColors;
bitmap = CreateDIBSection(hdc, &bmpinfo, DIB_PAL_COLORS, &pBits, NULL, 0);
if(bitmap==NULL) {
DeleteDC(hdc);
DeleteDC(hdc2);
return FALSE;
}
gdiobj = SelectObject(hdc2, (HGDIOBJ)bitmap);
if((gdiobj==NULL) || (gdiobj==(void *)GDI_ERROR)) {
DeleteDC(hdc);
DeleteDC(hdc2);
return FALSE;
}
if (!BitBlt(hdc2, 0,0, dwWidth, dwHeight, hdc, 0,0, SRCCOPY)) {
DeleteDC(hdc);
DeleteDC(hdc2);
return FALSE;
}
RGBQUAD colors[256];
if(dwNumColors!=0) {
dwNumColors = GetDIBColorTable(hdc2, 0, dwNumColors, colors);
}
BITMAPFILEHEADER bitmapfileheader;
BITMAPINFOHEADER bitmapinfoheader;
bitmapfileheader.bfType = 0x4D42;
bitmapfileheader.bfSize = ((dwWidth * dwHeight * dwBPP)/8) + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (dwNumColors * sizeof(RGBQUAD));
bitmapfileheader.bfReserved1 = 0;
bitmapfileheader.bfReserved2 = 0;
bitmapfileheader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (dwNumColors * sizeof(RGBQUAD));
bitmapinfoheader.biSize = sizeof(BITMAPINFOHEADER);
bitmapinfoheader.biWidth = dwWidth;
bitmapinfoheader.biHeight = dwHeight;
bitmapinfoheader.biPlanes = 1;
bitmapinfoheader.biBitCount = (WORD)dwBPP;
bitmapinfoheader.biCompression = BI_RGB;
bitmapinfoheader.biSizeImage = 0;
bitmapinfoheader.biXPelsPerMeter = 0;
bitmapinfoheader.biYPelsPerMeter = 0;
bitmapinfoheader.biClrUsed = dwNumColors;
bitmapinfoheader.biClrImportant = 0;
hfile=CreateFile(file,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(hfile==INVALID_HANDLE_VALUE) {
DeleteObject(bitmap);
DeleteDC(hdc2);
DeleteDC(hdc);
return FALSE;
}
WriteFile(hfile,&bitmapfileheader,sizeof(BITMAPFILEHEADER), &dwBytes, NULL);
WriteFile(hfile,&bitmapinfoheader,sizeof(BITMAPINFOHEADER), &dwBytes, NULL);
if(dwNumColors!=0)
WriteFile(hfile,colors,sizeof(RGBQUAD)*dwNumColors,&dwBytes,NULL);
WriteFile(hfile,pBits,(dwWidth*dwHeight*dwBPP)/8,&dwBytes,NULL);
CloseHandle(hfile);
DeleteObject(bitmap);
DeleteDC(hdc2);
DeleteDC(hdc);
return TRUE;
}
这就是我得到的..我不知道我做错了什么
Error 1 error C1189: #error : "No Target Architecture" C:Program FilesWindows Kits8.0Includeumwinnt.h 146 1 capture it 2
您需要在 windef.h 之前包含 windows.h
您需要进入项目的配置,并设置目标体系结构。在您的情况下,我假设这是 x86。
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 屏幕插入运算符<<的运算符过载问题
- 使用 fstream 库并在屏幕上打印的文件有问题?
- 显示和隐藏Windows 10屏幕键盘(osk.exe)时遇到问题
- BMP的完整屏幕截图.与块状和保存有关的问题
- OpenGL:MESA3D屏幕上的软件渲染性能问题
- FLTK 桌面屏幕截图问题
- 不触摸屏幕时的Android(Juce)性能问题
- SDL2-从Surface(屏幕快照)创建纹理的问题
- 此屏幕捕获代码有什么问题?
- SDL2图像到屏幕问题
- 在全屏运行快板程序后出现屏幕分辨率问题
- Qt保存屏幕截图 - 命名问题
- C++控制台"屏幕捕获"问题
- 在 SDL 中,当我在屏幕上绘制菜单时,它会使游戏变慢并且无法正常工作,我该如何解决这个问题?
- visual C++更改屏幕方向问题--DEVMODE dmDisplayOrientation DMDO_90未定义
- 输出到屏幕有什么问题?
- 检测Qt问题中的屏幕旋转
- Qt android屏幕锁定java问题