앞에서 배운 걸 조합
- 현재 마우스 위치 → 팝업 창으로 표시
- 화면 해상도 → 팝업 창으로 표시
- 추가 아이디어: 시스템 가동 시간 → 팝업 창으로 표시 (GetTickCount API 사용)
package main
import (
"fmt"
"syscall"
"unsafe"
)
var (
user32 = syscall.NewLazyDLL("user32.dll")
kernel32 = syscall.NewLazyDLL("kernel32.dll")
ptr *POINT = &POINT{}
)
type POINT struct {
X, Y int32
}
func main() {
// step 0: message box
messageProc := user32.NewProc("MessageBoxW")
// step 1: get the currnt cursor position
proc := user32.NewProc("GetCursorPos")
ret, _, err := proc.Call(uintptr(unsafe.Pointer(ptr)))
if ret == 0 {
panic(err)
}
// step 2: get the current window handle
proc = user32.NewProc("GetSystemMetrics")
system_width, _, _ := proc.Call(uintptr(0))
system_height, _, _ := proc.Call(uintptr(1))
// step 3: get the current window handle
proc = kernel32.NewProc("GetTickCount")
tickCount, _, _ := proc.Call()
uptimeMessage := float64(tickCount) / 1000
messageProc.Call(
uintptr(0),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(fmt.Sprintf("x=%d, y=%d", ptr.X, ptr.Y)))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("Mouse Position"))),
uintptr(0),
)
messageProc.Call(
uintptr(0),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(fmt.Sprintf("width=%d, height=%d", system_width, system_height)))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("system metrics"))),
uintptr(0),
)
messageProc.Call(
uintptr(0),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(fmt.Sprintf("uptime=%v", uptimeMessage)))),
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr("system uptime"))),
uintptr(0),
)
}
작은 시스템 모니터링 툴
'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 |