GetCursorPos() WIN API

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
unixkd
Posts: 565
Joined: Thu Feb 11, 2010 1:39 pm

GetCursorPos() WIN API

#1 Post by unixkd »

Hi All
Anybody with the idea of how to call GetCursorPos() WIN API in Xbase++ ?

Thanks

Joe

User avatar
Auge_Ohr
Posts: 1405
Joined: Wed Feb 24, 2010 3:44 pm

Re: GetCursorPos() WIN API

#2 Post 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})
greetings by OHR
Jimmy

User avatar
unixkd
Posts: 565
Joined: Thu Feb 11, 2010 1:39 pm

Re: GetCursorPos() WIN API

#3 Post by unixkd »

Hi Jimmy

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

Thanks.

Joe

User avatar
Auge_Ohr
Posts: 1405
Joined: Wed Feb 24, 2010 3:44 pm

Re: GetCursorPos() WIN API

#4 Post 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})
greetings by OHR
Jimmy

User avatar
unixkd
Posts: 565
Joined: Thu Feb 11, 2010 1:39 pm

Re: GetCursorPos() WIN API

#5 Post 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

User avatar
Auge_Ohr
Posts: 1405
Joined: Wed Feb 24, 2010 3:44 pm

Re: GetCursorPos() WIN API

#6 Post 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
greetings by OHR
Jimmy

User avatar
unixkd
Posts: 565
Joined: Thu Feb 11, 2010 1:39 pm

Re: GetCursorPos() WIN API

#7 Post by unixkd »

Jimmy thanks.

Worked perfectly

Joe

Post Reply