Procházet zdrojové kódy

一个使用DirectX 9.0的截图函数,但是部分函数没有找到头文件,估计要完整安装DX9.

sat23 před 5 roky
rodič
revize
01cd1c7eab
1 změnil soubory, kde provedl 55 přidání a 2 odebrání
  1. 55 2
      GameAssist/GameAssist/Assist.cpp

+ 55 - 2
GameAssist/GameAssist/Assist.cpp

@@ -1,6 +1,10 @@
 #include "StdAfx.h"
 #include "Assist.h"
 
+#include <D3D9.h>
+//#include <D3dx9tex.h>
+#pragma comment(lib, "D3dx9.lib")
+
 namespace GAssist
 {
 	// 根据路径名查找进程,返回进程ID;
@@ -107,10 +111,10 @@ namespace GAssist
 			ghwnd.strClassName = szClass;
 			g_vtGameHwnd.push_back(ghwnd);
 
-			printf("0x%08X    " , hWnd); // 输出窗口信息   
+			_tprintf_s(_T("0x%08X    ") , hWnd); // 输出窗口信息   
 			TCHAR buf[MAX_PATH];  
 			SendMessage(hWnd, WM_GETTEXT, MAX_PATH, (LPARAM)buf);  
-			wprintf(L"%s/n" , buf);  
+			_tprintf_s(_T("%s/n") , buf);
 			EnumChildWindows(hWnd, EnumChildWindowCallBack, lParam);    // 递归查找子窗口   
 		}  
 		return  TRUE;  
@@ -327,4 +331,53 @@ namespace GAssist
 		::ReleaseDC(hWnd, hDC); 
 	}  
 
+
+// 	#include <D3D9.h>
+// 	#include <D3dx9tex.h>
+// 	#pragma comment(lib, "D3dx9.lib")
+	//#include <d3d9helper>
+	BOOL ScreenShot(LPDIRECT3DDEVICE9 lpDevice, HWND hWnd, TCHAR* fileName)
+	{
+		HRESULT hr;
+		// Get adapter display mode
+		D3DDISPLAYMODE mode;
+		if (FAILED(hr = lpDevice->GetDisplayMode(0, &mode)))
+			return hr;
+
+		// Create the surface to hold the screen image data
+		LPDIRECT3DSURFACE9 surf;
+		if (FAILED(hr = lpDevice->CreateOffscreenPlainSurface(mode.Width,
+			mode.Height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &surf, NULL))) //注意第四个参数不能是D3DPOOL_DEFAULT
+		{
+			return hr;
+		}
+
+		// Get the screen data
+		if (FAILED(hr = lpDevice->GetFrontBufferData(0, surf)))
+		{
+			surf->Release();
+			return hr;
+		}
+
+		// area to capture
+		RECT* rect = NULL;
+
+		WINDOWINFO windowInfo;
+		windowInfo.cbSize = sizeof(WINDOWINFO);
+
+		if (hWnd) // capture window
+		{
+			GetWindowInfo(hWnd, &windowInfo);
+			rect = &windowInfo.rcWindow;
+		}
+
+		// Save the screen date to file
+		hr = D3DXSaveSurfaceToFile(fileName, D3DXIFF_BMP, surf, NULL, rect);
+
+		surf->Release();
+
+		return hr;
+	}
+
+
 }