창 전환
```
try {
Start-Sleep -Seconds 4
# API 정의 (이전과 동일)
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class User32 {
[DllImport("user32.dll")]
public static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
}
"@
# ----------------------------------------------------
# TODO: 필터링할 창 제목을 입력합니다.
$targetTitle = "Netflix"
# ----------------------------------------------------
# 프로세스 목록에서 MainWindowTitle이 'Netflix'인 항목을 찾습니다.
# UWP 앱의 경우 프로세스 이름은 'ApplicationFrameHost' 등이 될 수 있지만,
# MainWindowTitle은 'Netflix'로 표시될 가능성이 높습니다.
$process = Get-Process | Where-Object {
$_.MainWindowHandle -ne 0 -and $_.MainWindowTitle -like "*$targetTitle*"
} | Select-Object -First 1
if ($process) {
[User32]::SwitchToThisWindow($process.MainWindowHandle, $true)
Write-Host "'$targetTitle' 창을 성공적으로 전면으로 가져왔습니다."
} else {
Write-Error "'$targetTitle' 제목을 가진 창을 찾지 못했습니다. 앱이 실행 중인지 확인하세요."
}
} catch {
Write-Error "전환 실패했습니다: $($_.Exception.Message)"
}
```
포커스 전환
```
try {
# Playnite가 완전히 백그라운드로 전환될 시간을 충분히 줍니다.
# 기존 4초가 부족하면 5초 또는 6초로 늘려보세요.
Start-Sleep -Seconds 4
# Win32 API 함수 재정의: SetForegroundWindow 및 FindWindow 사용
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class User32 {
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
// 창을 찾고, 복원(최소화 해제)한 후 전면으로 가져옵니다.
public static bool BringWindowToFront(string windowTitle) {
// 창 제목으로 창 핸들(hWnd)을 찾습니다.
IntPtr hWnd = FindWindow(null, windowTitle);
if (hWnd != IntPtr.Zero) {
const int SW_RESTORE = 9; // 창을 복원 (최소화 해제)하는 명령어
ShowWindow(hWnd, SW_RESTORE);
return SetForegroundWindow(hWnd);
}
return false;
}
}
"@
# ----------------------------------------------------
# TODO: 필터링할 창 제목을 입력합니다. (예: "Netflix")
$targetTitle = "Netflix"
# ----------------------------------------------------
# 1. 프로세스 목록에서 MainWindowTitle이 'Netflix'인 항목을 찾아 창 핸들을 가져옵니다.
$process = Get-Process | Where-Object {
$_.MainWindowHandle -ne 0 -and $_.MainWindowTitle -like "*$targetTitle*"
} | Select-Object -First 1
if ($process) {
# 2. FindWindow를 통해 다시 한번 정확히 해당 창을 찾아 전면으로 가져옵니다.
# 이 방법이 SetForegroundWindow를 안정적으로 호출하는 데 가장 좋습니다.
$success = [User32]::BringWindowToFront($targetTitle)
if ($success) {
Write-Host "'$targetTitle' 창을 성공적으로 전면으로 가져왔습니다."
} else {
Write-Error "'$targetTitle' 창을 활성화하는 데 실패했습니다."
}
} else {
Write-Error "'$targetTitle' 제목을 가진 창을 찾지 못했습니다. 앱이 실행 중인지 확인하세요."
}
} catch {
Write-Error "전환 실패했습니다: $($_.Exception.Message)"
}
```
wono
|
Do you want to delete?