본문 바로가기

C Sharp

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);

                }
            }
        }
    }
}


반응형

'C Sharp' 카테고리의 다른 글

[C#] XML 파일 작성 예제  (0) 2018.10.10
C# 으로 키움증권 시스템 트레이딩에 도전하다.  (0) 2016.03.04
C# Queue 사용 예제.  (2) 2015.05.04
C# HashTable 사용 예제.  (0) 2015.05.04
C# ArrayList 사용예제.  (0) 2015.05.04