求 C# 获得另外一程序 句柄 后控制该程序,如控制其透明,或窗体大小等(求代码) 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 估计要调用 WINDOWS API了 都是些API调用,参考如下代码:using System.Runtime.InteropServices;[DllImport("user32.dll")]private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);[DllImport("user32.dll")]private static extern int GetWindowLong(IntPtr hWnd, int nIndex);[DllImport("user32.dll")]public static extern IntPtr FindWindow(string lpszClass, string lpszWindow);[DllImport("user32.dll")]public static extern bool SetLayeredWindowAttributes( IntPtr hWnd, int crKey, byte bAlpha, int dwFlags);[DllImport("user32.dll")]public static extern bool RedrawWindow(IntPtr hWnd, IntPtr lprcUpdate, IntPtr hrgnUpdate, uint flags);public const int GWL_EXSTYLE = -20;public const int WS_EX_LAYERED = 0x00080000;public const int LWA_ALPHA = 0x00000002;public const int RDW_INVALIDATE = 1;public const int RDW_ERASE = 4;public const int RDW_ALLCHILDREN = 0x80;public const int RDW_FRAME = 0x400;private void button1_Click(object sender, EventArgs e){ //设置透明 IntPtr vHandle = FindWindow("Notepad", null); // 这里换成你获得的窗体句柄,测试的时候可以用记事本。 SetWindowLong(vHandle, GWL_EXSTYLE, GetWindowLong(vHandle, GWL_EXSTYLE) | WS_EX_LAYERED); SetLayeredWindowAttributes(vHandle, 0, 255 / 2/*透明度*/, LWA_ALPHA); }private void button2_Click(object sender, EventArgs e){ //恢复 IntPtr vHandle = FindWindow("Notepad", null); SetWindowLong(vHandle, GWL_EXSTYLE, GetWindowLong(vHandle, GWL_EXSTYLE) & ~WS_EX_LAYERED); RedrawWindow(vHandle, IntPtr.Zero, IntPtr.Zero, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);}[DllImport("user32.dll")]public static extern bool MoveWindow( IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);private void button3_Click(object sender, EventArgs e){ //改变窗体大小和位置 IntPtr vHandle = FindWindow("Notepad", null); MoveWindow(vHandle, 20, 20, 200, 200, true);} 跪求C#的Application.StartupPath和System.Environment.CurrentDirectory的区别 RDLC多层钻取方法 关于后台侦听 能够帮忙吗? DATAGRID怎么让记录多种颜色显示? debug问题 C#编程时,在FTP中中文问题如何解决 求:C# Web服务高级编程源代码 为什么文件没有被下载?!急 昨天被人性骚扰了!!!不知道该怎么办,大家帮我出个主意,散分!!! [求助]请问如何写好代码? 新建项目--Visual C#--模板处空白
using System.Runtime.InteropServices;[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll")]
private static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpszClass, string lpszWindow);
[DllImport("user32.dll")]
public static extern bool SetLayeredWindowAttributes(
IntPtr hWnd, int crKey, byte bAlpha, int dwFlags);
[DllImport("user32.dll")]
public static extern bool RedrawWindow(IntPtr hWnd, IntPtr lprcUpdate,
IntPtr hrgnUpdate, uint flags);public const int GWL_EXSTYLE = -20;
public const int WS_EX_LAYERED = 0x00080000;
public const int LWA_ALPHA = 0x00000002;
public const int RDW_INVALIDATE = 1;
public const int RDW_ERASE = 4;
public const int RDW_ALLCHILDREN = 0x80;
public const int RDW_FRAME = 0x400;private void button1_Click(object sender, EventArgs e)
{
//设置透明
IntPtr vHandle = FindWindow("Notepad", null); // 这里换成你获得的窗体句柄,测试的时候可以用记事本。
SetWindowLong(vHandle, GWL_EXSTYLE,
GetWindowLong(vHandle, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(vHandle, 0, 255 / 2/*透明度*/, LWA_ALPHA);
}private void button2_Click(object sender, EventArgs e)
{
//恢复
IntPtr vHandle = FindWindow("Notepad", null);
SetWindowLong(vHandle, GWL_EXSTYLE,
GetWindowLong(vHandle, GWL_EXSTYLE) & ~WS_EX_LAYERED);
RedrawWindow(vHandle, IntPtr.Zero, IntPtr.Zero,
RDW_ERASE | RDW_INVALIDATE | RDW_FRAME | RDW_ALLCHILDREN);
}[DllImport("user32.dll")]
public static extern bool MoveWindow(
IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);private void button3_Click(object sender, EventArgs e)
{
//改变窗体大小和位置
IntPtr vHandle = FindWindow("Notepad", null);
MoveWindow(vHandle, 20, 20, 200, 200, true);
}