DesktopX() DesktopY()

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

DesktopX() DesktopY()

Post 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...)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Post by Mistrel »

I'm not sure I understand this request. Can you explain how DesktopX() and DesktopY() would function?
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post 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.
Tranquil
jayagopal
User
User
Posts: 35
Joined: Thu Oct 02, 2008 11:22 am
Location: india

i want this too

Post 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.
jayagopal
User
User
Posts: 35
Joined: Thu Oct 02, 2008 11:22 am
Location: india

Post by jayagopal »

User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post 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.
jayagopal
User
User
Posts: 35
Joined: Thu Oct 02, 2008 11:22 am
Location: india

Post 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!
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

You do realize that PB 4.30 has a DesktopX/Y() function, right ?

rtfm! :P
quidquid Latine dictum sit altum videtur
jayagopal
User
User
Posts: 35
Joined: Thu Oct 02, 2008 11:22 am
Location: india

Post by jayagopal »

no i didnt realize that :shock:

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.
Repeat this sequence out loud:
*say hare krishna twice
*then say krishna twice
*then say hare twice
*then do the whole thing with rama instead of krishna
if you do this correctly, a representative will appear with further instructions
Post Reply