๊ฐํน ๊ฐ๋ฐ์ ํ๋ค๋ณด๋ฉด ์ธ๋ถ ์์ฉํ๋ก๊ทธ๋จ์ ์ฐ๊ณํ๊ฑฐ๋ ์ ์ดํด์ผํ ์ผ์ด ์๋ค.
์ผ๋ฐ์ ์ผ๋ก ๋ณธ์ธ์ด ๋ง๋ (์์ค๊ฐ ์๋) ํ๋ก๊ทธ๋จ์ด๋ผ๋ฉด ์์ฝ๊ฒ ์ง๋ง ์๋๊ฒฝ์ฐ๊ฐ ๋๋ถ๋ถ์ด๋ค.
๊ทธ๋ด๋๋ Window Message๋ฅผ ์ด์ฉํ์ฌ ๋ค๋ฅธ ์์ฉํ๋ก๊ทธ๋จ์ ์ ์ดํ ์ ์๋ค.
๋ชจ๋ ์๋์ฐ ์์ฉํ๋ก๊ทธ๋จ์ ์๋์ฐ์ฆ ์์์ ๋์ํ๊ธฐ๋๋ฌธ์ ๊ณตํต๋ ๋ฉ์์ง๋ฅผ ์ด์ฉํ์ฌ ์ ์ดํ๋ ๋ฐฉ๋ฒ์ด๋ค.
์์
๋ค์์ ๊ณ์ฐ๊ธฐ ์์ฉํ๋ก๊ทธ๋จ์ ํธ๋ค์ ์ฐพ์์ ํด๋น ํธ๋ค์ ๋ฉ์์ง๋ฅผ ๋ณด๋ด๋ ์์ ์ด๋ค.
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 WindowsApplication1
{
public partial class Form1 : Form
{
//์ฌ์ฉํ APIํจ์๋ฅผ ์ํฌํธ ํ๋ค.
[DllImport("USER32.DLL")]
public static extern uint FindWindow(string lpClassName,
string lpWindowName);
[DllImport("user32.dll")]
public static extern uint FindWindowEx(uint hWnd1, uint hWnd2, string lpsz1, string lpsz2);
[DllImport("user32.dll")]
public static extern uint SendMessage(uint hwnd, uint wMsg, uint wParam, uint lParam);
[DllImport("user32.dll")]
public static extern uint PostMessage(uint hwnd, uint wMsg, uint wParam, uint lParam);
uint handle;
private void button3_Click(object sender, EventArgs e)
{
//ํธ๋ค์ ์ฐพ๋๋ค. Spy+๋ฅผ ํตํด ์ฐพ์ ํด๋์ค ์ด๋ฆ๊ณผ ์บก์
์ ์ด์ฉํ๋ฉด ๋๋ค. ๋ ์ค ํ๋๋ง ์๊ฒฝ์ฐ์๋ ์ฐพ์ ์ ์๋ค. ๊ทธ๋๋ ํ๋์ ์ธ์๋ฅผ null๋ก ๋๊ฒจ ์ฃผ๋ฉด๋๋ค.
handle = FindWindow("SciCalc", "๊ณ์ฐ๊ธฐ");
//์ฐพ์ ํธ๋ค์์ ์์ ์๋์ฐ ํธ๋ค์ ์ฐพ๊ธฐ ์ํด์๋ FindWindowEx๋ฅผ ์ด์ฉํ๋ค.
handle = FindWindowEx(handle, 0, "Shell DocObject View", null);
handle = FindWindowEx(handle, 0, "Internet Explorer_Server", null);
label1.Text = handle.ToString();
}
private void button1_Click(object sender, EventArgs e)
{
//์ฐพ์ ํธ๋ค์ ํตํด ๋ฉ์ธ์ง๋ฅผ ๋ณด๋ธ๋ค. ์ฌ๊ธฐ์๋ ์๋ 16์ง์๋ค ์ ๊ฐ์ ์คํ์ด ๋ฉ์ธ์ง ๋ก๊ทธ์์ ์ฐพ์ ๊ฐ์ ์ด์ฉํ๋ฉด ๋๋ค. ์ฌ๊ธฐ์๋ ํค๋ฅผ ๋๋ฅธ ๋ฉ์ธ์ง(ํญํค๋๋ฅธํ ์ํฐํค๋ฅผ ๋๋ฅธ๋ค.)๋ฅผ ๋ณด๋ด๋ ์์ ์ด๋ค.
PostMessage(handle, 0x0100, 0x9, 0xF0001);
PostMessage(handle, 0x0101, 0x9, 0xC00F0001);
PostMessage(handle, 0x0100, 0xD, 0x1C001);
PostMessage(handle, 0x0102, 0xD, 0xC01C001);
}
}
์ถ์ฒ:
https://kimkitty.net/archives/2276
Kim Kitty's Blog
๊นํคํฐ์ ์์๋ผ์ฅ - C#,PC๊ฒ์,์ด์,ํธ๋ ๋
kimkitty.net
์์ฝ ์ ๋ฆฌ
using System.Runtime.InteropServices;
private void button1_Click(object sender, EventArgs e)
{
//ํธ๋ค์ ์ฐพ๋๋ค. Spy+๋ฅผ ํตํด ์ฐพ์ ํด๋์ค ์ด๋ฆ๊ณผ ์บก์
์ ์ด์ฉํ๋ฉด ๋๋ค. ๋ ์ค ํ๋๋ง ์๊ฒฝ์ฐ์๋ ์ฐพ์ ์ ์๋ค. ๊ทธ๋๋ ํ๋์ ์ธ์๋ฅผ null๋ก ๋๊ฒจ ์ฃผ๋ฉด๋๋ค.
handle = FindWindow(null, "Form1");
handle = FindWindowEx(handle, 0, "WindowsForms10.BUTTON.app.0.141b42a_r7_ad1", null);
label1.Text = Convert.ToString(handle, 16);
}
private void button2_Click(object sender, EventArgs e)
{
Console.WriteLine("Handle Event: " + handle.ToString());
const uint BM_CLICK = 0x00F5;
PostMessage(h, BM_CLICK, 0, 0);
}
Spy++์์ ์ํ๋ ์๋์ฐ์ ์ฐฝ์ ์ก์ ํ์ ์บก์ (์๋์ฐ ํ์ดํ ์๋ก "Form1")๋ ์ฐฝ์ ํด๋์ค(WindowsForms10.BUTTON...)์ผ๋ก ์ก์์ ์ฌ์ฉํ๋ฉด ๋๋ค.
2022-08-28 ์์
const uint WM_KEYDOWN = 0x100;
const uint WM_KEYUP = 0x101;
const uint WM_CHAR = 0x102;
PostMessage(handle, WM_KEYDOWN, (int)Keys.Enter, 0);
PostMessage(handle, WM_KEYUP, (int)Keys.Enter, 0);
์๋ฅผ ์๋๋ก
const uint BM_CLICK = 0x00F5;
PostMessage(h, BM_CLICK, 0, 0);
https://stackoverflow.com/questions/4665463/button-click-in-sendmessage-api
Button click in sendmessage API
How can I simulate a button click in the sendmessage API in C#?
stackoverflow.com
ํด๋์ค๋ก ์ฐพ๋๊ฒ ์๋๋ผ ์บก์ (ํ ์คํธ)์ผ๋ก ์ฐพ๊ธฐ
์ด๋ฐ์์ผ๋ก "ํ๋ก๊ทธ๋จ ์์", "ํ๋ก๊ทธ๋จ ์ฌ๊ฐ", "ํ๋ก๊ทธ๋จ ์ ์ง" ๋ฒํผ์ ํ ์คํธ(์บก์ )๋ฅผ ์ธ์ํด์ ๋ฒํผ์ ์ฐพ๊ณ ์ถ์ ๊ฒฝ์ฐ
FindWindowEx(handle, 0, null, "ํ๋ก๊ทธ๋จ ์์");
FindWindowEx(handle, 0, null, "ํ๋ก๊ทธ๋จ ์ฌ๊ฐ");
FindWindowEx(handle, 0, null, "ํ๋ก๊ทธ๋จ ์ ์ง");
์ด๋ฐ์์ผ๋ก ํด๋์ค ์ธ์๋ null์ ๊ฑด๋ค์ฃผ๊ณ 4๋ฒ์งธ ์ธ์๋ก ์บก์ ์ ๊ฑด๋ค์ค๋ค.
โป ์ฃผ์
๋จผ์ ๋ฒํผ๋ค์ ๋ถ๋ชจ ํธ๋ค๋ก ์ฐพ์์ฃผ์ด์ผ ํ๋ค. spyxx๋ก ๋ถ๋ชจ ์์๋ฅผ ์ ์ฐพ์์ฃผ๋ฉด ๋๋ค.
'๐จ๐ผโ๐ป๊ฐ๋ฐ > C#' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
C# - ํ๋ก๊ทธ๋จ ์ค๋ณต ์คํ ๋ฐฉ์งํ๊ธฐ (0) | 2022.08.26 |
---|---|
C# - ๋ค๋ฅธ ํ๋ก์ธ์ค๋ผ๋ฆฌ ๋ฉ์์ง(string) ์ ๋ฌํ๊ธฐ(SendMessage) (0) | 2022.08.24 |
C# - ์ค๋ ๋์์ ์์ ฏ ์กฐ์ํ๊ธฐ (0) | 2022.08.23 |
C# - http ์์ฒญ(HttpWebRequest) (0) | 2022.06.27 |
C# - ๊ฐ๋จํ API ์์ฒญ & JSON ์ถ๋ ฅ (0) | 2022.02.02 |