multiple monitors

Share your advanced PureBasic knowledge/code with the community.
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post by Rescator »

A better solution might be to just fetch the work area instead (code elsewhere on the forum how to find this out) if you really need to.

One of my apps does something really cool after the user has moved the window: http://www.purebasic.fr/english/viewtopic.php?t=29652

This ensures that the window is "snapped" (clipped) to the nearest monitor and position that is visible in the case the window or a part of it is outside the visible monitor.
Different sized monitors and resolution is no problem either, the API handles most of the magic.
I believe it will also "snap" a window that is partially across 2 or more monitors, snapping it to the side/corner of the monitor with the most of the window in it.

Code like that should really be a MUST in all applications, I'm kinda surprised this isn't enforced by default in Windows (would make so much more sense to only allow manual override instead) oh well.

Thanks to that snapping feature my program is happily oblivious to the concept of multiple monitors/displays and even work area. (if moved over the taskbar it will "snap" to the the edge of it instead,, sweet).
And another benefit is in the cases where the app was on a 2nd monitor last time, but next time it's started the 2nd monitor is not hooked up or it's work area has changed, in which case that snap procedure will make the "lost" window appear again.

Try with the values:
x=-300
y=-800

In the 2nd example in that thread this will make the window appear to the left and up from pos 0,0 (top left of monitor 0) and then snap it to the nearest visible work area. Brilliant ;)

Would be really cool if PB had a new openwindow flag along the lines #PB_Window_SnapToWorkArea or something like that would do this automatically. Not sure if a similar API exist on Linux or Mac though.

PS! The 2nd example in that thread should work well with the fancy new Vista sidebar as well, and with custom placements of the taskbar as well.
jayagopal
User
User
Posts: 35
Joined: Thu Oct 02, 2008 11:22 am
Location: india

Post by jayagopal »

poshu: thanks! that works perfectly:

monitor 1
primary display
name \\.\DISPLAY1
handle 65537
pos x 0
pos y 0
width 1280
height 800
depth 32
refresh 60

monitor 2
name \\.\DISPLAY2
handle 0
pos x -1281
pos y -233
width 1280
height 1024
depth 32
refresh 60
Post Reply