C#, 인터넷 익스플로러 핸들 잡아서 컨트롤 하기.
1. 프로젝트 참조에서 Microsoft Internet Controls 추가하기.
2. DllImport 사용하기 위해서. using System.Runtime.InteropServices; 구문 추가
3. 소스 시작. 텍스트박스에 입력된 문구가 들어있는 익스플로러 창을 찾아서 위치 크기 설정하는 소스.
namespace 윈도우핸들사이즈조정
{
public partial class Form1 : Form
{
[DllImport("user32.dll", SetLastError = true)]
static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int Width, int Height, bool Repaint);
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
foreach (SHDocVw.InternetExplorer ieInst in new SHDocVw.ShellWindowsClass())
{
String url = ieInst.LocationURL;
if (url.Contains(textBox5.Text))
{
int val = ieInst.HWND;
IntPtr handle = new IntPtr(val);
MoveWindow(handle, int.Parse(textBox1.Text), int.Parse(textBox2.Text), int.Parse(textBox3.Text), int.Parse(textBox4.Text), true);
}
}
}
}
}