Powerpoint 2010 - vba - embedded control coordinates

Răspuns Powerpoint 2010 - vba - embedded control coordinates

  • 15 mai 2012 05:07
     
     

    Hi

    >> I am after the translation of units to pixels  or where in the VBA slide of a msoOLEControlObject object, has the top left pixel values ?

    e.g. in the object i can get the offsetWidth (document.body) and height in pixels. This seems to be true.
    However the units for left, top of the embedded control are float numbers like 48.25, 83.5

    Now using Spy++ the pixel values of the top left of the control in a full screen are 128, 283. You can see that even if you scale 48.25, this isn't the same scale ratio as the 83.5.

    I am guessing some part of the object model has either the pixels or the correct scaling.

    Thanks

Toate mesajele

  • 16 mai 2012 02:30
    Moderator
     
     

    Hi Greg,

    Thanks for posting in the MSDN Forum.

    I don't know how to measure the top, left property of the Shape, how ever I noticed that the Slide's Width is 720 and Height is 540. If you set 720 to Left, 540 to Top of the shape, the shape will just out of the slide's visible range. Angle on the angle. If you can know offsetWidth of the Slide I think you will easy to know how to measure the top and left.

    Have  a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

  • 16 mai 2012 08:07
     
     

    Thanks Tom but what you have suggested does not resolve the issue.

    Two issues as outlined above and why this is the case :

    - Coordinates from object do not correspond with actual pixel values in full screen (and likely windowed mode)
    - I need the top, left pixel and the values in the object do not map to the pixel locations or width in pixels

                    Set theObject = oShape.OLEFormat.Object
                    oLeft = theObject.Left
                    oTop = theObject.Top
                    oWidth = theObject.Width
                    oHeight = theObject.Height
                    theObject.Navigate (url)
                   Debug.Print "oLeft " & oLeft; " Top " & oTop & " Width " & oWidth & " Height " & oHeight

    >> There is a missing "X' from the doco which maps the values to true screen pixels

    Regards Greg

  • 17 mai 2012 02:28
    Moderator
     
     

    Hi Greg,

    OK, I will involve some experts into this issue the see whether them can help  you. There might be some time delay, thanks for your patience.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

  • 18 mai 2012 06:48
     
     

    Hi Greg,

    I have a few questions, what PowerPoint build and operating system are you running? Also what is your overall reason and objective in you acquiring the top left pixel value for an ole object? In very general terms what are you trying to achieve. Thanks for your time and effort.

    Regards,

    Arthur

  • 18 mai 2012 19:34
     
     

    Hi Greg,

    I also think the following link is worth taking a look at.

    http://startbigthinksmall.wordpress.com/2010/01/04/points-inches-and-emus-measuring-units-in-office-open-xml/

    Regards,

    Arthur

  • 19 mai 2012 00:32
     
     

    If you search for me on posts in this forum, you will see a long list of questions wrt. Powerpoint and VBA.

    I have a successful kios running in the company and the icing was allowing long web pages to scroll.

    I found out i can make this work by clicking the mouse inside the web browser object and doing a page down in VBA.

    It work reliably if you click on the RHS scroll bar. => Thus the need to know the screen coords.

    The article above looks promising, i get back here once i have tried a few things.

    regards Greg

  • 25 mai 2012 08:25
     
     

    Hi Greg

    I have not heard back from you, but I am hoping the article I referenced below helped you answer some of the questions you may have had. http://social.msdn.microsoft.com/Forums/en-US/officegeneral/thread/b2b070ff-4436-4c9d-95f5-6ff39e2bdf76

    If this information did not suffice, I would advise possible oppening a support case with us. Thanks for your time and effort.

    Regards,

    Arthur


  • 26 mai 2012 01:18
     
     

    Arthur

    I got stymed trying to use .PointsToScreenPixelsX which needs a DocumentWindow

    See http://social.msdn.microsoft.com/Forums/en-US/officegeneral/thread/ba10911f-abbc-4538-b9c6-1765a0331994 

    Unfortunately, Powerpoint is not consistent and does not always provide the DocumentWindow object

    Add to this that the coordinates are relative to the PP window, i.e. in full screen no problem, but in windowed mode you need to know you top left cord.

    Even then i am not sure if this is includes or excludes the realestate of the title bar in windowed mode.

    I worked on an alternative of using windows queries, that too is problematic becuase of the class changes between edit and run mode, full screen and windowed mode.

    I'll post back some results soon.

    Regards

  • 3 iunie 2012 04:17
     
     Răspuns Are cod

    OK here is the results of many hours of trial and error...

     .PointsToScreenPixelsX  does not work as documented, see http://social.msdn.microsoft.com/Forums/en-US/officegeneral/thread/eb927b38-bbf4-4c38-8cbd-18c8a5974bd1

    The way that does work is to look for the Windows used, parts of my code is below. This is for Powerpoint 2010.

    Of note, in fullscreen mode, the top window has class "screenClass". In windowed mode the window is "PPTFrameClass" (note this is shared with Edit mode as well).

    A web browser is housed in the "Shell Embedding" window. The coords are for the whole window so if a scroll bar exists it will be about 20 pixels before the X2 (right edge) point.

    Don't be fooled by the "Internet Explorer_Server" window Spy++ shows, this is a common window used in all other IE windows and is not a direct child of the Powerpoint process.

    => Once you know the coords of the windows, both the full presentation (PresRect) and web browser  (MDIRect) , then controlling scrolling works. I used a timer, clicked on the scroll bar and did page downs.

    NB: Name will vary for older versions of Powerpoint but the approach is much the same.

    Public Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long
    Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Public Declare Function GetCursorPos Lib "user32" _
    (lpPoint As POINTAPI) As Long
    Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
          (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As _
    Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpsz1 As String, ByVal hwnd As Long) As Long
    Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As Rect) As Long
    Type Rect
         x1 As Long
         y1 As Long
         x2 As Long
         y2 As Long
    End Type
    Private Type POINTAPI
        X As Long
        Y As Long
    End Type
    Public MDIRect As Rect              ' Co-ords of object
    Public PresRect As Rect             ' Co-ords of presentation
    Public ptLocation As POINTAPI       ' Current cursor point
    Public ptLocationSet As POINTAPI    ' Point we asked to cursor to be
    Public Const SCROLLBAR_XADJUST = -10
    Public Const SCROLLBAR_YADJUST = 100
    Public Const PARK_XADJUST = -300    ' Where to park relative to BR
    Public Const PARK_YADJUST = -20     ' Where to park relative to BR
    Option Explicit
    '
    ' Find the "Shell Embedding" window for the browser
    '
    Function GetBrowserLocation() As Boolean
        Dim hwnd1 As Long
        Dim retval As Long ' return value
        
        hwnd1 = FindWindow("screenClass", vbNullString)     ' This is valid in Full Screen Mode
        Debug.Print "screenClass - Handle is " & hwnd1
        
        If hwnd1 = 0 Then
        hwnd1 = FindWindow("PPTFrameClass", vbNullString)   ' This is valid in windowed mode, note name here is for Powerpoint 2010
        Debug.Print "PPTFrameClass - Handle is " & hwnd1    ' Other versions would need additional name checks
        End If
        
        GetWindowRect hwnd1, PresRect       ' Remember co-ords of overall presentation
        
        MDIRect.x1 = -1 ' Deliberately set -ve value to be used to check if valid co-ords have been found
        
        ' Use the above callback function to list all of the enumerated windows. Note that lParam is
        ' set to 0 because we don't need to pass any additional information to the function.
        If hwnd1 <> 0 Then
            retval = EnumChildWindows(hwnd1, AddressOf EnumChildProc, 0)
        End If
        
        If MDIRect.x1 = -1 Then
            GetBrowserLocation = False      ' Web browser not found
        Else
            GetBrowserLocation = True       ' Web browser found
            ' OK place cursor at parked position
            ptLocationSet.X = PresRect.x2 + PARK_XADJUST
            ptLocationSet.Y = PresRect.y2 + PARK_YADJUST
            
            SetCursorPos ptLocationSet.X, ptLocationSet.Y
        End If
    End Function
    ' Display the title bar text of all children of window MDIForm1. This
    ' task is given to the callback function, which will receive each handle individually.
    ' *** Place this code in a module. This is the callback function. ***
    ' This function displays the title bar text of the window identified by hwnd.
    Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
        Dim hwndChild As Long
        Dim buffer As String
        Dim retval As Long ' return value
        
        buffer = Space(100)
        
        retval = GetClassName(hwnd, buffer, 100)
        buffer = Trim(buffer)
        'Debug.Print "Class name: " & buffer
        ' By using Spy++ this is the common window name used to contain the object
        If StrComp(buffer, "Shell Embedding", 1) = 0 Then
            ' This means we have found the embedded object
            Debug.Print " Shell Embedding found"
            GetWindowRect hwnd, MDIRect     ' Remember location
            Debug.Print "Window Coords TL " & MDIRect.x1 & ", " & MDIRect.y1 & " BR " & MDIRect.x2 & ", " & MDIRect.y2
            EnumChildProc = 0
        Else
            'Debug.Print "Not found #" & hwndChild
            EnumChildProc = 1 ' return value of 1 means continue enumeration
        End If
    End Function