Programming/C/C++/C#
C# 윈도우 핸들 찾기(FIndWindow)
휘탱
2017. 7. 2. 11:44
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | using System; using System.Runtime.InteropServices; class Test { [DllImport("user32.dll")] public static extern int FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr hWnd); [DllImport("user32.dll")] private static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow); private const int SW_SHOWNORMAL = 1; private const int SW_SHOWMINIMIZED = 2; private const int SW_SHOWMAXIMIZED = 3; void Find() { // 윈도우 타이틀명으로 핸들을 찾는다 var hWnd = FindWindow(null, "Test"); if (!hWnd.Equals(IntPtr.Zero)) { // 윈도우가 최소화 되어 있다면 활성화 시킨다 ShowWindowAsync(hWnd, SW_SHOWNORMAL); // 윈도우에 포커스를 줘서 최상위로 만든다 SetForegroundWindow(hWnd); } } } | cs |
반응형