(.NET) exe 실행 파일 항상 위에 두기(BringWindowToTop, SetWindowPos - user32.dll)
어떻한 특정 실행 파일을 항상 가장 위에 두고싶을때 사용 하는 방법이다.
찾아보니 특정 실행파일을 가장 상위로 올려주는 프로그램도 많이 있었다.
class Program
{
static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
const UInt32 SWP_NOSIZE = 0x0001;
const UInt32 SWP_NOMOVE = 0x0002;
[DllImport("user32.dll")]
public static extern int BringWindowToTop(IntPtr hwnd);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
static void Main(string[] args)
{
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = @"C:\Program Files (x86)\Notepad2\Notepad2.exe";
process.Start();
process.WaitForInputIdle();
BringWindowToTop(process.MainWindowHandle);
SetWindowPos(process.MainWindowHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE);
}
}