Page 1 of 1

Sticky Window

Posted: Sun Aug 24, 2003 4:29 am
by Flype
I made a little proc in order to 'stick' your window to the screen borders.
Just like a WinAmp window do...
Run the example, and move it to the border of your desktop and look at the behavior...

Code: Select all

#SPACE = 16 

;-- Procedure StickyWindow -- 

Procedure StickyWindow( hWnd.l, Event.l, wParam.l, lParam.l ) 
  
  If Event = #WM_WINDOWPOSCHANGED 
    
    SystemParametersInfo_( #SPI_GETWORKAREA, 0, @scrRect.RECT, 0) 
      scrW = scrRect\right  - scrRect\left 
      scrH = scrRect\bottom - scrRect\top 
    
    GetWindowRect_( WindowID(), @wndRect.RECT ) 
      wndW = wndRect\right  - wndRect\left 
      wndH = wndRect\bottom - wndRect\top 
    
    If wndRect\left        < #SPACE : wndRect\left = 0 : EndIf 
    If wndRect\top         < #SPACE : wndRect\top  = 0 : EndIf 
    If scrW-wndRect\right  < #SPACE : wndRect\left = scrW-wndW : EndIf 
    If scrH-wndRect\bottom < #SPACE : wndRect\top  = scrH-wndH : EndIf 
    
    MoveWindow( wndRect\left, wndRect\top ) 
    
  EndIf 
  
  ProcedureReturn #PB_ProcessPureBasicEvents 
  
EndProcedure 

;-- Boucle Principale -- 

If OpenWindow( 0, 200, 200, 300, 100, #PB_Window_SystemMenu, "Sticky Window" ) 
  SetWindowCallback( @StickyWindow() ) 
  While WaitWindowEvent() <> #WM_CLOSE : Wend 
EndIf 

;-- Fin -- 

End
if anyone has idea to enhance it, tell me here :wink:

Posted: Sun Aug 24, 2003 11:07 am
by freak
You should have a look at the #WM_SIZING anf #WM_MOVING messages,
so you can allready snap the drag-rectangle of the window to the
borders of the desktop.

And this stuff only works on the primary monitor, if you have more than
one monitor, the window always jumps back to the oprimary monitor.

Timo

Posted: Mon Aug 25, 2003 6:22 pm
by Flype
works on the primary monitor, if you have more than
one monitor, the window always jumps back to the oprimary monitor
have U got a solution for this problem ? i don't know how to correct this one, and i can't test it at home as i have only one monitor :?

What's the english 'word' for what i call 'Sticky' ??? Snap-Window ?

Posted: Mon Aug 25, 2003 7:17 pm
by freak
Hmm, I just noticed, that the monitor stuff would prevent the program
from working on all windows versions. (only win2k+ and win98+)

I think, the best is to add some more checks, and if you end up with
negative values, the window is on another monitor, and should just stay
there.

Could look like this then...

Code: Select all

Procedure StickyWindow( hWnd.l, Event.l, wParam.l, lParam.l ) 
  
  If Event = #WM_WINDOWPOSCHANGED 
    
    SystemParametersInfo_( #SPI_GETWORKAREA, 0, @scrRect.RECT, 0)     
      scrW = scrRect\right  - scrRect\left 
      scrH = scrRect\bottom - scrRect\top     
    
    GetWindowRect_( WindowID(), @wndRect.RECT ) 
      wndW = wndRect\right  - wndRect\left 
      wndH = wndRect\bottom - wndRect\top 
    
    If wndRect\left-scrRect\left < #SPACE And wndRect\left-scrRect\left > 0 : wndRect\left = 0 : EndIf 
    If wndRect\top-scrRect\top < #SPACE And wndRect\top-scrRect\top  > 0 : wndRect\top  = 0 : EndIf 
    If scrRect\right-wndRect\right  < #SPACE And scrRect\right-wndRect\right > 0: wndRect\left = scrRect\right-wndW : EndIf 
    If scrRect\bottom-wndRect\bottom < #SPACE And scrRect\bottom-wndRect\bottom > 0: wndRect\top  = scrRect\bottom-wndH : EndIf 
    
    MoveWindow( wndRect\left, wndRect\top ) 
    
  EndIf 
  
  ProcedureReturn #PB_ProcessPureBasicEvents 
  
EndProcedure 
It works ok now here (just no action is taken, when the window is on the
second monitor.)

about the english word, i don't know that either. :roll:

Timo

Posted: Mon Aug 25, 2003 7:36 pm
by Karbon
I'd say snap-back windows works. Not sure there is a single English word for it - you could call it a lot of things.. If there is a proper term hopefully someone that knows it will speak up!

Sticky would mean that it stays in one place all the time - though arguably that one place could be right under another window..

Hell, sticky or snap-back works.. English is crazy :-)

Posted: Mon Aug 25, 2003 7:56 pm
by Flype
thanx for the feedback guys :wink:

Posted: Fri Feb 23, 2007 2:22 pm
by Joakim Christiansen
Is there anyway to make this flicker less? (yeah it's a serious question)

Posted: Fri Feb 23, 2007 9:21 pm
by PB
It's calling docking in English. Sticky windows are ones that are always on top.

Posted: Sat Feb 24, 2007 6:54 pm
by netmaestro
You shouldn't get any flicker from this one:

http://www.purebasic.fr/english/viewtop ... 51&start=3

Posted: Sun Mar 11, 2007 2:20 am
by Joakim Christiansen
Sweet, thanks! :D