zoukankan      html  css  js  c++  java
  • C# 获取桌面

                  

     [System.Runtime.InteropServices.DllImport(”gdi32.dll”)]
    
            public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, UInt32 dwRop);
    
          //创建桌面句柄
    
            [System.Runtime.InteropServices.DllImportAttribute(”gdi32.dll”)]
    
            public static extern IntPtr CreateDC(string lpszDriver, string lpszDevice, string lpszOutput, int lpInitData);
    
            [System.Runtime.InteropServices.DllImport(”gdi32.dll”)]
    
            public static extern IntPtr CreateCompatibleDC(IntPtr hdc);
    
            //转换为本地的图像资源
    
            [System.Runtime.InteropServices.DllImport(”gdi32.dll”)]
    
            public static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
    
            [System.Runtime.InteropServices.DllImport(”gdi32.dll”)]
    
            public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj);
    
            [System.Runtime.InteropServices.DllImport(”gdi32.dll”)]
    
            public static extern int DeleteDC(IntPtr hdc);
    
            //释放用过的设备句柄
    
            [DllImport(”user32.dll”)]
    
            public static extern bool ReleaseDC(
    
             IntPtr hwnd, IntPtr hdc
    
             );
    
            //释放用过的画笔等资源
    
            [DllImport(”gdi32.dll”)]
    
            public static extern bool DeleteObject(
    
              IntPtr hdc
    
             );
    
            
    
    /// <summary>
    
            /// 截取屏幕图像
    
            /// </summary>
    
            /// <param name=”Width”>宽</param>
    
            /// <param name=”Height”>高</param>
    
            /// <param name=”x”>x坐标(全屏时候为0)</param>
    
            /// <param name=”y”>y坐标(全屏时候为0)</param>
    
            /// <returns></returns>
    
            public Bitmap fullphoto(int Width,int Height,int x,int y)
    
            {
    
                Bitmap bitmap;
    
                //try
    
                //{
    
                    IntPtr hScreenDc = CreateDC(”DISPLAY”, null, null, 0); // 创建桌面句柄
    
                    IntPtr hMemDc = CreateCompatibleDC(hScreenDc); // 创建与桌面句柄相关连的内存DC
    
                    IntPtr hBitmap = CreateCompatibleBitmap(hScreenDc, Width, Height);   
    
                    IntPtr hOldBitmap = SelectObject(hMemDc, hBitmap);
    
                    BitBlt(hMemDc, x, y, Width, Height, hScreenDc, x, y, (UInt32)0xcc0020);
    
                    IntPtr map = SelectObject(hMemDc, hOldBitmap);
    
                    bitmap = Bitmap.FromHbitmap(map);  
    
                    ReleaseDC(hBitmap, hScreenDc);
    
                    DeleteDC(hScreenDc);//删除用过的对象
    
                    DeleteDC(hMemDc);//删除用过的对象
    
                    DeleteDC(hOldBitmap);
    
                    DeleteObject(hBitmap);
    
                   
    
                  
    
                //}
    
                //catch (Exception wx)
    
                //{
    
                //    return null;
    
                    //}
    
                    // number= number +1;
    
                    // bitmap.Save(”screen” + number + “.bmp”);
    
                
    
                return bitmap;
    
            }
    

           

  • 相关阅读:
    MongDB in Rails 3 using mongo_mapper
    Cucumber + Capybara What we need for rails integration test
    HTML5 drag & drop 拖拽与拖放简介
    Installing GitLab 2.1 on Centos 6
    CakePHP的belongsTo关系中关于外键关联字段都不是id字段的问题
    Mod_rewrite in Cakephp using Apache
    How to Configure Static IP Address on CentOS 6.3 Linux Server
    mongoDB 入门指南、示例
    MVC3/4项目开发中遇到的ajax提交Json数据到后台Controller处理(接收参数)
    ASP.NET jQuery (表单中使用回车在TextBox之间向下移动)
  • 原文地址:https://www.cnblogs.com/DotNetCSharp/p/2116574.html
Copyright © 2011-2022 走看看