Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2004

Tip: Looking for answers? Try searching our database.

Word and WinApi - moving caret to cursor

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg - 27 Dec 2004 19:07 GMT
Please help, how in VBA PROGRAM  move the caret to the location of the cursor

the given code does not work:

Public Declare Function GetActiveWindow _
Lib "user32" () As Long
 
Public Declare Function GetCursorPos _
Lib "user32" _
(pp As POINT) As Boolean

Public Declare Function ScreenToClient _
Lib "user32" _
(ByVal hwnd As Long, pp As POINT) As Boolean

Public Declare Function SetCaretPos _
Lib "user32" _
(ByVal x As Integer, ByVal y As Integer) As Boolean

Public Type POINT
x As Long
y As Long
End Type
'-------------------

sub SetCur()

Dim screen As POINT, q as Boolean

'get WORD descriptor
hwnd = GetActiveWindow

'get cursor position
q = GetCursorPos(screen)

' transforming screen coordinates to client
q = ScreenToClient(hwnd, screen)

' trying to move the caret-> don't working !!!!!!!!!!!
q = SetCaretPos(screen.x, screen.y)

end sub
Helmut Weber - 27 Dec 2004 20:31 GMT
Hi Greg,

not that I think I understand much of all that API-stuff,
but at a long shot,
when I look into my API-Reference, GetCursorPos,
ScreentoClient, SetCaretPos are all of type "long".

I wonder ....
Andi Mayer - 28 Dec 2004 09:54 GMT
>Please help, how in VBA PROGRAM  move the caret to the location of the cursor
>
[quoted text clipped - 38 lines]
>
>end sub

I don't know the api SetCaretPos, if you want to set the CorsourPos
use SetCursorPos

To Helmuth: in this case there is now difference, this function only
gives a true or false as result (better done or not done)

---
If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
MW
Greg - 28 Dec 2004 19:27 GMT
> I don't know the api SetCaretPos, if you want to set the CorsourPos
> use SetCursorPos
---------------------------------
to Andi Mayer

Thanks, but I don't want to set the CURSOR position, I would like to MOVE
the CARET position (in MS WORD ) to CURSOR position
Andi Mayer - 29 Dec 2004 13:39 GMT
>> I don't know the api SetCaretPos, if you want to set the CorsourPos
>> use SetCursorPos
[quoted text clipped - 3 lines]
>Thanks, but I don't want to set the CURSOR position, I would like to MOVE
>the CARET position (in MS WORD ) to CURSOR position

This was a Language problem on my side

do I understand you right:
you want to simulate a left-mouse-click?

if yes then use the mouse_event api

Private 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)
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP = &H40
Const MOUSEEVENTF_MOVE = &H1
Const MOUSEEVENTF_ABSOLUTE = &H8000
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
Private Sub Form_Activate()
   'KPD-Team 1998
   'URL: http://www.allapi.net/
   'E-Mail: KPDTeam@Allapi.net
   Do
       'Simulate a mouseclick on the cursor's position
       mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0&,
0&, cButt, dwEI
       DoEvents
   Loop
End Sub

---
If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
MW
Greg - 29 Dec 2004 19:23 GMT
> This was a Language problem on my side
>
[quoted text clipped - 25 lines]
>     Loop
> End Sub



Yes, it is!
It's working with some  modifing

   mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP,0&, 0&, 0&,
GetMessageExtraInfo()

Sorry for my bad English.
With the best regards from Moscow

P.S.   HAPPY  NEW YEAR!
Andi Mayer - 29 Dec 2004 21:06 GMT
>>     'KPD-Team 1998
>>     'URL: http://www.allapi.net/
>>     'E-Mail: KPDTeam@Allapi.net

>Sorry for my bad English.

?? your english is perfect,.

go to the website mentoned above, there is a small program called
API-Guide with a lot of explanations and samples.

P.S.   HAPPY  XMas in advance for your

---
If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
MW

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.