Sticky Window

Windows specific forum
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Sticky Window

Post 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:
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post 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 ?
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
freak
PureBasic Team
PureBasic Team
Posts: 5948
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
Karbon
PureBasic Expert
PureBasic Expert
Posts: 2010
Joined: Mon Jun 02, 2003 1:42 am
Location: Ashland, KY
Contact:

Post 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 :-)
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

thanx for the feedback guys :wink:
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Is there anyway to make this flicker less? (yeah it's a serious question)
I like logic, hence I dislike humans but love computers.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

It's calling docking in English. Sticky windows are ones that are always on top.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8452
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

You shouldn't get any flicker from this one:

http://www.purebasic.fr/english/viewtop ... 51&start=3
BERESHEIT
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

Post by Joakim Christiansen »

Sweet, thanks! :D
I like logic, hence I dislike humans but love computers.
Post Reply