I want to be able to save my window settings so they reset to the same location and mode on a relaunch. I can save the Top/Left/Height/Width, I can even save if the window was set to FullScreen, but how can I determine the Screen number that the window is on?
Of course, I am assuming a multi-screen desktop environment with the main screen being Screen(0). How can I determine if the window has been moved to, say, Screen(1)?
They don’t always. Depending on the user’s display layout, Screen 1 could be to the left of screen 0 and the x coordinates could be negative. Make sure you take that into account.
Indeed values could be negative but the principle remains. If he saves left and top negative values and the supplementary screen is still attached, the window will be reinstated at the same place.
Previously, I was not storing the screen coordinates with negative values, but now I am it works. On restoring I need to check if the screen was set to FullScreen (i.e. Top = 0) and not adjust the Top otherwise the window restores with the titlebar hidden by MenuBar. It’s working and restores to the relevant screen (left or right) and in FullScreen/Normal mode.
I’m finding it a pain when Apps such as Skype don’t restore to the same screen settings on launch, and similarly don’t want to upset my users.
I need to find out what screen my window is on so I can correctly calculate the screen available height. I have a control that shows a drop down list. I need to calculate the edge of the screen where the control is so I use all the available space without the list going off screen. I know it’s possible because in Xojo the auto complete list functions in this way.
[quote=336781:@Neil Burkholder]I know this is an old thread but…
I need to find out what screen my window is on so I can correctly calculate the screen available height. I have a control that shows a drop down list. I need to calculate the edge of the screen where the control is so I use all the available space without the list going off screen. I know it’s possible because in Xojo the auto complete list functions in this way.[/quote]
Actually, the OS does this for you. It’s part of the internal function of a PopupMenu or ContextualMenu.
Yeah except that I’m using a widow with a listbox inside it. And I’m pretty sure the autocomplete list in the IDE is a window with a ListBox and not a PopupMenu or ContextualMenu.
That said, can’t you figure that out by looking at the x and y coordinate of the window and figuring out which screen coordinates it fits into? Only screen(0) starts at 0,0. Screens above and to the left have a negative origin and below or to the right have an origin > 0.
Public Function WhichScreen(x as integer, y as integer) as integer
for i as integer = 0 to ScreenCount
if x >= Screen(i).left and x <= screen(i).width and _
y >= screen(i).top and y <= screen(i).height then
return i
end if
next
End Function
I actually wrote one but didn’t have time to post back yet.
On small flaw in your code. It didn’t account for screens with a left or top <> 0.
Public Function WhichScreen(x as integer, y as integer) as integer
for i as integer = 0 to ScreenCount
if x >= Screen(i).left and x <= screen(i).width + Screen(i).left and _
y >= screen(i).top and y <= screen(i).height + screen(i).top then
return i
end if
next
End Function
If I had stored a value from a multiple monitor setup, and then when I restarted my program, the second monitor was not active, I would get an error message there.
Hey guys, I’m thinking a good, simpler, solution is to open the window on the user’s current Active, Front Most Screen (which is NOT necessarily the “Main” screen). Anyone know how to determine the Active Screen?