Page 1 of 1
move window with resizewindow / slide window
Posted: Sun Jan 07, 2018 12:30 am
by Amnesty
Hello and although the year is already six days old, I would like to wish you the best for 2018.
I have got a general question:
for my application a need a borderless alert window which slides from the right edge into the screen. I m using a for ... next loop to set the position with resizewindow and a delay(1). It works but its not really smooth.
Is there anybody out there with a similar task or problem, who has got another / different solution how to create such a moving / sliding alert windows ?
regards
amnesty
Re: move window with resizewindow / slide window
Posted: Sun Jan 07, 2018 1:25 am
by JHPJHP
Hi Amnesty,
Happy New Year
Awhile ago I was playing around with some Windows only code; might be of some interest to you
-
Services, Stuff & Shellhook
--
Stuff\GadgetBar\GadgetBar.pb
Select your options; click anywhere on the window to slide open the Gadget-Bar, click again to close it.
NB*: Various parts of the package can be downloaded separately.
Re: move window with resizewindow / slide window
Posted: Sun Jan 07, 2018 1:48 am
by PureLust
Amnesty wrote:It works but its not really smooth.
Without a working sample-code it's a bit difficult to guess what the Problem could be.
Nevertheless:
1. maybe a Delay(1) is a but to short. Delay(16) should be enough to get a smooth 60Hz animation.
2. did you clear the Event-Loop after each ResizeWindow() ?
[EDIT:]
A quick sample-code, including the hints from above:
Code: Select all
ExamineDesktops()
OpenWindow(0,0,0,150,65,"Alert-Window",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ButtonGadget(0,5,5,140,25,"Fade in ...")
ButtonGadget(1,5,35,140,25,"Fade out ...")
OpenWindow(1,0,130,150,300,"Alert", #PB_Window_Invisible) ; #PB_Window_BorderLess|
AnimDuration = 500 ;ms
FrameDuration = 16 ;ms
AnimSteps.f = AnimDuration / FrameDuration
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
XStep.f = WindowWidth(1, #PB_Window_FrameCoordinate) / AnimSteps * 2
If EventGadget() = 0
XPos.f = DesktopWidth(0)-WindowWidth(1, #PB_Window_FrameCoordinate)+XStep*AnimSteps
ResizeWindow(1,XPos,#PB_Ignore,#PB_Ignore,#PB_Ignore)
HideWindow(1,#False)
For x = 1 To AnimSteps
While WindowEvent() : Wend
Delay(FrameDuration)
XPos - XStep
ResizeWindow(1,XPos,#PB_Ignore,#PB_Ignore,#PB_Ignore)
Next
ElseIf EventGadget() = 1
XPos.f = DesktopWidth(0)-WindowWidth(1, #PB_Window_FrameCoordinate)
ResizeWindow(1,XPos,#PB_Ignore,#PB_Ignore,#PB_Ignore)
For x = 1 To AnimSteps
While WindowEvent() : Wend
Delay(FrameDuration)
XPos + XStep
ResizeWindow(1,XPos,#PB_Ignore,#PB_Ignore,#PB_Ignore)
Next
HideWindow(1,#True)
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
(Only works correct, if Windows-Scaling is set to 100%. Otherwise window position is calculated wrong.)
Re: move window with resizewindow / slide window
Posted: Sun Jan 07, 2018 9:29 am
by netmaestro
No API so *should* be OK on all platforms. No guarantees, if you need one buy a toaster.
Code: Select all
;================================================================================
; INITIALIZATION SECTION
;================================================================================
Declare SlideOpen(window)
Declare SlideClosed(window)
ExamineDesktops()
Global w = DesktopWidth(0)
Global h = DesktopHeight(0)
LoadFont(0, "Verdana", 12, #PB_Font_Bold)
OpenWindow(0, w, h/2, 400, 60, "", #PB_Window_BorderLess)
TextGadget(0, 80, 18, 300, 26, "ALERT (click to dismiss)")
SetGadgetFont(0, FontID(0))
SetWindowColor(0, RGB(255,0,255))
SetGadgetColor(0, #PB_Gadget_BackColor, RGB(255,0,255))
CreateThread(@SlideOpen(), 0)
;================================================================================
; MAIN LOOP
;================================================================================
Repeat
EventID = WaitWindowEvent()
Select EventID
Case #PB_Event_LeftClick
tid = CreateThread(@SlideClosed(), 0)
EndSelect
Until EventID = #PB_Event_CloseWindow
;================================================================================
; PROCEDURE SECTION
;================================================================================
Procedure SlideOpen(window)
While WindowX(window) > (w-WindowWidth(window))
ResizeWindow(window, WindowX(window)-1, #PB_Ignore, #PB_Ignore, #PB_Ignore)
Delay(2)
Wend
EndProcedure
Procedure SlideClosed(window)
While WindowX(window) < w-1
ResizeWindow(window, WindowX(window)+1, #PB_Ignore, #PB_Ignore, #PB_Ignore)
Delay(2)
Wend
PostEvent(#PB_Event_CloseWindow, 0, 0)
EndProcedure
;================================================================================
; TH-TH-TH-TH-THAT'S ALL FOLKS!
;================================================================================
Re: move window with resizewindow / slide window
Posted: Sun Jan 07, 2018 10:05 am
by Dude
For Windows only, and guaranteed to be silky-smooth.
A major bonus is that it doesn't take the focus away from the active window, so you can (for example) be typing in Notepad without being interrupted when the window appears.
The second bonus is that it doesn't put a phantom button on the taskbar.
Code: Select all
ExamineDesktops()
If OpenWindow(0,DesktopWidth(0)-300,DesktopHeight(0)/2,300,50,"",#PB_Window_Invisible|#PB_Window_BorderLess)
SetWindowLongPtr_(WindowID(0),#GWL_EXSTYLE,GetWindowLongPtr_(WindowID(0),#GWL_EXSTYLE)|#WS_EX_TOOLWINDOW)
StickyWindow(0,#True)
TextGadget(0,0,20,300,20,"Here is your sliding message!",#PB_Text_Center)
AnimateWindow_(WindowID(0),250,#AW_SLIDE|#AW_HOR_NEGATIVE)
Sleep_(1000)
AnimateWindow_(WindowID(0),250,#AW_SLIDE|#AW_HOR_POSITIVE|#AW_HIDE)
CloseWindow(0)
EndIf
Re: move window with resizewindow / slide window
Posted: Mon Jan 08, 2018 10:37 pm
by Amnesty
Thank you, you helped me a lot, i did it with resizewindow, but Animatewindow_ is the best for me, in my case.
Amnesty!