久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

C#截取 當(dāng)前桌面的活動(dòng)窗體圖像

 Jcstone 2012-06-13
C# code
using System; 
using System.Text;
using System.Collections;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;

namespace GDBranchPlatDLP
{
/// <summary>
/// clsCaptureDesktop 的摘要說明。
/// </summary>
public class clsCaptureDesktop
{

[System.Runtime.InteropServices.DllImport("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, //目標(biāo)設(shè)備的句柄
int nXDest, //目標(biāo)對像的左上角的X坐標(biāo)
int nYDest, //目標(biāo)對象的左上角的Y坐標(biāo)
int nWidth, //目標(biāo)對象的矩形的寬度
int nHeight, //目標(biāo)對象的矩形的長度
IntPtr hdcSrc, //源設(shè)備的句柄
int nXSrc, //源對像的左上角的X坐標(biāo)
int nYSrc, //源對象的左上角的Yw坐標(biāo)
System.Int32 dwRop //光柵的操作值
);
[System.Runtime.InteropServices.DllImport("gdi32.dll")]
private static extern IntPtr CreateDC(
string lpszDriver, // 驅(qū)動(dòng)名稱
string lpszDevice, // 設(shè)備名稱
string lpszOutput, // 無用,,可以設(shè)定位"NULL"
IntPtr lpInitData // 任意的打印機(jī)數(shù)據(jù)
);

public Bitmap Capture(Size size)
{
Bitmap bmpDeskTop = null;

ArrayList arryHideWidow=new ArrayList();        //記錄隱藏的窗體,,以便恢復(fù)過來
foreach(Window w in new Windows())  //枚舉所有窗體
{
arryHideWidow.Add(w);
w.Visible=false;  //隱藏所有窗口(包括活動(dòng)的和非活動(dòng)的)
}

try
{
IntPtr dc1=CreateDC("DISPLAY",null,null,(IntPtr)null);
//創(chuàng)建顯示器的DC
Graphics g1=Graphics.FromHdc(dc1);
//由一個(gè)指定的設(shè)備的句柄創(chuàng)建一個(gè)新的Graphics對象
bmpDeskTop = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height,g1);
//根據(jù)屏幕大小創(chuàng)建一個(gè)與之相同大小的Bitmap對象
Graphics g2=Graphics.FromImage(bmpDeskTop);
//獲得屏幕的句柄
IntPtr dc3=g1.GetHdc();
//獲得位圖的句柄
IntPtr dc2=g2.GetHdc();
//把當(dāng)前屏幕捕獲到位圖對象中
BitBlt(dc2,0,0,Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height,dc3,0,0,13369376);
//把當(dāng)前屏幕拷貝到位圖中
g1.ReleaseHdc(dc3);
//釋放屏幕句柄
g2.ReleaseHdc(dc2);

g1.Dispose();
g2.Dispose();
}
catch
{
}
//釋放位圖句柄
foreach(Window w in arryHideWidow)
{
w.Visible=true; //恢復(fù)隱藏的窗口
}

Bitmap bmpRet=new Bitmap(bmpDeskTop,size);
bmpDeskTop.Dispose();
bmpDeskTop=null;

return bmpRet;
}

public clsCaptureDesktop()
{
//
// TODO: 在此處添加構(gòu)造函數(shù)邏輯
//
}


}


public class Window
{
///

/// Win32 API Imports

///

[DllImport("user32.dll")] private static extern
bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")] private static extern
bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")] private static extern
bool IsIconic(IntPtr hWnd);
[DllImport("user32.dll")] private static extern
bool IsZoomed(IntPtr hWnd);
[DllImport("user32.dll")] private static extern
IntPtr GetForegroundWindow();
[DllImport("user32.dll")] private static extern
IntPtr GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
[DllImport("user32.dll")] private static extern
IntPtr AttachThreadInput(IntPtr idAttach, IntPtr idAttachTo, int fAttach);

///

/// Win32 API Constants for ShowWindowAsync()

///

private const int SW_HIDE = 0;
private const int SW_SHOWNORMAL = 1;
private const int SW_SHOWMINIMIZED = 2;
private const int SW_SHOWMAXIMIZED = 3;
private const int SW_SHOWNOACTIVATE = 4;
private const int SW_RESTORE = 9;
private const int SW_SHOWDEFAULT = 10;

///

/// Private Fields

///

private IntPtr m_hWnd;
private string m_Title;
private bool m_Visible = true;
private string m_Process;
private bool m_WasMax = false;

///

/// Window Object's Public Properties

///

public IntPtr hWnd
{
get{return m_hWnd;}
}
public string Title
{
get{return m_Title;}
}
public string Process
{
get{return m_Process;}
}

///

/// Sets this Window Object's visibility

///

public bool Visible
{
get{return m_Visible;}
set
{
//show the window

if(value == true)
{
if(m_WasMax)
{
if(ShowWindowAsync(m_hWnd,SW_SHOWMAXIMIZED))
m_Visible = true;
}
else
{
if(ShowWindowAsync(m_hWnd,SW_SHOWNORMAL))
m_Visible = true;
}
}
//hide the window

if(value == false)
{
m_WasMax = IsZoomed(m_hWnd);
if(ShowWindowAsync(m_hWnd,SW_HIDE))
m_Visible = false;
}
}
}

///

/// Constructs a Window Object

///

/// Title Caption

/// Handle

/// Owning Process

public Window(string Title, IntPtr hWnd, string Process)
{
m_Title = Title;
m_hWnd = hWnd;
m_Process = Process;
}

//Override ToString()

public override string ToString()
{
//return the title if it has one, if not return the process name

if (m_Title.Length > 0)
{
return m_Title;
}
else
{
return m_Process;
}
}

///

/// Sets focus to this Window Object

///

public void Activate()
{
if(m_hWnd == GetForegroundWindow())
return;

IntPtr ThreadID1 = GetWindowThreadProcessId(GetForegroundWindow(),
IntPtr.Zero);
IntPtr ThreadID2 = GetWindowThreadProcessId(m_hWnd,IntPtr.Zero);
           
if (ThreadID1 != ThreadID2)
{
AttachThreadInput(ThreadID1,ThreadID2,1);
SetForegroundWindow(m_hWnd);
AttachThreadInput(ThreadID1,ThreadID2,0);
}
else
{
SetForegroundWindow(m_hWnd);
}

if (IsIconic(m_hWnd))
{
ShowWindowAsync(m_hWnd,SW_RESTORE);
}
else
{
ShowWindowAsync(m_hWnd,SW_SHOWNORMAL);
}
}
}

///

/// Collection used to enumerate Window Objects

///

public class Windows : IEnumerable, IEnumerator
{
///

/// Win32 API Imports

///

[DllImport("user32.dll")] private static extern
int GetWindowText(int hWnd, StringBuilder title, int size);
[DllImport("user32.dll")] private static extern
int GetWindowModuleFileName(int hWnd, StringBuilder title, int size);
[DllImport("user32.dll")] private static extern
int EnumWindows(EnumWindowsProc ewp, int lParam);
[DllImport("user32.dll")] private static extern
bool IsWindowVisible(int hWnd);

//delegate used for EnumWindows() callback function

public delegate bool EnumWindowsProc(int hWnd, int lParam);

private int m_Position = -1; // holds current index of wndArray,

// necessary for IEnumerable

       
ArrayList wndArray = new ArrayList(); //array of windows

       
//Object's private fields

private bool m_invisible = false;
private bool m_notitle = false;

///

/// Collection Constructor with additional options

///

/// Include invisible Windows

/// Include untitled Windows

public Windows(bool Invisible, bool Untitled)
{
m_invisible = Invisible;
m_notitle = Untitled;

//Declare a callback delegate for EnumWindows() API call

EnumWindowsProc ewp = new EnumWindowsProc(EvalWindow);
//Enumerate all Windows

EnumWindows(ewp, 0);
}
///

/// Collection Constructor

///

public Windows()
{
//Declare a callback delegate for EnumWindows() API call

EnumWindowsProc ewp = new EnumWindowsProc(EvalWindow);
//Enumerate all Windows

EnumWindows(ewp, 0);
}
//EnumWindows CALLBACK function

private bool EvalWindow(int hWnd, int lParam)
{
if (m_invisible == false && !IsWindowVisible(hWnd))
return(true);

StringBuilder title = new StringBuilder(256);
StringBuilder module = new StringBuilder(256);

GetWindowModuleFileName(hWnd, module, 256);
GetWindowText(hWnd, title, 256);

if (m_notitle == false && title.Length == 0)
return(true);

wndArray.Add(new Window(title.ToString(), (IntPtr)hWnd,
module.ToString()));

return(true);
}
       
//implement IEnumerable

public IEnumerator GetEnumerator()
{
return (IEnumerator)this;
}
//implement IEnumerator

public bool MoveNext()
{
m_Position++;
if (m_Position < wndArray.Count)
{
return true;
}
else
{
return false;
}
}
public void Reset()
{
m_Position = -1;
}
public object Current
{
get
{
return wndArray[m_Position];
}
}
}
}




這段代碼是抓取桌面圖像的,,你可以參考一下,,把不是活動(dòng)窗口隱藏,,活動(dòng)窗口不隱藏,,應(yīng)該可以實(shí)現(xiàn)你的需求

調(diào)用clsCaptureDesktop類的Capture方法

    本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲(chǔ)空間,,所有內(nèi)容均由用戶發(fā)布,,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購買等信息,,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請點(diǎn)擊一鍵舉報(bào),。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多