In Windows use:
Code: Select all
Dim Shared As Long xWindow, yWindow
After window creation use something like:
Code: Select all
IF AfxFileExists(AfxGetExePath & "\Location.dat") Then
f = Freefile
Open AfxGetExePath & "\Location.dat" For Input As #f
Get #f, , xWindow
Get #f, , yWindow
Close #f
SetWindowPos( hDlg, HWND_TOPMOST, xWindow, yWindow, 0, 0, SWP_NOSIZE )
Else
pWindow.Center
SetWindowPos hDlg, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End If
I use José Roca's WinFBX and I am a topmost fanatic.
On your application's initial outing Location.dat won't exist, so it will get centred on the desktop.
Now position the window wherever you want it.
In the call back function trap WM_CLOSE and SC_CLOSE and use something like this:
Code: Select all
Dim As Long x, y, f
Dim rc As RECT
GetWindowRect( hDlg, @rc )
' If Window has moved then save current location
If xWindow <> rc.left Orelse yWindow <> rc.top Then
f = Freefile
Open AfxGetExePath & "\Location.dat" For Output As #f
Put #f, , rc.left
Put #f, , rc.top
Close #f
End If
For second and subsequent application sessions, your window will be located at the last saved location.
Notice that xWindow and yWindow are Longs. I have a secondary monitor and a lot of my applications open on that.