Page 1 of 1

Restoring a borderless window from the taskbar

Posted: Mon Sep 10, 2018 8:25 am
by Seymour Clufley
Surprisingly, I can't find code on the forum for doing this.

I have a borderless window. A buttongadget enables the user to minimise it. That works. Pressing the window's taskbar button restores the window, as normal. But, if the window is currently restored, pressing the taskbar button does not minimise it. This does happen if I get rid of #PB_Window_Borderless and replace it with #PB_Window_MinimizeGadget - but I don't want to do that. The window needs to be borderless.

Does anyone know what to do?

Code: Select all

win = OpenWindow(#PB_Any,0,0,800,600,"Test",#PB_Window_ScreenCentered|#PB_Window_BorderLess)
minbut = ButtonGadget(#PB_Any,50,50,100,25,"Minimise")

Macro MinimiseWindow
  ShowWindow_(WindowID(win),#SW_MINIMIZE)
  minimised = #True
  Debug "MINIMISED"
EndMacro

Macro RestoreWindow
  ShowWindow_(WindowID(win),#SW_SHOWNORMAL)
  minimised = #False
  Debug "RESTORED"
EndMacro


Repeat 
  we = WaitWindowEvent(50)
  Select we
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case minbut
          MinimiseWindow
      EndSelect
  EndSelect
Until GetAsyncKeyState_(#VK_ESCAPE)

Re: Restoring a borderless window from the taskbar

Posted: Mon Sep 10, 2018 8:33 am
by RSBasic

Code: Select all

win = OpenWindow(#PB_Any,0,0,800,600,"Test",#PB_Window_ScreenCentered|#PB_Window_BorderLess | #PB_Window_MinimizeGadget)
minbut = ButtonGadget(#PB_Any,50,50,100,25,"Minimise")

Macro MinimiseWindow
  ShowWindow_(WindowID(win),#SW_MINIMIZE)
  minimised = #True
  Debug "MINIMISED"
EndMacro

Macro RestoreWindow
  ShowWindow_(WindowID(win),#SW_SHOWNORMAL)
  minimised = #False
  Debug "RESTORED"
EndMacro

SetWindowLongPtr_(WindowID(win), #GWL_STYLE, GetWindowLongPtr_(WindowID(win), #GWL_STYLE) ! #WS_DLGFRAME)
SetWindowPos_(WindowID(win), 0,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE|#SWP_NOZORDER|#SWP_FRAMECHANGED)

Repeat
  we = WaitWindowEvent(50)
  Select we
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case minbut
          MinimiseWindow
      EndSelect
  EndSelect
Until GetAsyncKeyState_(#VK_ESCAPE)

Re: Restoring a borderless window from the taskbar

Posted: Mon Sep 10, 2018 10:57 am
by Seymour Clufley
Thank you very much! :)