App runs on #Desktop?
App runs on #Desktop?
Is there a way to find out the specific desktop an application is running on if a user has multiple desktops? This seems useful if one is to examine the minimum allowed resolution for one's app...
Any insight greatly appreciated
Frank
Any insight greatly appreciated
Frank
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
Re: App runs on #Desktop?
Use the Desktop lib in PB. If you subtract the y pos from desktopweigth without negative you are on second desktop, and so on 

Re: App runs on #Desktop?
You mean desktopheight?
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
Re: App runs on #Desktop?
desktop width!
Code: Select all
Res. 16:10
1680 * 1050
Desktop Primary 1 Secundary 2 ... 3
-----------------------------------------------------
| |
0 - 1679 | 1680 - 3359 | 3360 -
| |
------------------------------------------------------
Re: App runs on #Desktop?
Ah, so if the first desktop has width 1440, where X = 0, then the second desktop's X will be 1440, right?
Edit: right, you just added the answer to my question... Thankx!
Edit: right, you just added the answer to my question... Thankx!
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
Re: App runs on #Desktop?
You are assuming that the monitors are all next to each other (with the primary one on the left), but that does not have to be the case.
You should use DesktopX() and DesktopY() so it will work with all possible configurations.
You should use DesktopX() and DesktopY() so it will work with all possible configurations.
quidquid Latine dictum sit altum videtur
Re: App runs on #Desktop?
but how can i test which desktop, if the user moves the window to secondary?
I can only use WindowX(0), and this give me a value like my description above.
The primary is not always on the left, but the values of WindowX(0) works in this way!
I can only use WindowX(0), and this give me a value like my description above.
The primary is not always on the left, but the values of WindowX(0) works in this way!
Re: App runs on #Desktop?
All coordinates in PB are "virtual screen coordinates". This means they are relative to the top/left corner of the primary monitor, even if you are on another monitor. DesktopX/DesktopY tells you the location of the monitors in these coordinates as well. (so its the location of the top/left corner of the specified monitor in relation to the primary one.
See here about the virtual screen: http://msdn.microsoft.com/en-us/library/dd145136.aspx
Example:
This will work with any monitor configuration.
See here about the virtual screen: http://msdn.microsoft.com/en-us/library/dd145136.aspx
Example:
Code: Select all
Procedure DesktopFromPoint(x, y)
Count = ExamineDesktops()
For i = 0 To Count-1
dx = DesktopX(i)
dy = DesktopY(i)
dw = DesktopWidth(i)
dh = DesktopHeight(i)
If x >= dx And x <= dx+dw And y >= dy And y <= dy+dh
ProcedureReturn i
EndIf
Next i
ProcedureReturn -1 ; point is outside of all monitors
EndProcedure
OpenWindow(0, 100, 100, 200, 50, "Monitor check", #PB_Window_SystemMenu)
TextGadget(0, 10, 10, 180, 25, "Window is on Desktop: " + Str(DesktopFromPoint(WindowX(0), WindowY(0))))
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
Case #PB_Event_MoveWindow
SetGadgetText(0, "Window is on Desktop: " + Str(DesktopFromPoint(WindowX(0), WindowY(0))))
EndSelect
ForEver
quidquid Latine dictum sit altum videtur
Re: App runs on #Desktop?
Nice code, thanks
Re: App runs on #Desktop?
On the sideline, would it not be more optimal to code:freak wrote:Code: Select all
If x >= dx And x <= dx+dw And y >= dy And y <= dy+dh ProcedureReturn i EndIf
Code: Select all
If x >= dx
If x <= dx+dw
If y >= dy
If y <= dy+dh
ProcedureReturn i
EndIf
EndIf
EndIf
EndIf
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)
Re: App runs on #Desktop?
You wouldn't have to do that because the complier uses shortcut evaluation. It will only evaluate all the conditions if each one is successively and sequentially true.Frarth wrote:On the sideline, would it not be more optimal to code:freak wrote:Code: Select all
If x >= dx And x <= dx+dw And y >= dy And y <= dy+dh ProcedureReturn i EndIf
This would be the case if the compiler were to examine all conditions, even if the first fails.Code: Select all
If x >= dx If x <= dx+dw If y >= dy If y <= dy+dh ProcedureReturn i EndIf EndIf EndIf EndIf
Re: App runs on #Desktop?
Yes, both are equivalent, so the shorted the better 

Re: App runs on #Desktop?
Thanks for elaborating on this!
Frank
Frank
PureBasic 5.41 LTS | Xubuntu 16.04 (x32) | Windows 7 (x64)