操作别的窗体
2015-04-28 07:56:17 访问(2100) 赞(0) 踩(0)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace Other_windows_interaction_in_CSharp
{
public partial class Form1 : Form
{
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern IntPtr WindowFromPoint(int xPoint, int yPoint);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern bool SetWindowText(IntPtr hWnd, string lpString);
[DllImport("user32.dll", SetLastError = true)]
static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
static extern bool EnableWindow(IntPtr hWnd, bool bEnable);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
txtHwnd.Text = FindWindow(null, txtTitle.Text).ToString();
}
private void button2_Click(object sender, EventArgs e)
{
txtHwnd.Text = FindWindow(txtClass.Text, null).ToString();
}
private void button3_Click(object sender, EventArgs e)
{
int x = Int32.Parse(txtX.Text);
int y = Int32.Parse(txtY.Text);
txtHwnd.Text = WindowFromPoint(x, y).ToString();
}
private void btnSetText_Click(object sender, EventArgs e)
{
var hWnd = new IntPtr(Int32.Parse(txtHwnd.Text));
SetWindowText(hWnd, txtSetText.Text);
}
private void btnMove_Click(object sender, EventArgs e)
{
var hWnd = new IntPtr(Int32.Parse(txtHwnd.Text));
var x = Int32.Parse(txtMoveX.Text);
var y = Int32.Parse(txtMoveY.Text);
var w = Int32.Parse(txtMoveW.Text);
var h = Int32.Parse(txtMoveH.Text);
MoveWindow(hWnd, x, y, w, h, true);
}
private void button4_Click(object sender, EventArgs e)
{
var hWnd = new IntPtr(Int32.Parse(txtHwnd.Text));
SetForegroundWindow(hWnd);
}
private void buttonEna_Click(object sender, EventArgs e)
{
var hWnd = new IntPtr(Int32.Parse(txtHwnd.Text));
EnableWindow(hWnd, chkEna.Checked);
}
}
}
标签:
操作别的窗体 


上一条:
下一条:
相关评论
发表评论