none
VBA to find the HWND of a Page in Publisher. RRS feed

  • Question

  • I am trying to put rectangle in a publisher page when user click on the publisher. I got the Click point by using the following code.

    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Public Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
    Private Type POINTAPI
         x As Long
         y As Long
    End Type

    Sub Macro1()
    Dim Pos As POINTAPI

    Do Until (GetAsyncKeyState(vbKeyEscape))

     l = GetCursorPos(pos)

     If (GetAsyncKeyState(vbKeyLButton)) Then
      Call ScreenToClient(ActiveWindow.hwnd, pos)
      ActiveDocument.Pages(1).Shapes.AddShape Type:=msoShapeRectangle, _
      Left:=Pos.x, Top:=Pos.y, Width:=100, Height:=100
     End If

    Loop

    End Sub

    But with this i am not able to get the mouse position on the page. But i am getting mouse position on the window.(Bacause i am using (ActiveWindow.hwnd). Is there anyway so that i can convert the mouse position on the page or a shape on the page?

    Thanks in Advance
    Jithin Prakash


    Thursday, June 27, 2013 9:20 AM