Access Main Window Size

P

Paradigm

I have some code that lets me size the main Access Window. I would like to
be able to find the size of the Window before and after resizing.
Does anyone know if this can be done and if so could you please let me know.
Alec
 
G

Graham R Seach

Alec,

Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Public Declare Function GetWindowRect Lib "user32" ( _
ByVal hWnd As Long, lpRect As RECT) As Long

Public Sub WhereIsMDIWindow(Cancel As Integer)
Dim RectMDI As RECT
Dim hWndMDI As Long

hWndMDI = FindWindowEx(Access.hWndAccessApp, _
0, "MDIClient", vbNullString)

GetWindowRect hWndMDI, RectMDI

MsgBox "Top: " & RectMDI.Top & vbCrLf & _
"Left: " & RectMDI.Left & vbCrLf & _
"Right: " & RectMDI.Right & vbCrLf & _
"Bottom: " & RectMDI.Bottom
End Sub

Regards,
Graham R Seach
Microsoft Access MVP
Canberra, Australia
 
G

Graham R Seach

Screen co-ordinates. In this case, pixels. :)

Regards,
Graham R Seach
Microsoft Access MVP
Canberra, Australia
---------------------------
 
P

Paradigm

I appreciate your help, thank you.
I have the code to read the window position and I have code to set the
position.
If I read the position and then reset the window using the same values, the
window seems to shift down and to the left. The shift down seems to be the
title bar of the window which is 94 pixels on my computer but will obviously
be different on other computers. The shift to the left seems to be about 4
pixels. The bottom of the window also moves up quit a bit.
Are the sizes returned the sizes that are need to set the window? What I am
trying to achieve is to get access window to open the size it was when it
was last closed. Since the user has other access applications and will
resize the window for them, I want the window for my application to open as
it was left.

The code I am using to resize the window is


Declare Sub SetWindowPos Lib "user32" (ByVal hWnd&, _
ByVal hWndInsertAfter&, _
ByVal X&, ByVal Y&, ByVal cX&, _
ByVal cY&, ByVal wFlags&)
------------------------
h = Application.hWndAccessApp
'Position Microsoft Access.
SetWindowPos h, HWND_TOP, WindowLeft4, WindowTop, WindowRight - WindowLeft,
WindowBottom - WindowTop , SWP_NOZORDER

where the window sizes are the values reurned by the function you gave me.

Alec
 
G

Graham R Seach

Alec,

Sorry, the co-ordinates are relative to the top-left of the MDI window. To
get the co-ordinates of the application window, try this:

Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Public Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Public Declare Function GetWindowRect Lib "user32" ( _
ByVal hWnd As Long, lpRect As RECT) As Long

Public Sub WhereIsAppWindow()
Dim RectApp As RECT
Dim hWndApp As Long

hWndApp = FindWindow("OMain", "Microsoft Access")
GetWindowRect hWndApp, RectApp

MsgBox "Top: " & RectApp.Top & vbCrLf & _
"Left: " & RectApp.Left & vbCrLf & _
"Right: " & RectApp.Right & vbCrLf & _
"Bottom: " & RectApp.Bottom
End Sub


Regards,
Graham R Seach
Microsoft Access MVP
Canberra, Australia
---------------------------
 
P

Paradigm

The code seems to keep the top and right positions but each time I run it
the forms gets wider and higher.
Top: 127;Left: 143;Right: 1755;Bottom: 1339
Top: 127;Left: 143;Right: 1666;Bottom: 1241
Top: 127;Left: 143;Right: 1523;Bottom: 1114
Top: 127;Left: 143;Right: 1380;Bottom: 987
Top: 127;Left: 143;Right: 1237;Bottom: 860
The debug.print shows the most recent run at the top. You can see the form
getting slightly larger each time.

The code I am using to set the window position is

Declare Sub SetWindowPos Lib "user32" (ByVal hWnd&, _
ByVal hWndInsertAfter&, _
ByVal X&, ByVal Y&, ByVal cX&, _
ByVal cY&, ByVal wFlags&)

SetWindowPos h, HWND_TOP, WindowLeft, WindowTop, WindowRight, WindowBottom,
SWP_NOZORDER

It may be this that is setting it larger when I use the same sizes read
using your code.

Alec
 
G

Graham R Seach

Specify no size changes:
SWP_NOZORDER Or SWP_NOSIZE

Regards,
Graham R Seach
Microsoft Access MVP
Canberra, Australia
---------------------------
 
P

Paradigm

Thanks, it is now setting the main window to the same size that was saved. I
have discovered another problem. When an access form is maximised inside the
main access window, the values saved for the main window are all zero. I
generally run with a form maximised. I am trying to get the main access
window to open at the same size it was when it was closed and save these
setting seperately for different access applications.
Alec
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top