Hello,
In CorelDraw, there is this method Document.GetUserClick, that allows you to let the user point-and-click somewhere in the document, without leaving the macro.
I've never found anything similar to this in Photopaint, and I miss it a lot.
Is there anyway to achieve something similar, or to build an own extension to the base Object Model to achieve this ?
Regards,
Laurent
you could visit http://forum.oberonplace.com/
and post your question there. It is the best place to get Corel's VBA help.
Regards
Michael CervantesMC Design Studio
It depends on what you want to retrieve with the mouse click in your document. If you want to get the position of the click, you can get it with an API call "Get CursorPos()". http://www.freevbcode.com/ShowCode.asp?ID=2890 or http://support.microsoft.com/?scid=kb%3Ben-us%3B114777&x=13&y=10
Of course you could combine the call with the object's area to get the object you have clicked. But I think its easier to retrieve the object with "Application.ActiveLayer"...
Thanks for this. Il will certainly use it.... after I could grab the mouse click.
That's my main problem: how can I halt the macro, let the user click somewhere, "hear" the click and then do the "GetCursorPos()" ?
To halt the program, I guess a "DoEvents()" will do the job. But how do I "hear" the click ?????
About the forum on oberon, I tried to register, without success...
Here is the solution:
Option ExplicitPrivate Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As IntegerPrivate Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As LongPrivate Type POINTAPI x As Long y As Long End Type
Private Function GetUserClick(ByRef where As POINTAPI) As Integer Dim EscapePressed As Integer: EscapePressed = 0 Dim ClickDone As Integer: ClickDone = 0 'Boucle tant que touche Suppr pas actionnée.. While ((EscapePressed = 0) And (ClickDone = 0)) DoEvents EscapePressed = GetAsyncKeyState(&H1B) 'Escape ClickDone = GetAsyncKeyState(&H2) 'Souris bouton gauche Wend If (EscapePressed <> 0) Then GetUserClick = 0 Else GetCursorPos where GetUserClick = 1 End IfEnd Function
An excellent solution, congrats! Though I would suggest to build in another "trapdoor" in the "While"-capsule, just to prevent critical errors within the function:
It is not necessary, but would be more stable, if the "While"-capsule could be terminated automatically with a Timer-Event (for example if the user doesn't react the macro terminates after 30 seconds, I use the two API Calls "Function SetTimer" and "Function KillTimer" for it). I made the experience that using DoEvents-Call within a While-Wend-Loop could freeze and crash sometimes, and that's not funny with API Calls! Another suggestion is to add an Error-listener and branch it to let the macro terminate itself: "On Error GoTo MyErrorhandler...Your Function body here...MyErrorhandler: Exit Function".
Great suggestions ! Thanks.