[v3 windows] Add WndProcInterceptor for custom message processing

This commit is contained in:
Lea Anthony 2023-04-30 09:49:50 +10:00 committed by Misite Bao
commit 7f3fdd6977
4 changed files with 32 additions and 0 deletions

View file

@ -202,3 +202,17 @@ On Windows, if the `BackgroundType` is set to `BackgroundTypeTranslucent`, the t
- `Tabbed` - The window will use the tabbed effect
## Windows Application Options
### WndProcInterceptor
If this is set, the WndProc will be intercepted and the function will be called. This allows you to handle Windows
messages directly. The function should have the following signature:
```go
func(hwnd uintptr, msg uint32, wParam, lParam uintptr) (returnValue uintptr, shouldReturn)
```
The `shouldReturn` value should be set to `true` if the returnValue should be returned by the main wndProc method.
If it is set to `false`, the return value will be ignored and the message will continue to be processed by the main
wndProc method.

View file

@ -128,6 +128,15 @@ func (m *windowsApp) wndProc(hwnd w32.HWND, msg uint32, wParam, lParam uintptr)
m.invokeCallback(wParam, lParam)
return 0
}
// If the WndProcInterceptor is set in options, pass the message on
if m.parent.options.Windows.WndProcInterceptor != nil {
returnValue, shouldReturn := m.parent.options.Windows.WndProcInterceptor(hwnd, msg, wParam, lParam)
if shouldReturn {
return returnValue
}
}
switch msg {
case w32.WM_SETTINGCHANGE:
settingChanged := w32.UTF16PtrToString((*uint16)(unsafe.Pointer(lParam)))

View file

@ -12,6 +12,7 @@ type Options struct {
Description string
Icon []byte
Mac MacOptions
Windows WindowsApplicationOptions
Bind []any
Logger struct {
Silent bool

View file

@ -1,5 +1,13 @@
package application
type WindowsApplicationOptions struct {
// WndProcInterceptor is a function that will be called for every message sent in the application.
// Use this to hook into the main message loop. This is useful for handling custom window messages.
// If `shouldReturn` is `true` then `returnCode` will be returned by the main message loop.
// If `shouldReturn` is `false` then returnCode will be ignored and the message will be processed by the main message loop.
WndProcInterceptor func(hwnd uintptr, msg uint32, wParam, lParam uintptr) (returnCode uintptr, shouldReturn bool)
}
type BackdropType int32
const (