I have an app where the user can set the windows to either the restored default setting or maximized. That setting is stored in a database and is displayed in a Textbox named txtWindowSize. I am using the code below to detect what the saved setting is.
[code] If txtWindowSize.Text=“Maximum” Then
frmContents.Maximize
End IF
If txtWindowSize.Text=“Default” Then
frmContents.Restore
End If[/code]
The problem is that when the window is already maximized and the code frmContents.Maximize is fired, it actually makes the window smaller returning it to the restored size.
So if the window is already maximized running the code frmContents.Maximize actually makes the window small again.
Is there a way I can detect whether the window is already maximized so I only run the code if the window is in the restored small state?
Sub DetermineWindowHeight(Extends MyWindow as Window)
If MyWindow.Bounds.Height >= MyWindow.GetScreen.AvailableHeight Then
Dim r as New REALbasic.Rect
r.Left = MyWindow.Bounds.Left
r.Height = MyWindow.GetScreen.AvailableHeight
r.Width = MyWindow.Bounds.Width
r.top = MyWindow.GetScreen.AvailableTop
MyWindow.Bounds = r
End Sub
Window.GetScreen is a method that determines which screen has the window.
So basically check if the bounds of the window are the same size as the AvailableHeight and AvailableWidth of the screen.
Thanks so much for taking the time to provide that code. I really appreciate it. I actually did find a simple solution that works fine. You create a string variable and assign what the current screen size is when you leave the window. When your return to the window the screen size will look at the variable and if it is different, it will maximize or minimize the window.
This is the code I used.
[code] If txtWindowSize.Text=“Maximum” Then
If CH=“Default” Then
frmContents.Maximize
End If
End IF
If txtWindowSize.Text=“Default” Then
frmContents.Restore
End If[/code]
The txtWindowSize text reads the current setting from the database and sets CH to the current value. When you return to the window this code will see whether the value stored in the CH variable is either Default or Maximize. If it is Default it will maximize it.
Function WhichScreen(W as window) As Integer
for i as integer = 0 to ScreenCount-1
if W.Left > Screen(i).Left and W.Left < Screen(i).Left+Screen(i).Width _
and W.Top > Screen(i).Top and W.Top < Screen(i).Top+Screen(i).Height then
return i
end if
next
End Function
If a window is across the boundaries of a screen, for instance between 0 and 1, what counts is the upper left corner of the window.
I have an app where the user can set the windows to either the restored default setting or maximized. That setting is stored in a database and is displayed in a Textbox named txtWindowSize. I am using the code below to detect what the saved setting is.
[code] If txtWindowSize.Text=“Maximum” Then
frmContents.Maximize
End IF
If txtWindowSize.Text=“Default” Then
frmContents.Restore
End If[/code]
The problem is that when the window is already maximized and the code frmContents.Maximize is fired, it actually makes the window smaller returning it to the restored size.
So if the window is already maximized running the code frmContents.Maximize actually makes the window small again.
Is there a way I can detect whether the window is already maximized so I only run the code if the window is in the restored small state?
[code]
Declare Function IsZoomed Lib “user32.dll” (ByVal hwnd As integer) As integer
Declare Function IsIconic Lib “user32.dll” (ByVal hwnd As integer) As integer
Dim IsMaximized as boolean = (IsZoomed(self.handle) <> 0)
Dim IsMinimized as boolean = (IsIconic(self.handle) <> 0)[/code]