[DllImport(“user32.dll”)]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
[DllImport(“user32.dll”)]
static extern byte MapVirtualKey(byte wCode, int wMap);
[DllImport(“user32.dll”)]
static extern IntPtr FindWindow(string strClass, string strWindow);
[DllImport(“user32.dll”)]
private static extern IntPtr GetForegroundWindow();
[DllImport(“user32.dll”, EntryPoint = “SetForegroundWindow”, SetLastError = true)]
private static extern void SetForegroundWindow(IntPtr hwnd);
[DllImport(“user32.dll”, CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
private void ShowVideo()
{
//keybd_event(18, MapVirtualKey(18, 0), 0, 0); //按下CTRL鍵。
while (true)
{
Thread.Sleep(100);
//获取目标窗口句柄
//可以通过工具中Spy++获得
IntPtr ptrTaskbar = FindWindow("ZPContentViewWndClass", "Zoom");//"ZPContentViewWndClass"
if (ptrTaskbar != IntPtr.Zero)
{
//获取当前窗口句柄
IntPtr ptrCc = GetForegroundWindow();
if (ptrCc == ptrTaskbar)
{
//模拟按键
keybd_event(18, MapVirtualKey(18, 0), 0, 0); //按下alt鍵。
keybd_event(86, MapVirtualKey(70, 0), 0, 0);//鍵下v鍵。
keybd_event(86, MapVirtualKey(70, 0), 0x2, 0);//放開v鍵。 0x35
// Thread.Sleep(Convert.ToInt32(10 * 1000));//开起程序后等待
keybd_event(18, MapVirtualKey(18, 0), 0x2, 0);//放開alt鍵。
//MessageBox.Show("as");
//this.WindowState = WindowState.Maximized;
//SetForegroundWindow(ptrTaskbar);
//SendMessage(mainHandle, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
ShowWindow(ptrTaskbar, 3);//窗口最大化
return;
}
//MessageBox.Show("1111");
}
else
{
//MessageBox.Show("没有");
}
ptrTaskbar = IntPtr.Zero;
}
Thread.Sleep(20000);
Console.WriteLine("222222");
keybd_event(18, MapVirtualKey(18, 0), 0, 0); //按下alt鍵。
keybd_event(86, MapVirtualKey(70, 0), 0, 0);//鍵下v鍵。
keybd_event(86, MapVirtualKey(70, 0), 0x2, 0);//放開v鍵。 0x35
//Thread.Sleep(Convert.ToInt32(10 * 1000));//开起程序后等待
keybd_event(18, MapVirtualKey(18, 0), 0x2, 0);//放開alt鍵。
//MessageBox.Show("111111111111");
//Process cur = Process.GetCurrentProcess();
////当前进程的id
//Console.WriteLine(cur.Id);
////获取关联的进程的终端服务会话标识符。
//Console.WriteLine(cur.SessionId);
////当前进程的名称
//Console.WriteLine(cur.ProcessName);
////当前进程的启动时间
//Console.WriteLine(cur.StartTime);
////获取关联进程终止时指定的值,在退出事件中使用
////Console.WriteLine(cur.ExitCode);
////获取进程的当前机器名称
//Console.WriteLine(cur.MachineName); //.代表本地
// //获取进程的主窗口标题。
//Console.WriteLine(cur.MainWindowTitle);
}