Peter
Wed Jul 23 11:54:07 PDT 2008
Works great thank you! I have one more problem: The system.verticalResolution
function gives the entire screen's vertical dimensions. I now have to
subtract the space taken up by the Windows taskbar. This needs to be obtained
from the system as well (not hard-coded) because I use two rows for my
Windows Taskbar on my desktop but only one on my laptop. Do you have code to
determine the location and size of the Windows Taskbar?
Thanks,
Peter
"Jonathan West" wrote:
>
> "Peter" <Peter@discussions.microsoft.com> wrote in message
> news:2545A221-CC1B-41B8-9006-74A1F7C03780@microsoft.com...
> > I've got some macros for positioning and sizing the word window but
> > currently
> > am using hard coded numbers for width, height, left and top parameters.
> > These
> > numbers were obtained empirically for my desktop. When I take documents to
> > my
> > laptop with different screen dimensions, these macros do not produce the
> > intended effect.
> >
> > I am simply asking how I can determine the screen dimensions and how they
> > relate to the word window. It appears I may have to take title bars and
> > word
> > task bar into account. I was wondering if anyone has either figured this
> > all
> > out or better yet has code that does this.
>
> System.HorizontalResolution and System.VerticalResolution will give you the
> number of pixels on the screen in each direction. Unfortunately, this is not
> quite enough, and you also need to know the points-per-pixel ratio in each
> direction, as UserForm sizes and positions are determined in points, not
> pixels. This ratio varies according to the screen resolution and the system
> font size settings in Windows.
>
> Place the following code in a separate module, and you will have available
> functions PixelsPerInchX and PixelsPerInchY, which will allow you to make
> conversions as needed. You may need to adjust the code to remove line
> breaks.
>
>
> ' Device capabilities
> Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hDC As Long, ByVal
> nIndex As Long) As Long
> Private Const LOGPIXELSY = 90 ' Logical pixels/inch in Y
> Private Const LOGPIXELSX = 88 ' Logical pixels/inch in X
>
> ' Used to obtain screen device context
> Private Declare Function GetDesktopWindow Lib "user32" () As Long
> Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
> Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal
> hDC As Long) As Long
>
> Public Function PixelsPerInchX() As Long
> Dim hWnd As Long
> Dim hDC As Long
> ' Retrieves the number of pixels per logical
> ' inch in the X-direction on screen.
> hWnd = GetDesktopWindow()
> hDC = GetDC(hWnd)
> PixelsPerInchX = GetDeviceCaps(hDC, LOGPIXELSX)
> Call ReleaseDC(hWnd, hDC)
> End Function
>
> Public Function PixelsPerInchY() As Long
> Dim hWnd As Long
> Dim hDC As Long
> ' Retrieves the number of pixels per logical
> ' inch in the Y-direction on screen.
> hWnd = GetDesktopWindow()
> hDC = GetDC(hWnd)
> PixelsPerInchY = GetDeviceCaps(hDC, LOGPIXELSY)
> Call ReleaseDC(hWnd, hDC)
> End Function
>
> The code above is adapted from Karl Peterson's NCMetrics class module,
> available on his site
http://vb.mvps.org. That site is full of useful little
> routines for this sort of thing. Originally written in and for VB6, large
> parts of his code can be dropped into VBA projects unmodified, and the site
> indicates which of his code samples have been checked for VBA compatibility.
> A very useful resource, I use stuff from his site all the time.
>
>
> --
> Regards
> Jonathan West - Word MVP
> www.intelligentdocuments.co.uk
> Please reply to the newsgroup
>
>
>