Access Main window's size

P

Patrick386

Hello!

Is there a way to get the main Access window's position and size compared to the screen display?

Thanks in advance for any suggestion.
 
P

Pieter Wijnen

Slight mod of this should do it

Public Const WU_SW_RESTORE = 9
Public Const WU_SW_MAXIMIZE = 3
Public Const WU_SW_MINIMIZE = 2
Public Const WU_SW_SHOWNORMAL = 1
Public Const WU_SW_HIDE = 0

Public Type WU_RECT
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type

Public Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, ByVal X As Long, ByVal Y As Long, ByVal dx As Long, ByVal dy As Long, ByVal fRepaint As Long) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal NewState As Long) As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, R As WU_RECT) As Long
Public Declare Function GetDesktopWindow Lib "user32" () As Long

Public Function SetAccessSize(Optional ByVal dx As Long = 1024, Optional ByVal dy As Long = 768) As Long
' Set Size of Access & Center on Screen
Const X = 0, Y = 0
Dim hWnd As Long, F As Long
Dim RDesk As WU_RECT

On Local Error Resume Next

hWnd = Application.hWndAccessApp
If (IsZoomed(hWnd)) Then
ShowWindow hWnd, WU_SW_RESTORE
End If
GetWindowRect GetDesktopWindow(), RDesk
If ((RDesk.x2 - RDesk.x1) - (dx - X) < 0) Or ((RDesk.y2 - RDesk.y1) - (dy - Y)) < 0 Then
' Screen Size To Small
MoveWindow hWnd, RDesk.x1, RDesk.y1, RDesk.x2, RDesk.y2, True
F = False
Else
MoveWindow hWnd, RDesk.x1 + ((RDesk.x2 - RDesk.x1) - dx) / 2, RDesk.y1 + ((RDesk.y2 - RDesk.y1) - dy) / 2, dx, dy, True
F = True
End If
SetAccessSize = F
End Function

Pieter
Hello!

Is there a way to get the main Access window's position and size compared to the screen display?

Thanks in advance for any suggestion.
 
P

Patrick386

Thanks for your response!
but the code you gave me sets the main Access Window... and I am looking to get its actual position.
I cannot reposition the window otherwise I'll disturbe the user's interface

Any idea of other functions that can give the window's position?

Thanks again
"Pieter Wijnen" <it.isi.llegal.to.send.unsollicited.mail.wijnen.nospam.please@online.replace.with.norway> a écrit dans le message de news: (e-mail address removed)...
Slight mod of this should do it

Public Const WU_SW_RESTORE = 9
Public Const WU_SW_MAXIMIZE = 3
Public Const WU_SW_MINIMIZE = 2
Public Const WU_SW_SHOWNORMAL = 1
Public Const WU_SW_HIDE = 0

Public Type WU_RECT
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type

Public Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, ByVal X As Long, ByVal Y As Long, ByVal dx As Long, ByVal dy As Long, ByVal fRepaint As Long) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal NewState As Long) As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, R As WU_RECT) As Long
Public Declare Function GetDesktopWindow Lib "user32" () As Long

Public Function SetAccessSize(Optional ByVal dx As Long = 1024, Optional ByVal dy As Long = 768) As Long
' Set Size of Access & Center on Screen
Const X = 0, Y = 0
Dim hWnd As Long, F As Long
Dim RDesk As WU_RECT

On Local Error Resume Next

hWnd = Application.hWndAccessApp
If (IsZoomed(hWnd)) Then
ShowWindow hWnd, WU_SW_RESTORE
End If
GetWindowRect GetDesktopWindow(), RDesk
If ((RDesk.x2 - RDesk.x1) - (dx - X) < 0) Or ((RDesk.y2 - RDesk.y1) - (dy - Y)) < 0 Then
' Screen Size To Small
MoveWindow hWnd, RDesk.x1, RDesk.y1, RDesk.x2, RDesk.y2, True
F = False
Else
MoveWindow hWnd, RDesk.x1 + ((RDesk.x2 - RDesk.x1) - dx) / 2, RDesk.y1 + ((RDesk.y2 - RDesk.y1) - dy) / 2, dx, dy, True
F = True
End If
SetAccessSize = F
End Function

Pieter
Hello!

Is there a way to get the main Access window's position and size compared to the screen display?

Thanks in advance for any suggestion.
 
P

Pieter Wijnen

Use GetWindowRect on The Application.hWndAccessApp

Pieter
Thanks for your response!
but the code you gave me sets the main Access Window... and I am looking to get its actual position.
I cannot reposition the window otherwise I'll disturbe the user's interface

Any idea of other functions that can give the window's position?

Thanks again
"Pieter Wijnen" <it.isi.llegal.to.send.unsollicited.mail.wijnen.nospam.please@online.replace.with.norway> a écrit dans le message de news: (e-mail address removed)...
Slight mod of this should do it

Public Const WU_SW_RESTORE = 9
Public Const WU_SW_MAXIMIZE = 3
Public Const WU_SW_MINIMIZE = 2
Public Const WU_SW_SHOWNORMAL = 1
Public Const WU_SW_HIDE = 0

Public Type WU_RECT
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type

Public Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, ByVal X As Long, ByVal Y As Long, ByVal dx As Long, ByVal dy As Long, ByVal fRepaint As Long) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal NewState As Long) As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, R As WU_RECT) As Long
Public Declare Function GetDesktopWindow Lib "user32" () As Long

Public Function SetAccessSize(Optional ByVal dx As Long = 1024, Optional ByVal dy As Long = 768) As Long
' Set Size of Access & Center on Screen
Const X = 0, Y = 0
Dim hWnd As Long, F As Long
Dim RDesk As WU_RECT

On Local Error Resume Next

hWnd = Application.hWndAccessApp
If (IsZoomed(hWnd)) Then
ShowWindow hWnd, WU_SW_RESTORE
End If
GetWindowRect GetDesktopWindow(), RDesk
If ((RDesk.x2 - RDesk.x1) - (dx - X) < 0) Or ((RDesk.y2 - RDesk.y1) - (dy - Y)) < 0 Then
' Screen Size To Small
MoveWindow hWnd, RDesk.x1, RDesk.y1, RDesk.x2, RDesk.y2, True
F = False
Else
MoveWindow hWnd, RDesk.x1 + ((RDesk.x2 - RDesk.x1) - dx) / 2, RDesk.y1 + ((RDesk.y2 - RDesk.y1) - dy) / 2, dx, dy, True
F = True
End If
SetAccessSize = F
End Function

Pieter
Hello!

Is there a way to get the main Access window's position and size compared to the screen display?

Thanks in advance for any suggestion.
 
P

Patrick386

Great thanks for your help!
Best regards
"Pieter Wijnen" <it.isi.llegal.to.send.unsollicited.mail.wijnen.nospam.please@online.replace.with.norway> a écrit dans le message de news: (e-mail address removed)...
Use GetWindowRect on The Application.hWndAccessApp

Pieter
Thanks for your response!
but the code you gave me sets the main Access Window... and I am looking to get its actual position.
I cannot reposition the window otherwise I'll disturbe the user's interface

Any idea of other functions that can give the window's position?

Thanks again
"Pieter Wijnen" <it.isi.llegal.to.send.unsollicited.mail.wijnen.nospam.please@online.replace.with.norway> a écrit dans le message de news: (e-mail address removed)...
Slight mod of this should do it

Public Const WU_SW_RESTORE = 9
Public Const WU_SW_MAXIMIZE = 3
Public Const WU_SW_MINIMIZE = 2
Public Const WU_SW_SHOWNORMAL = 1
Public Const WU_SW_HIDE = 0

Public Type WU_RECT
x1 As Long
y1 As Long
x2 As Long
y2 As Long
End Type

Public Declare Function IsZoomed Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, ByVal X As Long, ByVal Y As Long, ByVal dx As Long, ByVal dy As Long, ByVal fRepaint As Long) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hWnd As Long, ByVal NewState As Long) As Long
Public Declare Function GetWindowRect Lib "user32" (ByVal hWnd As Long, R As WU_RECT) As Long
Public Declare Function GetDesktopWindow Lib "user32" () As Long

Public Function SetAccessSize(Optional ByVal dx As Long = 1024, Optional ByVal dy As Long = 768) As Long
' Set Size of Access & Center on Screen
Const X = 0, Y = 0
Dim hWnd As Long, F As Long
Dim RDesk As WU_RECT

On Local Error Resume Next

hWnd = Application.hWndAccessApp
If (IsZoomed(hWnd)) Then
ShowWindow hWnd, WU_SW_RESTORE
End If
GetWindowRect GetDesktopWindow(), RDesk
If ((RDesk.x2 - RDesk.x1) - (dx - X) < 0) Or ((RDesk.y2 - RDesk.y1) - (dy - Y)) < 0 Then
' Screen Size To Small
MoveWindow hWnd, RDesk.x1, RDesk.y1, RDesk.x2, RDesk.y2, True
F = False
Else
MoveWindow hWnd, RDesk.x1 + ((RDesk.x2 - RDesk.x1) - dx) / 2, RDesk.y1 + ((RDesk.y2 - RDesk.y1) - dy) / 2, dx, dy, True
F = True
End If
SetAccessSize = F
End Function

Pieter
Hello!

Is there a way to get the main Access window's position and size compared to the screen display?

Thanks in advance for any suggestion.
 

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