Jump to content
  • Advertisement

Amokossi

Member
  • Content Count

    6
  • Joined

  • Last visited

Community Reputation

109 Neutral

About Amokossi

  • Rank
    Newbie
  1. Thanks. Will give it a try. Added you to Gmail. If I get any Problems I may get back to you ;)   BTW: What Timezone are you?   Germany:11:50 PM 10:18   Kingston (GMT+11:30) 09:48   Lord Howe Island (GMT+11) 09:18   Adelaide (GMT+10:30) 06:48   Perth (GMT+8) 05:48   Weihnachtsinsel (GMT+7)   *EDIT* Got it: MemoryStream ms = new MemoryStream(screenshot.CapturedBitmap);                             Image i = Image.FromStream(ms);                             i.Save("test.jpg");  
  2. This is my code and the Backbuffer is drawn to Picturebox1. Maybe someone can edit it to save a bmp/jpg or png file instead of Picturebox1?   Strg+F4 inject Strg+F5 capture using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Diagnostics; using System.Threading; using EasyHook; using System.Runtime.Remoting.Channels.Ipc; using System.Runtime.Remoting; using System.Runtime.InteropServices; using System.IO; using Capture.Interface; using Capture.Hook; using Capture; namespace TestScreenshot { public partial class Form1 : Form { public Form1() { InitializeComponent(); } [DllImport("user32.dll")] private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk); [DllImport("user32.dll")] private static extern bool UnregisterHotKey(IntPtr hWnd, int id); const int MOD_CONTROL = 0x0002; const int MOD_SHIFT = 0x0004; const int WM_HOTKEY = 0x0312; private void Form1_Load(object sender, EventArgs e) { { RegisterHotKey(this.Handle, 1, MOD_CONTROL , (int)Keys.F4); RegisterHotKey(this.Handle, 2, MOD_CONTROL , (int)Keys.F5); } } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { UnregisterHotKey(this.Handle, 1); } protected override void WndProc(ref Message m) { if (m.Msg == WM_HOTKEY && (int)m.WParam == 1) btnInject.PerformClick(); if (m.Msg == WM_HOTKEY && (int)m.WParam == 2) btnCapture.PerformClick(); base.WndProc(ref m); } private void btnInject_Click(object sender, EventArgs e) { if (_captureProcess == null) { btnInject.Enabled = false; if (cbAutoGAC.Checked) { // NOTE: On some 64-bit setups this doesn't work so well. // Sometimes if using a 32-bit target, it will not find the GAC assembly // without a machine restart, so requires manual insertion into the GAC // Alternatively if the required assemblies are in the target applications // search path they will load correctly. // Must be running as Administrator to allow dynamic registration in GAC Config.Register("Capture", "Capture.dll"); } AttachProcess(); } else { HookManager.RemoveHookedProcess(_captureProcess.Process.Id); _captureProcess.CaptureInterface.Disconnect(); _captureProcess = null; } if (_captureProcess != null) { btnInject.Text = "Detach"; btnInject.Enabled = true; } else { btnInject.Text = "Inject"; btnInject.Enabled = true; } } int processId = 0; Process _process; CaptureProcess _captureProcess; private void AttachProcess() { string exeName = Path.GetFileNameWithoutExtension(textBox1.Text); Process[] processes = Process.GetProcessesByName(exeName); foreach (Process process in processes) { // Simply attach to the first one found. // If the process doesn't have a mainwindowhandle yet, skip it (we need to be able to get the hwnd to set foreground etc) if (process.MainWindowHandle == IntPtr.Zero) { continue; } // Skip if the process is already hooked (and we want to hook multiple applications) if (HookManager.IsHooked(process.Id)) { continue; } Direct3DVersion direct3DVersion = Direct3DVersion.Direct3D10; if (rbDirect3D11.Checked) { direct3DVersion = Direct3DVersion.Direct3D11; } else if (rbDirect3D10_1.Checked) { direct3DVersion = Direct3DVersion.Direct3D10_1; } else if (rbDirect3D10.Checked) { direct3DVersion = Direct3DVersion.Direct3D10; } else if (rbDirect3D9.Checked) { direct3DVersion = Direct3DVersion.Direct3D9; } else if (rbAutodetect.Checked) { direct3DVersion = Direct3DVersion.AutoDetect; } CaptureConfig cc = new CaptureConfig() { Direct3DVersion = direct3DVersion, ShowOverlay = cbDrawOverlay.Checked }; processId = process.Id; _process = process; var captureInterface = new CaptureInterface(); captureInterface.RemoteMessage += new MessageReceivedEvent(CaptureInterface_RemoteMessage); _captureProcess = new CaptureProcess(process, cc, captureInterface); break; } Thread.Sleep(10); if (_captureProcess == null) { MessageBox.Show("No executable found matching: '" + exeName + "'"); } else { btnLoadTest.Enabled = true; btnCapture.Enabled = true; } } /// <summary> /// Display messages from the target process /// </summary> /// <param name="message"></param> void CaptureInterface_RemoteMessage(MessageReceivedEventArgs message) { txtDebugLog.Invoke(new MethodInvoker(delegate() { txtDebugLog.Text = String.Format("{0}\r\n{1}", message, txtDebugLog.Text); }) ); } /// <summary> /// Display debug messages from the target process /// </summary> /// <param name="clientPID"></param> /// <param name="message"></param> void ScreenshotManager_OnScreenshotDebugMessage(int clientPID, string message) { txtDebugLog.Invoke(new MethodInvoker(delegate() { txtDebugLog.Text = String.Format("{0}:{1}\r\n{2}", clientPID, message, txtDebugLog.Text); }) ); } DateTime start; DateTime end; private void btnCapture_Click(object sender, EventArgs e) { start = DateTime.Now; progressBar1.Maximum = 1; progressBar1.Step = 1; progressBar1.Value = 0; DoRequest(); } private void btnLoadTest_Click(object sender, EventArgs e) { // Note: we bring the target application into the foreground because // windowed Direct3D applications have a lower framerate // if not the currently focused window _captureProcess.BringProcessWindowToFront(); start = DateTime.Now; progressBar1.Maximum = Convert.ToInt32(txtNumber.Text); progressBar1.Minimum = 0; progressBar1.Step = 1; progressBar1.Value = 0; DoRequest(); } /// <summary> /// Create the screen shot request /// </summary> void DoRequest() { progressBar1.Invoke(new MethodInvoker(delegate() { if (progressBar1.Value < progressBar1.Maximum) { progressBar1.PerformStep(); _captureProcess.BringProcessWindowToFront(); // Initiate the screenshot of the CaptureInterface, the appropriate event handler within the target process will take care of the rest _captureProcess.CaptureInterface.BeginGetScreenshot(new Rectangle(int.Parse(txtCaptureX.Text), int.Parse(txtCaptureY.Text), int.Parse(txtCaptureWidth.Text), int.Parse(txtCaptureHeight.Text)), new TimeSpan(0, 0, 2), Callback); } else { end = DateTime.Now; txtDebugLog.Text = String.Format("Debug: {0}\r\n{1}", "Total Time: " + (end-start).ToString(), txtDebugLog.Text); } }) ); } /// <summary> /// The callback for when the screenshot has been taken /// </summary> /// <param name="clientPID"></param> /// <param name="status"></param> /// <param name="screenshotResponse"></param> void Callback(IAsyncResult result) { using (Screenshot screenshot = _captureProcess.CaptureInterface.EndGetScreenshot(result)) try { _captureProcess.CaptureInterface.DisplayInGameText("Screenshot captured..."); if (screenshot != null && screenshot.CapturedBitmap != null) { pictureBox1.Invoke(new MethodInvoker(delegate() { if (pictureBox1.Image != null) { pictureBox1.Image.Dispose(); } pictureBox1.Image = screenshot.CapturedBitmap.ToBitmap(); }) ); } Thread t = new Thread(new ThreadStart(DoRequest)); t.Start(); } catch { } } } } Thanks. This still gives teh error when detaching. But maybe I just do not detach. You know if the SharpDX Version you used (2.4.2) is compatible to win8? On Win8 I got crashes and maybe I can take 2.6.2 release of sharpXP.   Amokossi
  3. Hey Thanks.   I sent a PM. ;)   Seems that this errormessage is now gone. Injecting and taking screens into Picturebox is fine now. But when I detach Fifa freeztes and crashes. Do I definately have to detach?
  4. Ok. I got 2 Hotkeys. 1 For Inject and 1 for capture. And it is capturing the fullscreen image into your Tool.   Fullscreen Capture:   But I still get the error message as before and the Game is crashing.   What I will need to finally make out of these brilliant results is. Change all this to get rid of the fault I'm getting save the captured screenshot into a file clean all up to have only the functions and form I need. best regards Rene
  5. Yes its code from your project.   I already downloaded your projects and tried to hook into the application with no success at all.I tried also to hook in any other process like notepad but then windows throws an error notepad no more working and similar... The link you gave me now seem to be a newer version as in the old was no auto-detect. I can successfully hook into the process.   In windowed mode its fine and i can see the screen in your tool but I get an error. see attached.     I need to program a key to make the capture with your Direct3DHook in fullscreen. Fast solution or is tehre already a hotkey?       VB is not a need. Finally it would be ok if I have an .exe which do the DirectX screen and saves it in the same folder. The other things will be done in my tool which then just start the exe to take the screenshot.   best regards René
  6. Hi,   I need to find an answer to a problem I'm having with taking fullscreen Screenshots using SlimDX. SlimDX must be used as all basic screenshot methods giving me black screens in Win7. In the past I used to press F10 ingame and the game switches to window mode - take screen - switches back to fullscreen.   This is really annoying.   The background is that we are going to start kind of FIFA Tournament Page and want to implement in the client tool a Screenshot option to proove the result in case of different result entries.   What I finally got after searching and using some code snippets is. It uses SlimDX and works in windowed mode. As soon as I switch to Fullscreen I get "device lost" error in VB2010.   Project Visual Basic 2010   The code seem to be messed up by the code tag here but copy paste into VB will work fine.   These 3 Lines seem to be problematic: This -> was original in the code snippet-> Not working at all in windowed or fullscreen: 'bitmap = New Bitmap(SlimDX.Direct3D9.Surface.ToStream(surface, SlimDX.Direct3D9.ImageFileFormat.Bmp, New Rectangle(region.Left, region.Top, region.Right, region.Bottom))) This -> was modified in a forum -> Not working at all in windowed or fullscreen: 'bitmap = New Bitmap(SlimDX.Direct3D9.Surface.ToStream(surface, SlimDX.Direct3D9.ImageFileFormat.Bmp, New Rectangle(region.Left, region.Top, region.Width, region.Height))) This -> modified by me-> working in windowed not in fullscreen (device lost error): bitmap = New Bitmap(SlimDX.Direct3D9.Surface.ToStream(surface, SlimDX.Direct3D9.ImageFileFormat.Bmp, New Rectangle(100, 100, 100, 100))) Imports System Imports System.Collections.Generic Imports System.Text Imports System.Drawing Imports System.Runtime.InteropServices Imports System.ComponentModel Imports System.Data Imports System.Linq Imports System.Windows.Forms Public Class Form1 Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As IntPtr, ByVal id As Integer, ByVal fsModifier As Integer, ByVal vk As Integer) As Integer Private Declare Sub UnregisterHotKey Lib "user32" (ByVal hWnd As IntPtr, ByVal id As Integer) Private Const Key_NONE As Integer = &H0 Private Const WM_HOTKEY As Integer = &H312 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'die F10 taste abfangen RegisterHotKey(Me.Handle, 1, Key_NONE, Keys.F10) End Sub Private Sub test() Handles Button1.Click Dim prcs As System.Diagnostics.Process() = System.Diagnostics.Process.GetProcessesByName("fifa14") For Each prc As System.Diagnostics.Process In prcs Dim screenshot As Bitmap = Spazzarama.ScreenCapture.Direct3DCapture.CaptureWindow(prc.MainWindowHandle) screenshot.Save("C:\Users\ReneLenovo\Documents\FIFA 11\1.bmp", System.Drawing.Imaging.ImageFormat.Bmp) Next End Sub Protected Overrides Sub WndProc(ByRef m As Message) 'die messages auswerten If m.Msg = WM_HOTKEY Then test() 'hier wird entschieden welcher hotkey es war 'einfach die übergebene id auswerten 'Select Case m.WParam ' Case ' MessageBox.Show("Sie haben die Tab-Taste gedrückt!") ' Case 2 ' MessageBox.Show("Sie haben die 1 gedrückt!") 'End Select MyBase.WndProc(m) End Sub End Class Namespace Spazzarama.ScreenCapture Public Module Direct3DCapture Sub New() End Sub Private _direct3D9 As New SlimDX.Direct3D9.Direct3D() Private _direct3DDeviceCache As New Dictionary(Of IntPtr, SlimDX.Direct3D9.Device)() ''' <summary> ''' Capture the entire client area of a window ''' </summary> ''' <param name="hWnd"></param> ''' <returns></returns> Public Function CaptureWindow(ByVal hWnd As IntPtr) As Bitmap Return CaptureRegionDirect3D(hWnd, NativeMethods.GetAbsoluteClientRect(hWnd)) End Function ''' <summary> ''' Capture a region of the screen using Direct3D ''' </summary> ''' <param name="handle">The handle of a window</param> ''' <param name="region">The region to capture (in screen coordinates)</param> ''' <returns>A bitmap containing the captured region, this should be disposed of appropriately when finished with it</returns> Public Function CaptureRegionDirect3D(ByVal handle As IntPtr, ByVal region As Rectangle) As Bitmap Dim hWnd As IntPtr = handle Dim bitmap As Bitmap = Nothing ' We are only supporting the primary display adapter for Direct3D mode Dim adapterInfo As SlimDX.Direct3D9.AdapterInformation = _direct3D9.Adapters.DefaultAdapter Dim device As SlimDX.Direct3D9.Device '#Region "Get Direct3D Device" ' Retrieve the existing Direct3D device if we already created one for the given handle If _direct3DDeviceCache.ContainsKey(hWnd) Then device = _direct3DDeviceCache(hWnd) Else ' We need to create a new device ' Setup the device creation parameters Dim parameters As New SlimDX.Direct3D9.PresentParameters() parameters.BackBufferFormat = adapterInfo.CurrentDisplayMode.Format Dim clientRect As Rectangle = NativeMethods.GetAbsoluteClientRect(hWnd) parameters.BackBufferHeight = clientRect.Height parameters.BackBufferWidth = clientRect.Width parameters.Multisample = SlimDX.Direct3D9.MultisampleType.None parameters.SwapEffect = SlimDX.Direct3D9.SwapEffect.Discard parameters.DeviceWindowHandle = hWnd parameters.PresentationInterval = SlimDX.Direct3D9.PresentInterval.[Default] parameters.FullScreenRefreshRateInHertz = 0 ' Create the Direct3D device device = New SlimDX.Direct3D9.Device(_direct3D9, adapterInfo.Adapter, SlimDX.Direct3D9.DeviceType.Hardware, hWnd, SlimDX.Direct3D9.CreateFlags.SoftwareVertexProcessing, parameters) _direct3DDeviceCache.Add(hWnd, device) End If '#End Region ' Capture the screen and copy the region into a Bitmap Using surface As SlimDX.Direct3D9.Surface = SlimDX.Direct3D9.Surface.CreateOffscreenPlain(device, adapterInfo.CurrentDisplayMode.Width, adapterInfo.CurrentDisplayMode.Height, SlimDX.Direct3D9.Format.A8R8G8B8, SlimDX.Direct3D9.Pool.SystemMemory) device.GetFrontBufferData(0, surface) 'bitmap = New Bitmap(SlimDX.Direct3D9.Surface.ToStream(surface, SlimDX.Direct3D9.ImageFileFormat.Bmp, New Rectangle(region.Left, region.Top, region.Right, region.Bottom))) 'bitmap = New Bitmap(SlimDX.Direct3D9.Surface.ToStream(surface, SlimDX.Direct3D9.ImageFileFormat.Bmp, New Rectangle(region.Left, region.Top, region.Width, region.Height))) bitmap = New Bitmap(SlimDX.Direct3D9.Surface.ToStream(surface, SlimDX.Direct3D9.ImageFileFormat.Bmp, New Rectangle(100, 100, 100, 100))) End Using Return bitmap End Function End Module #Region "Native Win32 Interop" ''' <summary> ''' The RECT structure defines the coordinates of the upper-left and lower-right corners of a rectangle. ''' </summary> <Serializable(), StructLayout(LayoutKind.Sequential)> _ Friend Structure RECT Public Left As Integer Public Top As Integer Public Right As Integer Public Bottom As Integer Public Sub New(ByVal left As Integer, ByVal top As Integer, ByVal right As Integer, ByVal bottom As Integer) Me.Left = left Me.Top = top Me.Right = right Me.Bottom = bottom End Sub Public ReadOnly Property AsRectangle() As Rectangle Get Return New Rectangle(Me.Left, Me.Top, Me.Right - Me.Left, Me.Bottom - Me.Top) End Get End Property Public Shared Function FromXYWH(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer) As RECT Return New RECT(x, y, x + width, y + height) End Function Public Shared Function FromRectangle(ByVal rect As Rectangle) As RECT Return New RECT(rect.Left, rect.Top, rect.Right, rect.Bottom) End Function End Structure <System.Security.SuppressUnmanagedCodeSecurity()> _ Friend NotInheritable Class NativeMethods <DllImport("user32.dll")> _ Friend Shared Function GetClientRect(ByVal hWnd As IntPtr, ByRef lpRect As RECT) As Boolean End Function <DllImport("user32.dll")> _ Friend Shared Function GetWindowRect(ByVal hWnd As IntPtr, ByRef lpRect As RECT) As <MarshalAs(UnmanagedType.Bool)> Boolean End Function ''' <summary> ''' Get a windows client rectangle in a .NET structure ''' </summary> ''' <param name="hwnd">The window handle to look up</param> ''' <returns>The rectangle</returns> Friend Shared Function GetClientRect(ByVal hwnd As IntPtr) As Rectangle Dim rect As New RECT() GetClientRect(hwnd, rect) Return rect.AsRectangle End Function ''' <summary> ''' Get a windows rectangle in a .NET structure ''' </summary> ''' <param name="hwnd">The window handle to look up</param> ''' <returns>The rectangle</returns> Friend Shared Function GetWindowRect(ByVal hwnd As IntPtr) As Rectangle Dim rect As New RECT() GetWindowRect(hwnd, rect) Return rect.AsRectangle End Function Friend Shared Function GetAbsoluteClientRect(ByVal hWnd As IntPtr) As Rectangle Dim windowRect As Rectangle = NativeMethods.GetWindowRect(hWnd) Dim clientRect As Rectangle = NativeMethods.GetClientRect(hWnd) ' This gives us the width of the left, right and bottom chrome - we can then determine the top height Dim chromeWidth As Integer = CInt(((windowRect.Width - clientRect.Width) / 2)) Return New Rectangle(New Point(windowRect.X + chromeWidth, windowRect.Y + (windowRect.Height - clientRect.Height - chromeWidth)), clientRect.Size) End Function End Class #End Region End Namespace Maybe someone can try this code and maybe find a solution. Thanks René
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!