Page 1 of 1

GetCursorPos() WIN API

Posted: Wed Nov 14, 2018 12:52 pm
by unixkd
Hi All
Anybody with the idea of how to call GetCursorPos() WIN API in Xbase++ ?

Thanks

Joe

Re: GetCursorPos() WIN API

Posted: Wed Nov 14, 2018 1:21 pm
by Auge_Ohr
hi,
try this

Code: Select all

STATIC DLLFUNCTION GetCursorPos( @pPoint )                       ;
       USING STDCALL                                             ;
       FROM  USER32.DLL

FUNCTION MyCursorPos()
LOCAL sPoint := REPLICATE(CHR(0),8)
LOCAL nX     := 0
LOCAL nY     := 0
STATIC GetCursorPos

   IF GetCursorPos = NIL
      GetCursorPos := DllPrepareCall("user32.dll",;
     DLL_STDCALL,;
     "GetCursorPos")
   ENDIF
   DllExecuteCall(GetCursorPos,@sPoint)

   nX := BIN2L(SUBSTR(sPoint,1,4))
   nY := BIN2L(SUBSTR(sPoint,5,4))
   nY := (- 1 * nY)+APPDESKTOP():CURRENTSIZE()[2]       // Xbase++ 0,0 lower left

RETURN ({nX,nY})

Re: GetCursorPos() WIN API

Posted: Wed Nov 14, 2018 4:13 pm
by unixkd
Hi Jimmy

I got error: Function not declared. I thought the DLLFUNCTION .... declares the function ?

Thanks.

Joe

Re: GetCursorPos() WIN API

Posted: Wed Nov 14, 2018 4:26 pm
by Auge_Ohr
unixkd wrote:I got error: Function not declared. I thought the DLLFUNCTION .... declares the function ?

Code: Select all

#include "DLL.CH"

STATIC DLLFUNCTION GetCursorPos( @pPoint )                       ;
       USING STDCALL                                             ;
       FROM  USER32.DLL

PROCEDURE MAIN
   ? MyCursorPos()
   WAIT
RETURN

FUNCTION MyCursorPos()
LOCAL sPoint := REPLICATE(CHR(0),8)
LOCAL nX     := 0
LOCAL nY     := 0
STATIC GetCursorPos

   IF GetCursorPos = NIL
      GetCursorPos := DllPrepareCall("user32.dll",;
     DLL_STDCALL,;
     "GetCursorPos")
   ENDIF
   DllExecuteCall(GetCursorPos,@sPoint)

   nX := BIN2L(SUBSTR(sPoint,1,4))
   nY := BIN2L(SUBSTR(sPoint,5,4))
   nY := (- 1 * nY)+APPDESKTOP():CURRENTSIZE()[2]       // Xbase++ 0,0 lower left

RETURN ({nX,nY})

Re: GetCursorPos() WIN API

Posted: Wed Nov 14, 2018 6:37 pm
by unixkd
Working now thanks.

Once more I need help on GetAsyncState() API

From the documentation it requires VK_..... values as parameter

I need to pass VK_RBUTTON defined

#define VK_RBUTTON 0x02

Re: GetCursorPos() WIN API

Posted: Wed Nov 14, 2018 7:37 pm
by Auge_Ohr

Code: Select all

#include "DLL.CH"

// https://docs.microsoft.com/de-de/windows/desktop/inputdev/virtual-key-codes
#define VK_LBUTTON 0x01
#define VK_RBUTTON 0x02

DLLFUNCTION GetAsyncKeyState( n ) USING STDCALL FROM USER32.DLL

PROCEDURE MAIN
CLS
? "Press right mouse button"
   DO WHILE GetAsyncKeyState( VK_RBUTTON ) = 0
      Sleep( 10 )
   ENDDO
? "seems to work ;)"
WAIT
RETURN

Re: GetCursorPos() WIN API

Posted: Thu Nov 15, 2018 10:13 am
by unixkd
Jimmy thanks.

Worked perfectly

Joe