110,534
社区成员
发帖
与我相关
我的任务
分享
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow(string strclassName, string strWindowText);
[DllImport("user32.dll")]
public static extern IntPtr GetWindowDC( IntPtr hwnd );
[DllImport("user32.dll")]
public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("gdi32.dll")]
public static extern int BitBlt(
IntPtr hdcDest, // handle to destination DC目标设备的句柄
int nXDest, // x-coord of destination upper-left corner目标对象的左上角的X坐标
int nYDest, // y-coord of destination upper-left corner目标对象的左上角的Y坐标
int nWidth, // width of destination rectangle目标对象的矩形宽度
int nHeight, // height of destination rectangle目标对象的矩形长度
IntPtr hdcSrc, // handle to source DC源设备的句柄
int nXSrc, // x-coordinate of source upper-left corner源对象的左上角的X坐标
int nYSrc, // y-coordinate of source upper-left corner源对象的左上角的Y坐标
UInt32 dwRop // raster operation code光栅的操作值
);
private const uint SRCCOPY = (uint)0xCC0020;//光栅操作码:复制
hWndSrcForm = FindWindow(strWindowClassName, null);//获取待捕捉窗口句柄
IntPtr hdcSrc = Form1.GetWindowDC(hWndSrcForm);//创建待捕获窗口的设备上下文(绘图句柄)
//RECT windowRect = new Form1.RECT();
//Form1.GetWindowRect(hWndSrcForm, ref windowRect);//获取待捕获窗口大小,含非客户区
//int width = windowRect.right - windowRect.left; //此处不能这样做,应根据测试直接在BitBle函数中赋值
//int height = windowRect.bottom - windowRect.top;
IntPtr handle = this.Handle; //
IntPtr hdDesForm = this.CreateGraphics().GetHdc();
//this.lblLocHandle.Text = handle.ToString();
//this.lblLocDC.Text = hdDesForm.ToString();
//this.lblSrcHandle.Text = hWndSrcForm.ToString();
//this.lblSrcDC.Text = hdcSrc.ToString();
//this.lblClass.Text = Settings.Default.WindowClassName;
Form1.BitBlt(hdDesForm, 100, 100, 250, 65, hdcSrc, 40, 40, Form1.SRCCOPY);//将源DC中的指定位置和大小的图像复制到目标DC
Form1.ReleaseDC(handle, hdDesForm);
Form1.ReleaseDC(hWndSrcForm, hdcSrc);
hWndSrcForm = FindWindow(strWindowClassName, null);//获取待捕捉窗口句柄
Process[] locAllProcess = Process.GetProcessesByName(Settings.Default.AppName);
string strMainWindowTitle = locAllProcess[0].MainWindowTitle;
hWndSrcForm = FindWindow(null, strMainWindowTitle);//获取待捕捉窗口句柄