35 mensajes Página 1 de 2
Hola amigos de AMSSpecialist.info, quiero presentaros la tercera DLL que he creado es una dll muy simple y limitada pero bueno es lo que diríamos practicas con Visual Studio. Como el nombre bien describe esta dll es para capturas de pantalla, ventanas, secciones... mas adelante la mejorare por ahora me contento con esto jejeje... si detectarais algún error decírmelo gracias!!

using System;
using System.Collections.Generic;
using System.Text;
using RGiesecke.DllExport;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;

namespace CaptureGDIDLL
{
    internal static class UnmanagedExports
    {
        private static Image CaptureScreenA()
        {
            return CaptureWindowA(User32.GetDesktopWindow());
        }

        private static Image CaptureScreenRegionA(int xvalue, int yvalue, int width, int height)
        {
            return CaptureWindowRegionA(User32.GetDesktopWindow(), xvalue, yvalue,  width, height);
        }
       

        private static Image CaptureWindowA(IntPtr handle)
        {
            // get te hDC of the target window
            IntPtr hdcSrc = User32.GetWindowDC(handle);
            // get the size
            User32.RECT windowRect = new User32.RECT();
            User32.GetWindowRect(handle, ref windowRect);
            int width = windowRect.right - windowRect.left;
            int height = windowRect.bottom - windowRect.top;
            // create a device context we can copy to
            IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
            // create a bitmap we can copy it to,
            // using GetDeviceCaps to get the width/height
            IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, width, height);
            // select the bitmap object
            IntPtr hOld = GDI32.SelectObject(hdcDest, hBitmap);
            // bitblt over
            GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, 0, 0, GDI32.SRCCOPY);
            // restore selection
            GDI32.SelectObject(hdcDest, hOld);
            // clean up
            GDI32.DeleteDC(hdcDest);
            User32.ReleaseDC(handle, hdcSrc);
            // get a .NET image object for it
            Image img = Image.FromHbitmap(hBitmap);
            // free up the Bitmap object
            GDI32.DeleteObject(hBitmap);
            return img;
        }

        private static Image CaptureWindowRegionA(IntPtr handle, int xvalue, int yvalue, int width, int height)
        {
            // get te hDC of the target window
            IntPtr hdcSrc = User32.GetWindowDC(handle);
            // get the size
            User32.RECT windowRect = new User32.RECT();
            User32.GetWindowRect(handle, ref windowRect);
            // create a device context we can copy to
            IntPtr hdcDest = GDI32.CreateCompatibleDC(hdcSrc);
            // create a bitmap we can copy it to,
            // using GetDeviceCaps to get the width/height
            IntPtr hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, width, height);
            // select the bitmap object
            IntPtr hOld = GDI32.SelectObject(hdcDest, hBitmap);
            // bitblt over
            GDI32.BitBlt(hdcDest, 0, 0, width, height, hdcSrc, xvalue, yvalue, GDI32.SRCCOPY);
            // restore selection
            GDI32.SelectObject(hdcDest, hOld);
            // clean up
            GDI32.DeleteDC(hdcDest);
            User32.ReleaseDC(handle, hdcSrc);
            // get a .NET image object for it
            Image img = Image.FromHbitmap(hBitmap);
            // free up the Bitmap object
            GDI32.DeleteObject(hBitmap);
            return img;
        }

        private class GDI32
        {

            public const int SRCCOPY = 0x00CC0020; // BitBlt dwRop parameter
            [DllImport("gdi32.dll")]
            public static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest,
                int nWidth, int nHeight, IntPtr hObjectSource,
                int nXSrc, int nYSrc, int dwRop);
            [DllImport("gdi32.dll")]
            public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int nWidth,
                int nHeight);
            [DllImport("gdi32.dll")]
            public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
            [DllImport("gdi32.dll")]
            public static extern bool DeleteDC(IntPtr hDC);
            [DllImport("gdi32.dll")]
            public static extern bool DeleteObject(IntPtr hObject);
            [DllImport("gdi32.dll")]
            public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
        }

        private class User32
        {
            [StructLayout(LayoutKind.Sequential)]
            public struct RECT
            {
                public int left;
                public int top;
                public int right;
                public int bottom;
            }
            [DllImport("user32.dll")]
            public static extern IntPtr GetDesktopWindow();
            [DllImport("user32.dll")]
            public static extern IntPtr GetWindowDC(IntPtr hWnd);
            [DllImport("user32.dll")]
            public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
            [DllImport("user32.dll")]
            public static extern IntPtr GetWindowRect(IntPtr hWnd, ref RECT rect);
        }

        // Function CaptureWindow args: handle and filename.
        [DllExport("CaptureWindow", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
        static void CaptureWindow(IntPtr handle, string filename, int format)
        {
            Image img = CaptureWindowA(handle);
            var formatF = ImageFormat.Jpeg;
            if (format == 1) { formatF = ImageFormat.Bmp; }
            else if (format == 2) { formatF = ImageFormat.Emf; }
            else if (format == 3) { formatF = ImageFormat.Exif; }
            else if (format == 4) { formatF = ImageFormat.Gif; }
            else if (format == 5) { formatF = ImageFormat.Icon; }
            else if (format == 6) { formatF = ImageFormat.Jpeg; }
            else if (format == 7) { formatF = ImageFormat.Png; }
            else if (format == 8) { formatF = ImageFormat.Tiff; }
            else if (format == 9) { formatF = ImageFormat.Wmf; }
            img.Save(filename, formatF);
        }

        // Function CaptureWindowRegion args: hadle, filename, format, xvalue, yvalue, width and height
        [DllExport("CaptureWindowRegion", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
        static void CaptureWindowRegion(IntPtr handle, string filename, int format, int xvalue, int yvalue, int width, int height)
        {
            Image img = CaptureWindowRegionA(handle, xvalue, yvalue, width, height);
            var formatF = ImageFormat.Jpeg;
            if      (format == 1) { formatF = ImageFormat.Bmp; }
            else if (format == 2) { formatF = ImageFormat.Emf; }
            else if (format == 3) { formatF = ImageFormat.Exif; }
            else if (format == 4) { formatF = ImageFormat.Gif; }
            else if (format == 5) { formatF = ImageFormat.Icon; }
            else if (format == 6) { formatF = ImageFormat.Jpeg; }
            else if (format == 7) { formatF = ImageFormat.Png; }
            else if (format == 8) { formatF = ImageFormat.Tiff; }
            else if (format == 9) { formatF = ImageFormat.Wmf; }
            img.Save(filename, formatF);
        }

        // Function CaptureScreen args: filename and format.
        [DllExport("CaptureScreen", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
        static void CaptureScreen(string filename, int format)
        {
            Image img = CaptureScreenA();
            var formatF = ImageFormat.Jpeg;
            if (format == 1) { formatF = ImageFormat.Bmp; }
            else if (format == 2) { formatF = ImageFormat.Emf; }
            else if (format == 3) { formatF = ImageFormat.Exif; }
            else if (format == 4) { formatF = ImageFormat.Gif; }
            else if (format == 5) { formatF = ImageFormat.Icon; }
            else if (format == 6) { formatF = ImageFormat.Jpeg; }
            else if (format == 7) { formatF = ImageFormat.Png; }
            else if (format == 8) { formatF = ImageFormat.Tiff; }
            else if (format == 9) { formatF = ImageFormat.Wmf; }
            img.Save(filename, formatF);
        }

        // Function CaptureScreenRegion args: filename, format xvalue, yvalue, width and height.
        [DllExport("CaptureScreenRegion", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
        static void CaptureScreenRegion(string filename, int format, int xvalue, int yvalue, int width, int height)
        {
            Image img = CaptureScreenRegionA(xvalue, yvalue, width, height);
            var formatF = ImageFormat.Jpeg;
            if (format == 1) { formatF = ImageFormat.Bmp; }
            else if (format == 2) { formatF = ImageFormat.Emf; }
            else if (format == 3) { formatF = ImageFormat.Exif; }
            else if (format == 4) { formatF = ImageFormat.Gif; }
            else if (format == 5) { formatF = ImageFormat.Icon; }
            else if (format == 6) { formatF = ImageFormat.Jpeg; }
            else if (format == 7) { formatF = ImageFormat.Png; }
            else if (format == 8) { formatF = ImageFormat.Tiff; }
            else if (format == 9) { formatF = ImageFormat.Wmf; }
            img.Save(filename, formatF);
        }
    }
}
Parsed in 0.033 seconds, using GeSHi 1.0.8.9


--IMAGE FORMATS:
IMAGE_BMP       = 1;
IMAGE_EMF       = 2;
IMAGE_EXIF      = 3;
IMAGE_GIF       = 4;
IMAGE_ICON      = 5;
IMAGE_JPEG      = 6;
IMAGE_PNG       = 7;
IMAGE_TIFF      = 8;
IMAGE_WMF       = 9;

-- CAPTUREWINDOW
handle = Application.GetWndHandle();
filename = _SourceFolder.."\\Autoplay\\Images\\Sample"..Math.Random(0, 999)..".png"
format = IMAGE_PNG

local args = handle..",\""..filename.."\","..format
local DllFile = _SourceFolder.."\\AutoPlay\\Docs\\CaptureGDIDLL.dll"
DLL.CallFunction(DllFile, "CaptureWindow", args, DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);

-- CAPTURESCREEN
filename = _SourceFolder.."\\Autoplay\\Images\\Sample"..Math.Random(0, 999)..".bmp"
format = IMAGE_BMP;

local args = "\""..filename.."\","..format
local DllFile = _SourceFolder.."\\AutoPlay\\Docs\\CaptureGDIDLL.dll"
DLL.CallFunction(DllFile, "CaptureScreen", args, DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);

-- CAPTUREWINDOWREGION
handle = Application.GetWndHandle();
filename = _SourceFolder.."\\Autoplay\\Images\\Sample"..Math.Random(0, 999)..".gif"
fomat = IMAGE_GIF
xvalue = 10
yvalue = 10
width = 100
height = 100

DLL.CallFunction("AutoPlay\\Docs\\CaptureGDIDLL.dll", "CaptureWindowRegion", handle..",\""..filename.."\","..format..","..xvalue..","..yvalue..","..width..","..height, DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);

-- CAPTURESCREENREGION
filename = _SourceFolder.."\\Autoplay\\Images\\Sample"..Math.Random(0, 999)..".jpg"
fomat = IMAGE_JPEG
xvalue = 10
yvalue = 10
width = 400
height = 400

local args = "\""..filename.."\","..format..","..xvalue..","..yvalue..","..width..","..height
local DllFile = _SourceFolder.."\\AutoPlay\\Docs\\CaptureGDIDLL.dll"
DLL.CallFunction(DllFile, "CaptureScreenRegion", args, DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);
Parsed in 0.006 seconds, using GeSHi 1.0.8.9


Descarga:
Contenido Oculto: ON
	<br />Usted necesita responder en este tema para ver el contenido oculto.
genial amigo esto me sera de mucha ayuda en mi software.
Imagen
MUCHAS GRACIAS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<div>
algunas cosas del codigo se pueden mejorar pero bueno por ahora ira bien... creo yo!
thanx ceone
ya me diréis si detectáis algún fallo...
good :yes:
Imagen
thanks
grazie paharo!
he puesto una duda referente a esta dll amigo aquí espero me des una mano viewtopic.php?f=3&t=721
Imagen
wooow cool
... thanks
???
thank yu ....cione
very good .. thanks
Thank yoou
Imagen
thank
Thank you!
EDIT: can someone please post another link other than multiupload :SOS:
I would love to use this but I get this:

---------------------------
Error
---------------------------
Failed to find the specified function within the DLL.
---------------------------
OK
---------------------------

Any ideas ?
wow thanks, by the way the file did not exist anymore (removed by depositfile) re Upload please.... Ceone..
35 mensajes Página 1 de 2

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 2 invitados

cron