윈도우 핸들을 사용해서 창의 위치, 크기, Z-Order(창 순서) 등을 바꿉니다.
package window
import (
"syscall"
"unsafe"
)
func FindWindows(mod *syscall.LazyDLL) uintptr {
proc := mod.NewProc("FindWindowW")
className := syscall.StringToUTF16Ptr("Notepad")
hWnd, _, err := proc.Call(uintptr(unsafe.Pointer(className)), 0)
if hWnd == 0 {
panic(err)
}
return hWnd
}
func SetWindowPosition(mod *syscall.LazyDLL, hWnd uintptr, x, y, width, height int32) {
proc := mod.NewProc("SetWindowPos")
proc.Call(
hWnd,
uintptr(0), // Z-Order
uintptr(x),
uintptr(y),
uintptr(width),
uintptr(height),
0x0040, // 플래그 SWP_SHOWWINDOW
)
}
func callSetWindowPosition() {
mod := syscall.NewLazyDLL("user32.dll")
hWnd := window.FindWindows(mod)
window.SetWindowPosition(mod, hWnd, 0, 0, 800, 600)
}
결과
- 메모장 열기 (창 제목: 상관없음)
- 이 코드를 실행하면:
- 메모장이 화면의 (0, 0) 위치로 이동
- 창 크기는 800x600으로 변경
SetWindowPos 플래그 값
- 0x0040: SWP_SHOWWINDOW → 창 보이기
- 0x0001: SWP_NOSIZE → 크기 변경 안 함
- 0x0002: SWP_NOMOVE → 위치 변경 안 함
- 0x0200: SWP_NOACTIVATE → 창 활성화 안 함
'Go > window_api' 카테고리의 다른 글
[Go] Windows API - 창 상태 제어 (0) | 2025.03.05 |
---|---|
[Go] Windows API - 창 핸들 찾기 (0) | 2025.03.05 |
[Go] Windows API - 마우스, 화면, 시스템 상태까지 확인 (0) | 2025.03.05 |
[Go] Windows API - 시스템 해상도 가져오기 (0) | 2025.03.05 |
[Go] Windows API - 메시지 박스 (0) | 2025.03.05 |