Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DisableMinimizeButton and SwitchToThisWindow functions #438

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions window.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ type Window interface {
// By default this is nil.
Cursor() Cursor

// Disable minimized button
DisableMinimizeButton() error

// Dispose releases the operating system resources, associated with the
// Window.
//
Expand Down Expand Up @@ -277,6 +280,8 @@ type Window interface {
// RootWidgets like *MainWindow or *Dialog and relative to the parent for
// child Windows.
Y() int

SwitchToThisWindow()
}

type calcTextSizeInfo struct {
Expand Down Expand Up @@ -657,6 +662,21 @@ func (wb *WindowBase) AddDisposable(d Disposable) {
wb.disposables = append(wb.disposables, d)
}

// DisableMinimizeButton disables minimized button
func (wb *WindowBase) DisableMinimizeButton() error {
style := uint32(win.GetWindowLong(wb.hWnd, win.GWL_STYLE))
if style == 0 {
return lastError("GetWindowLong")
}
if newStyle := style &^ win.WS_MINIMIZEBOX; newStyle != style {
win.SetLastError(0)
if win.SetWindowLong(wb.hWnd, win.GWL_STYLE, int32(newStyle)) == 0 {
return lastError("SetWindowLong")
}
}
return nil
}

// Dispose releases the operating system resources, associated with the
// *WindowBase.
//
Expand Down Expand Up @@ -1906,3 +1926,11 @@ func (wb *WindowBase) WndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr)

return win.DefWindowProc(hwnd, msg, wParam, lParam)
}

func (wb *WindowBase) SwitchToThisWindow() {
libuser32 := win.MustLoadLibrary("User32.dll")
syscall.Syscall(win.MustGetProcAddress(libuser32, "SwitchToThisWindow"), 2,
uintptr(wb.hWnd),
1,
0)
}