첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

▶ 특정 프로세스의 윈도우 상태 구하기 예제

using System;
using System.Diagnostics;

rocess[] processArray = Process.GetProcesses();

foreach(Process process in processArray)
{
    if(process.ProcessName == "notepad")
    {
        WindowPlacement windowPlacement = GetWindowPlacement(process.MainWindowHandle);

        Console.WriteLine(windowPlacement.ShowWindowCommand.ToString());
    }
}

 

728x90

 

▶ 특정 프로세스의 윈도우 상태 구하기

using System;
using System.Runtime.InteropServices;

#region 윈도우 표시 명령 - ShowWindowCommand

/// <summary>
/// 윈도우 표시 명령
/// </summary>
public enum ShowWindowCommand : int
{
    /// <summary>
    /// 숨김
    /// </summary>
    Hide = 0,

    /// <summary>
    /// 일반
    /// </summary>
    Normal = 1,

    /// <summary>
    /// 최소
    /// </summary>
    Minimized = 2,

    /// <summary>
    /// 최대
    /// </summary>
    Maximized = 3,
}

#endregion
#region 윈도우 배치 - WindowPlacement

/// <summary>
/// 윈도우 배치
/// </summary>
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public struct WindowPlacement
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Field
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region Field

    /// <summary>
    /// 길이
    /// </summary>
    public int Length;

    /// <summary>
    /// 플래그
    /// </summary>
    public int Flag;

    /// <summary>
    /// 윈도우 표시 명령
    /// </summary>
    public ShowWindowCommand ShowWindowCommand;

    /// <summary>
    /// 최소 위치
    /// </summary>
    public System.Drawing.Point MinimumPosition;

    /// <summary>
    /// 최대 위치
    /// </summary>
    public System.Drawing.Point MaximumPosition;

    /// <summary>
    /// 일반 사각형
    /// </summary>
    public System.Drawing.Rectangle NormalRectangle;

    #endregion
}

#endregion
#region 윈도우 배치 구하기 - GetWindowPlacement(windowHandle, windowPlacement)

/// <summary>
/// 윈도우 배치 구하기
/// </summary>
/// <param name="windowHandle">윈도우 핸들</param>
/// <param name="windowPlacement">윈도우 배치</param>
/// <returns>처리 결과</returns>
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool GetWindowPlacement(IntPtr windowHandle, ref WindowPlacement windowPlacement);

#endregion
#region 윈도우 배치 구하기 - GetWindowPlacement(windowHandle)

/// <summary>
/// 윈도우 배치 구하기
/// </summary>
/// <param name="windowHandle">윈도우 핸들</param>
/// <returns>윈도우 배치</returns>
public WindowPlacement GetWindowPlacement(IntPtr windowHandle)
{
    WindowPlacement windowPlacement = new WindowPlacement();

    windowPlacement.Length = Marshal.SizeOf(windowPlacement);

    GetWindowPlacement(windowHandle, ref windowPlacement);

    return windowPlacement;
}

#endregion
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요