728x90
반응형
728x170
▶ WIN32 API를 사용해 최상위 윈도우 여부 구하기 예제
using System;
Console.WriteLine(WindowHelper.IsTopMostWindow("notepad"));
728x90
▶ WIN32 API를 사용해 최상위 윈도우 여부 구하기
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
/// <summary>
/// 윈도우 헬퍼
/// </summary>
public static class WindowHelper
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Import
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 윈도우 값 구하기 - GetWindowLong(windowHandle, index)
/// <summary>
/// 윈도우 값 구하기
/// </summary>
/// <param name="windowHandle">윈도우 핸들</param>
/// <param name="index">인덱스</param>
/// <returns>값</returns>
[DllImport("user32.dll", SetLastError = true)]
private static extern int GetWindowLong(IntPtr windowHandle, int index);
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// GWL_EXSTYLE
/// </summary>
private const int GWL_EXSTYLE = -20;
/// <summary>
/// WS_EX_TOPMOST
/// </summary>
private const uint WS_EX_TOPMOST = 0x0008;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Public
#region 최상위 윈도우 여부 구하기 - IsTopMostWindow(processName)
/// <summary>
/// 최상위 윈도우 여부 구하기
/// </summary>
/// <param name="processName">프로세스명</param>
/// <returns>최상위 윈도우 여부</returns>
public static bool IsTopMostWindow(string processName)
{
Process[] processArray = Process.GetProcessesByName(processName);
if(processArray.Length == 0)
{
return null;
}
Process process = processArray[0];
int dwExStyle = GetWindowLong(process.MainWindowHandle, GWL_EXSTYLE);
bool result = ((dwExStyle & WS_EX_TOPMOST) != 0);
return result;
}
#endregion
}
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] 윈도우즈 서비스 내에서 사용자 계정 변경하기 (0) | 2019.06.20 |
---|---|
[C#/COMMON] AppDomain 클래스 : 별도 애플리케이션 도메인에서 특정 어셈블리 로드하기 (0) | 2019.06.18 |
[C#/COMMON] AppDomain 클래스 : 애플리케이션 그림자 복사(Shadow Copy) 사용하기 (0) | 2019.06.18 |
[C#/COMMON] SpeechSynthesizer 클래스 : GetInstalledVoices 메소드를 사용해 설치 음성 목록 구하기 (0) | 2019.06.11 |
[C#/COMMON] UNIX 타임 스탬프 구하기 (0) | 2019.06.09 |
[C#/COMMON] WIN32 API를 사용해 최상위 윈도우 여부 구하기 (0) | 2019.06.06 |
[C#/COMMON] Process 클래스 : 윈도우즈 서비스 실행하기 (0) | 2019.06.06 |
[C#/COMMON] 공용체(Union) 구조체 사용하기 (0) | 2019.06.02 |
[C#/COMMON] Socket 클래스 : 소켓 연결시 시간 제한하기 (0) | 2019.06.02 |
[C#/COMMON] 파일 확장자 연결하기 (0) | 2019.05.30 |
[C#/COMMON] 바이트 배열에서 구조체 객체 구하기 (0) | 2019.05.27 |
댓글을 달아 주세요