summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAlexander Neumann <alexander.neumann@picos-software.com>2018-12-05 16:36:34 +0100
committerAlexander Neumann <alexander.neumann@picos-software.com>2018-12-05 16:36:34 +0100
commitc1af619bceabb3611026b5fdb62d75379b757cbf (patch)
tree7d55f8865b6c36db80c3b07e8aa8ef3b9433174c
parentDon't activate a window when it is made visible (diff)
downloadwireguard-windows-c1af619bceabb3611026b5fdb62d75379b757cbf.tar.xz
wireguard-windows-c1af619bceabb3611026b5fdb62d75379b757cbf.zip
WindowBase: Add ForEachDescendant
-rw-r--r--window.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/window.go b/window.go
index 88f80d75..f11972ff 100644
--- a/window.go
+++ b/window.go
@@ -915,6 +915,28 @@ func setWindowText(hwnd win.HWND, text string) error {
return nil
}
+func forEachDescendant(hwnd win.HWND, lParam uintptr) uintptr {
+ if window := windowFromHandle(hwnd); window != nil && forEachDescendantCallback(window.(Widget)) {
+ return 1
+ }
+
+ return 0
+}
+
+var (
+ forEachDescendantCallbackPtr = syscall.NewCallback(forEachDescendant)
+ forEachDescendantCallback func(widget Widget) bool
+)
+
+func (wb *WindowBase) ForEachDescendant(f func(widget Widget) bool) {
+ forEachDescendantCallback = f
+ defer func() {
+ forEachDescendantCallback = nil
+ }()
+
+ win.EnumChildWindows(wb.hWnd, forEachDescendantCallbackPtr, 0)
+}
+
// Visible returns if the *WindowBase is visible.
func (wb *WindowBase) Visible() bool {
return win.IsWindowVisible(wb.hWnd)