move window with resizewindow / slide window

Just starting out? Need help? Post your questions and find answers here.
Amnesty
User
User
Posts: 54
Joined: Wed Jul 04, 2007 4:34 pm
Location: Germany

move window with resizewindow / slide window

Post 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
User avatar
JHPJHP
Addict
Addict
Posts: 2259
Joined: Sat Oct 09, 2010 3:47 am

Re: move window with resizewindow / slide window

Post 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.

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
PureLust
Enthusiast
Enthusiast
Posts: 477
Joined: Mon Apr 16, 2007 3:57 am
Location: Germany, NRW

Re: move window with resizewindow / slide window

Post 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.)
[Dynamic-Dialogs] - create complex GUIs the easy way
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: move window with resizewindow / slide window

Post 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!
;================================================================================

BERESHEIT
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: move window with resizewindow / slide window

Post 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
Amnesty
User
User
Posts: 54
Joined: Wed Jul 04, 2007 4:34 pm
Location: Germany

Re: move window with resizewindow / slide window

Post 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!
Post Reply