connecting users of the CorelDRAW family of products

[VBA]Document.GetUserClick in Photopaint

rated by 0 users
Not Answered This post has 0 verified answers | 6 Replies | 1 Follower

Share  
Page 1 of 1 (7 items) | RSS

lvr123 posted on Tue, Jun 30 2009 7:04

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

 

All Replies

Top 50 Contributor
Puerto Rico
Male

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 Cervantes
MC Design Studio

Top 10 Contributor
Germany / Europe
Male
mo replied on Wed, Jul 1 2009 16:58

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 Explicit
Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private 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 If

End Function

Top 10 Contributor
Germany / Europe
Male
mo replied on Thu, Sep 24 2009 16:20

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.

Page 1 of 1 (7 items) | RSS
© Corel Corporation. The content herein is in the form of a personal web log ("Blog") or forum posting. As such, the views expressed in this site are those of the participants and do not necessarily reflect the views of Corel Corporation, or its affiliates and their respective officers, directors, employees and agents. Terms and Conditions / User Guidelines.