Page 1 of 1
DesktopX() DesktopY()
Posted: Sat Jan 05, 2008 11:40 pm
by blueznl
... to return the x,y coordinates of the origin of a desktop (ie. screen / monitor)
(Think I've asked this one before, the reason it pops up again is I'm rewriting some old programs, and I was trying to remove as much winapi as possible, but I have no alternative for this one...)
Posted: Sun Jan 06, 2008 1:43 am
by Mistrel
I'm not sure I understand this request. Can you explain how DesktopX() and DesktopY() would function?
Posted: Mon Jan 07, 2008 6:00 am
by Tranquil
Mistrel wrote:I'm not sure I understand this request. Can you explain how DesktopX() and DesktopY() would function?
I think he means the X Position of another connected screen. If you have two monitors connected to your GFX Card you are able to expand your desktop to the right or left side. (Maybe even uppon your actual desktop, did not tried this). In this cases you will have coordinates beyond your actual primary desktop display.
i want this too
Posted: Mon Apr 13, 2009 1:12 pm
by jayagopal
ya, i'm gonna have to figure out how to do this with WinAPI. those would be great functions.
i want to keep a particular hindi/sanskrit dictionary program fully visible on one monitor (either monitor) depending on where the user clicks (on a word in another program):
Code: Select all
x=DesktopMouseX()
y=DesktopMouseY()+20
numDesks=ExamineDesktops()
DW=DesktopWidth(0)
DH=DesktopHeight(0)
If numDesks>1
If x>DW
DW=DW+DesktopWidth(1)
DH=DesktopHeight(1)
ElseIf x<0
DW=0
DH=DesktopHeight(1)
EndIf
EndIf
If x+800>DW: x=DW-800: EndIf
If y+231>DH: y=y-231-40: EndIf
ResizeWindow(#mainWindow, x, y, 600, 231)
ResizeWindow(#defViewer, x+600, y, 200, 231)
the problem is, on the second monitor (currently to the left of the primary), the x range is from [-1280 to 0] and the y range is from [-224 to 800], so i can't easily decide when my window will go off the bottom of the screen (which has a DesktopHeight of 1024 but a max y value of 800).
so DesktopX(0) and DesktopY(0) will always = 0
but in my case, DesktopX(1) will return -1280 and DesktopY(1) will return -224. had it been on the right side DesktopX(1) would return 1280 (my primary is 1280x800, so the secondary starts on its right edge).
when (if) i find the WinAPI for this i'll post it.
Posted: Mon Apr 13, 2009 1:20 pm
by jayagopal
Posted: Tue Apr 14, 2009 12:06 am
by Rescator
http://www.purebasic.fr/english/viewtop ... 2&start=21
That's the solution you actually need in this case and which is a very popular behavior in one of my programs. (the users love it)
Ideally every GUI program out there should do this but alas they do not.
Posted: Thu Apr 16, 2009 10:27 am
by jayagopal
what poshu has made available (
http://www.purebasic.fr/english/viewtop ... n&start=19) is the really really good way to do it. the following method is far less robust.
GetSystemMetrics_(#SM_XVIRTUALSCREEN) is the originX of the entire work-area, of all connected monitors... use Y for originY.
and
GetSystemMetrics_(#SM_CXVIRTUALSCREEN) is the width of the entire work-area... use Y for height
so if you expect more than 2 monitors, and want proper info about them, use poshu's. if you just want a clean way to get the x&y origin and you know there are only 2 monitors (and it is pretty rare to have more than 2), then use this method.
here's an example:
Code: Select all
;This will work only if there are exactly two monitors
numDesks=ExamineDesktops()
If numDesks=2
Debug "Desktop #0:"
Debug "OriginX = 0"
Debug "OriginY = 0"
Debug "WidthX = "+Str(DesktopWidth(0))
Debug "WidthY = "+Str(DesktopHeight(0))
Debug ""
Debug "Desktop #1:"
Debug "OriginX = "+Str(GetSystemMetrics_(#SM_XVIRTUALSCREEN))
Debug "OriginY = "+Str(GetSystemMetrics_(#SM_YVIRTUALSCREEN))
Debug "WidthX = "+Str(DesktopWidth(1))
Debug "WidthY = "+Str(DesktopHeight(1))
Else
Debug "Desktop #0:"
Debug "OriginX = 0"
Debug "OriginY = 0"
Debug "WidthX = "+Str(DesktopWidth(0))
Debug "WidthY = "+Str(DesktopHeight(0))
EndIf
hare krsna!
Posted: Thu Apr 16, 2009 11:17 am
by freak
You do realize that PB 4.30 has a DesktopX/Y() function, right ?
rtfm!

Posted: Thu Apr 16, 2009 1:22 pm
by jayagopal
no i didnt realize that
i have 4.10
--------------
edit: now i have 4.30... low and behold: DesktopX/Y(). that's really useful
the PB developers are one of the few remaining good things about this world.