Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0
And game development. We have a problem in the capture part.
Windows 7 operating system. the process nprotect's gamemon.des the screen capture function does not work. What part did I go wrong?
 
namespace System.Drawing
{
    using System;
    using System.Runtime.InteropServices;
 
    public static class ScreenCapture
    {
        public static Bitmap DesktopCapture()
        {
            Bitmap bitmap;
            IntPtr desktopWindow = GetDesktopWindow();
            IntPtr dC = GetDC(desktopWindow);
            try
            {
                bitmap = Image.FromHbitmap(GetCurrentObject(dC, 7));
            }
            finally
            {
                ReleaseDC(desktopWindow, dC);
            }
            return bitmap;
        }
 
        [DllImport("gdi32.dll")]
        private static extern IntPtr GetCurrentObject(IntPtr hdc, ushort objectType);
        [DllImport("user32.dll")]
        private static extern IntPtr GetDC(IntPtr hwnd);
        [DllImport("User32")]
        private static extern IntPtr GetDesktopWindow();
        [DllImport("user32.dll")]
        private static extern void ReleaseDC(IntPtr hwnd, IntPtr hdc);
    }
}
Posted 19-Jan-13 10:14am
Edited 19-Jan-13 10:33am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Actually .net has it's own method to do it: Graphics.CopyFromScreen[^]. I suggest you consult this simple article for sample implementation: TeboScreen: Basic C# Screen Capture Application[^]
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 19-Jan-13 18:47pm
   
Absolutely right, my 5.
 
Sorry, my mistake was to put a bit redundant answer, as I did it before I paid attention that you already advised to use CopyFromScreen. However, in return, I added some motivation information, please see. I will add a credit to your answer now.
 
—SA
Zoltán Zörgő at 20-Jan-13 2:22am
   
Thank you.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Zoltán Zörgő answer.Does not progress, but having said
Is there any other way?
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 406
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 205
3 Raul Iloc 170
4 Maciej Los 164
0 OriginalGriff 8,289
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,624
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 20 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100