728x90
728x170
■ HwndSource 클래스의 FromHwnd 정적 메소드를 사용해 윈도우 핸들로 윈도우를 구하는 방법을 보여준다.
▶ HwndSource 클래스 : FromHwnd 정적 메소드를 사용해 윈도우 핸들로 윈도우 구하기 예제 (C#)
using System;
using System.Runtime.InteropServices;
using System.Windows;
IntPtr windowHandle = GetForegroundWindow();
Window window = GetWindow(windowHandle);
#region 전경 윈도우 구하기 - GetForegroundWindow()
/// <summary>
/// 전경 윈도우 구하기
/// </summary>
/// <returns>윈도우 핸들</returns>
[DllImport("user32")]
private static extern IntPtr GetForegroundWindow();
#endregion
▶ HwndSource 클래스 : FromHwnd 정적 메소드를 사용해 윈도우 핸들로 윈도우 구하기 (C#)
using System;
using System.Windows;
using System.Windows.Interop;
#region 윈도우 구하기 - GetWindow(windowHandle)
/// <summary>
/// 윈도우 구하기
/// </summary>
/// <param name="windowHandle">윈도우 핸들</param>
/// <returns>윈도우</returns>
public Window GetWindow(IntPtr windowHandle)
{
Window window = (Window)HwndSource.FromHwnd(windowHandle).RootVisual;
return window;
}
#endregion
728x90
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] Window 클래스 : 커스텀 윈도우 사용하기 (0) | 2021.08.20 |
---|---|
[C#/WPF] Application 클래스 : Restart 메소드를 사용해 애플리케이션 재시작하기 (0) | 2021.08.19 |
[C#/WPF] Vector 구조체 : 벡터 각도 구하기 (0) | 2021.08.19 |
[C#/WPF] ResourceDictionary 클래스 : MergedDictionaries 속성을 사용해 Application 객체의 리소스 사용하기 (0) | 2021.07.08 |
[C#/WPF] ControlTemplate 엘리먼트 : Thumb/ScrollBar/ListBoxItem 엘리먼트 정의하기 (0) | 2021.06.07 |
[C#/WPF] 잠금 화면 설정하기 (기능 개선) (0) | 2021.05.31 |
[C#/WPF] 비동기 가상화 컬렉션 사용하기 (0) | 2021.05.21 |
[C#/WPF] PathGeometry 클래스 : GraphicsPath 객체에서 패스 지오메트리 구하기 (0) | 2021.05.13 |
[C#/WPF] 누겟 설치 : AvalonEdit (0) | 2021.05.10 |
[C#/WPF] 코드 편집기(Code Editor) 사용하기 (0) | 2021.05.07 |