C# api调用,上窗口在最上面,模拟键盘

摘要:
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Runtime.InteropServices;//闫磊namespace

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices; //闫磊

namespace Api
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//闫磊加入
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImport("user32.dll")]
private static extern bool SetCursorPos(int X, int Y);
[DllImport("user32.dll")]
private static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
[DllImport("user32.dll")]
private static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
[DllImport("user32.dll")]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndlnsertAfter, int X, int Y, int cx, int cy, uint Flags);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

[System.Runtime.InteropServices.DllImport("user32", EntryPoint = "SetForegroundWindow")]
public static extern bool SetFocus(IntPtr hWnd);//设置此窗体为活动窗体

private void button1_Click(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{

IntPtr myIntPtr = FindWindow(null, "gisoracle的专栏 - CSDN博客 - Windows Internet Explorer");
//ShowWindow(myIntPtr, SW_RESTORE); //将窗口还原
SetWindowPos(myIntPtr, (IntPtr)(-1), 100, 200, 0, 0, 0x0040 | 0x0001); //放在最前面
SendKeys.Send("{F5}");

//SetParent(myIntPtr, this.Handle);
// SetFocus(myIntPtr);
}

private void timer1_Tick(object sender, EventArgs e)
{
IntPtr myIntPtr = FindWindow(null, "gisoracle的专栏 - CSDN博客 - Windows Internet Explorer");
//ShowWindow(myIntPtr, SW_RESTORE); //将窗口还原
SetWindowPos(myIntPtr, (IntPtr)(-1), 100, 200, 0, 0, 0x0040 | 0x0001); //放在最前面
SendKeys.Send("{F5}");

//SetParent(myIntPtr, this.Handle);
// SetFocus(myIntPtr);

}
}
}

免责声明:文章转载自《C# api调用,上窗口在最上面,模拟键盘》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇GPIO常用操作【JVM】CPU飙升问题下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

C# 弹出层移动

 groupPrint.MouseDown += GroupBox1_MouseDown; #region 弹出层移动        [System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint = "ReleaseCapture")]        public static ext...

C 函数

C函数 函数是一组一起执行一个任务的语句。每个 C 程序都至少有一个函数,即主函数main(),所有简单的程序都可以定义其他额外的函数。 您可以把代码划分到不同的函数中。如何划分代码到不同的函数中是由您来决定的,但在逻辑上,划分通常是根据每个函数执行一个特定的任务来进行的。 函数声明告诉编译器函数的名称、返回类型和参数。函数定义提供了函数的实际主体。 C...

cJSON 使用详解

由于c语言中,没有直接的字典,字符串数组等数据结构,所以要借助结构体定义,处理json。如果有对应的数据结构就方便一些, 如python中用json.loads(json)就把json字符串转变为内建的数据结构处理起来比较方便。     cjson库文件下载:     sourceforge地址     一个重要概念:         在cjson中,js...

__declspec的15种用法

__cdecl和__stdcall都是函数调用规范(还有一个__fastcall),规定了参数出入栈的顺序和方法,如果只用VC编程的话可以不用关心,但是要在C++和Pascal等其他语言通信的时候就要注意了,只有用相同的方法才能够调用成功.另外,像printf这样接受可变个数参数的函数只有用cdecl才能够实现.__declspec主要是用于说明DLL的引...

BitBlt 函数 详解, StretchBlt、SetStretchBltMode、SetBrushOrgEx 按句柄截图、直接截取缩略图

BitBlt 该函数对指定的源设备环境区域中的像素进行位块(bit_block)转换,以传送到目标设备环境。 函数原型 [DllImport("gdi32.dll")] public static extern bool BitBlt(IntPtr hObject, int nXDest, intnY...

日记:VB调用C++ DLL注意事项

1. DLL的接口必须在.def中声明,否则VB无法调用。根据已有资料,.def文件完成的作用是与extern "C"相同,也就是说如果在接口定义的头文件中使用了extern "C",则不需要在.def中声明。在实际中,供C++、C#和Java调用的DLL都只需要使用extern "C"来声明接口即可,VB应属一个特例,具体原因尚不清楚。 2. VB声明原...