I have a method that creates a new instance of a window, and gets the stored .top and .left values from a database.
Dim W As winSelectCo
W=New winSelectCo
W.Show
dim varTop as integer = 100 ' dim the vars and set default values
dim varLeft as integer = 171
dim varWidth as integer = 650
dim varHeight as integer = 450
if not Keyboard.ShiftKey then '' if Shift is used, then the default values above are used, otherwise get values from database
varTop = GetUserVarI (1) '' have checked, this returns 120
varLeft = GetUserVarI (2) '' this returns 240
varWidth = GetUserVarI (3) '' this returns 150
varHeight = GetUserVarI (4) '' this returns 150
end if
W.top = varTop
W.left = varLeft
W.width = varWidth
W.height = varHeight
In the Open event of the new instance, used to hide the window from the taskbar :
#if TargetWin32 Then
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Int32, ByVal nIndex As Int32, ByVal dwNewLong As Int32) As Int32
Const GWL_EXSTYLE = -20
Const WS_EX_TOOLWINDOW = &H80
Call SetWindowLong(Self.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW)
#endif
... rest of code for open event does not affect top, left, etc
Every time that I run the code and the new window is created, the .top value = 116 ( 120 - 4 )
If I change the database content to return any other number, the actual top of the new window is ALWAYS less 4.
Very odd, and been trying to find the cause for a few hours.
So eventually I comment out to Declare Function SetWindowLong code in the new instance open event, and now the top of the new window is exactly as it should be - the value retrieved from the database.
Anyone able to explain why this SetWindowLong call would affect the top of a window ?
Xojo are making certain assumptions about the window based on its Frame property. You’re changing that without letting them know. Once you start using declares to modify the window, you pretty much need to use declares for everything.
OK. For now I have fiddled a work-around. Not elegent, and most certainly not ‘correct’, but …
I know from experience that the declares reduces the top of the window by 4 ( on my PC anyway )
4 is not a big number, and really does not affect my app, except when I save the .top in the window close method to my database for next time the window is opened.
So I have decided to only save the new .top value if the .top has changed by more than 10.
' only save the new .top value if it has changed by more than 10 compared to the value in the database
dim varTop as integer
varTop = Abs(self.top - GetUserVarI (1)) ' GetUserVarI(1) gets the integer value of 'user setting # 1' from the database
if varTop > 10 then SetUserVar (1,self.top) ' updates the database 'user setting # 1' with the integer self.top
[quote=110966:@Michel Bujardet]Got it :)
Set the window as invisible in the inspector, then do :
Sub Open()
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (hWnd As integer, nIdex As integer, dwNewLong As Integer) As Integer
DIM t_result As Integer = SetWindowLong(self.Handle, -20,&h80)
me.visible = true
End Sub
The taskbar icon never shows :)[/quote]
Unfortunately, that is essentially what I already have in the original post, and although it works very well at hiding the window from the Windows Taskbar, it does reduce the top of the window by 4.
I have copy / pasted your code as it is coded slightly differently, but the result is unchanged.
[code=110966:@Michel Bujardet]Got it
Set the window as invisible in the inspector, then do :
Sub Open()
Declare Function SetWindowLong Lib “user32” Alias “SetWindowLongA” (hWnd As integer, nIdex As integer, dwNewLong As Integer) As Integer
DIM t_result As Integer = SetWindowLong(self.Handle, -20,&h80)
me.visible = true[/code]
Unfortunately, that is essentially what I already have in the original post, and although it works very well at hiding the window from the Windows Taskbar, it does reduce the top of the window by 4.
I have copy / pasted your code as it is coded slightly differently, but the result is unchanged.[/quote]
I just tried this code again, there is no change whatsoever in the top of the window, whether I place the code in a button on in the Open event. Of course, I use a plain out of the box window created in the IDE. Would the issue be in the code you use to create the window ?
Will, so you SO clever. I was thinking inside the box. You were looking from the outside.
Thank You.
Dim W As winSelectCo
W=New winSelectCo
dim varTop as integer = 81
dim varLeft as integer = 146
dim varWidth as integer = 650
dim varHeight as integer = 450
if not Keyboard.ShiftKey then
varTop = GetUserVarI (1)
varLeft = GetUserVarI (2)
varWidth = GetUserVarI (3)
varHeight = GetUserVarI (4)
end if
Dim myBounds As New Realbasic.Rect
myBounds.Top = varTop
myBounds.Left = varLeft
myBounds.Height = varHeight
myBounds.Width = varWidth
W.Bounds = myBounds
W.Show
But as you pointed out before, we have moved outside the confines of Xojo, and into windows, so now there is a lot more than just the Xojo IDE / framework that can affect this. Windows version, service pack, individual PC flavor settings and personalization, etc.
So many options that there is little guarantee of reproducing this on other PCs on a consistent basis.
As above, I have tried Wills’ idea and that is working good for me. A ‘solution’ about as good as it can get for this problem.
But as you pointed out before, we have moved outside the confines of Xojo, and into windows, so now there is a lot more than just the Xojo IDE / framework that can affect this. Windows version, service pack, individual PC flavor settings and personalization, etc.
So many options that there is little guarantee of reproducing this on other PCs on a consistent basis.
As above, I have tried Wills’ idea and that is working good for me. A ‘solution’ about as good as it can get for this problem.[/quote]
I do that often : use declares or JavaScript, and then turn around and back to Xojo to correct the fine points