Kamis, 21 Agustus 2014

RE: [MS_AccessPros] widths and heights

 

Hi Stuart

Below are two functions (and a whole bunch of supporting code) to return you the width of the nav pane and the height of the ribbon (note that this includes the QAT and the title bar!)

Just call GetNavPaneWidth() and GetRibbonHeight()

All the best,
Graham

Copy and paste this code into a new module:
============== Start Code =================
Option Compare Database
Option Explicit

Private Const LOGPIXELSX    As Long = 88
Private Const LOGPIXELSY    As Long = 90

Private Const nTwipsPerInch As Long = 1440

Private dTwipsPerPixelX     As Double
Private dTwipsPerPixelY     As Double

Private Type winRECT
  Left As Long
  Top As Long
  Right As Long
  Bottom As Long
End Type

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

Private Declare Function GetDeviceCaps _
  Lib "gdi32" ( _
    ByVal hDC As Long _
  , ByVal nIndex As Long _
  ) As Long
 
Private Declare Function GetWindowRect _
  Lib "user32" _
  ( _
    ByVal hWnd As Long _
  , lpRect As winRECT _
  ) As Long

Private Declare Function FindWindowEx _
  Lib "user32" _
  Alias "FindWindowExA" ( _
    ByVal hWndParent As Long _
  , ByVal hwndChildAfter As Long _
  , ByVal lpszClass As String _
  , ByVal lpszWindow As String _
  ) As Long

Private Function TwipsPerPixelX() As Double
  If dTwipsPerPixelX = 0 Then GetScreenMetrics
  TwipsPerPixelX = dTwipsPerPixelX
End Function

Private Function TwipsPerPixelY() As Double
  If dTwipsPerPixelY = 0 Then GetScreenMetrics
  TwipsPerPixelY = dTwipsPerPixelY
End Function

Private Sub GetScreenMetrics()
Dim hDC As Long
  hDC = GetDC(0)
  dTwipsPerPixelX = nTwipsPerInch / GetDeviceCaps(hDC, LOGPIXELSX)
  dTwipsPerPixelY = nTwipsPerInch / GetDeviceCaps(hDC, LOGPIXELSY)
  hDC = ReleaseDC(0, hDC)
End Sub

Public Function GetRibbonHeight() As Long
' Return height of the Ribbon in twips
' Note that the result includes the QAT and the application title bar
Dim hWnd As Long, xRect As winRECT
  hWnd = FindWindowEx(hWndAccessApp, 0, "MsoCommandBarDock", "MsoDockTop")
  If hWnd <> 0 Then
    hWnd = FindWindowEx(hWnd, 0, "MsoCommandBar", "Ribbon")
  End If
  If hWnd = 0 Then
    MsgBox "Ribbon not found"
  Else
    If GetWindowRect(hWnd, xRect) = 0 Then
      MsgBox "Cannot determine Ribbon dimensions"
    Else
      With xRect
        GetRibbonHeight = (.Bottom - .Top) * TwipsPerPixelY
      End With
    End If
  End If
End Function

Public Function GetNavPaneWidth() As Long
' Return width of the Nav Pane in twips
Dim hWnd As Long, xRect As winRECT, dHeight As Double
  hWnd = FindWindowEx(hWndAccessApp, 0, "NetUINativeHWNDHost", "Navigation Pane Host")
  If hWnd = 0 Then
    MsgBox "Nav Pane not found"
  Else
    If GetWindowRect(hWnd, xRect) = 0 Then
      MsgBox "Cannot determine Nav Pane dimensions"
    Else
      With xRect
        GetNavPaneWidth = (.Right - .Left) * TwipsPerPixelX
      End With
    End If
  End If
End Function
================  End Code =========================

From: MS_Access_Professionals@stage.yahoogroups.com [mailto:MS_Access_Professionals@stage.yahoogroups.com]
Sent: Friday, 22 August 2014 13:42
To: MS_Access_Professionals@stage.yahoogroups.com
Subject: RE: [MS_AccessPros] widths and heights

 
Hi Stuart

Yes – that's what I meant by "the results stay the same …"

I'm just working on some code for you … watch this space :-)

Graham

 
From: MS_Access_Professionals@stage.yahoogroups.com [mailto:MS_Access_Professionals@stage.yahoogroups.com]
Sent: Friday, 22 August 2014 13:40
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] widths and heights

 
 
Hi, I tried this, maybe I am not understanding something.   NavPaneClosed returns 0 whether the Nav pane is there or not, and the width always shows 209, even when I change the width.   Am I missing something?
 
Regards, Stuart
 
On Thursday, August 21, 2014 7:40 PM, "'Graham Mandeno' graham@mandeno.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com> wrote:
 
 
Hi Crystal

Thank you!  I just learned about some more properties :-)

However … the results stay the same, whether I show/hide the nav pain, or change its width, or show/hide the search bar :-/

-- Graham

 
From: MS_Access_Professionals@yahoogroups.com [mailto:MS_Access_Professionals@yahoogroups.com]
Sent: Friday, 22 August 2014 11:29
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] widths and heights

 
 
Sub NavPane()
   With CurrentDb
      Debug.Print "Show Navigation Pane Search Bar = "; .Properties("Show Navigation Pane Search Bar")
      Debug.Print "NavPane Closed: "; .Properties("NavPane Closed")
      Debug.Print "NavPane Width: "; .Properties("NavPane Width")
   End With
End Sub

 
someone else can jump in on the ribbon part of your question ...
 
Warm Regards,
Crystal

Remote Programming & Training -- connect to me, let's build it together

 
Code Documenter for Access
http://www.accessmvp.com/strive4peace/CodeDocumenter.htm


Through sharing, we will all get better
~  have an awesome day ~

 

 

 

 

 

 

Crystal's Code Documenter
Download Crystal's Code Documenter Please send me your comments and ideas! This also documents MDB files. Watch for updates. Access 2007+ version Crystals_CodeDocumenter_120204_2p_BETA_ACCDE_TXT.zip

Preview by Yahoo

 

 
 
On Thursday, August 21, 2014 1:11 PM, "Stuart Schulman stoughy@yahoo.com [MS_Access_Professionals]" <MS_Access_Professionals@yahoogroups.com> wrote:
 
 
Is there any way (Access 2007) to determine the width of the navigation pane?  Or the height of the ribbon?
 
Thanks, Stuart
 
 
 
 


__._,_.___

Posted by: "Graham Mandeno" <graham@mandeno.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (8)

Yahoo Groups
Did you know?
Learn about editing tables within Groups


.

__,_._,___

Tidak ada komentar:

Posting Komentar