Solved

VBScript : How to get the cursor coordinates

Posted on 2004-09-05
13
6,621 Views
Last Modified: 2010-10-07
I have  VB code which will get me the cursor x and y coordinates. I have use the user32.dll to fetch the coordinates. Here is that code...

*********************************************************
Private Declare Sub GetCursorPos Lib "user32.dll" (lpPoint As POINTAPI)

Private Type POINTAPI
X As Integer
Y As Integer
End Type
Private mPosition As POINTAPI

Call GetCursorPos(mPosition)
msgbox mPosition.X
msgbox mPosition.Y
*********************************************************

Now I need the same code to be executed in a vbs file ie., as a VBScript file. Can anyone tell me how to use windows api in vbs file and give me the vbs code for the above situation.

Note : I need a vb script code which will be executed in vbs file.


0
Comment
Question by:sangack
  • 3
  • 3
  • 2
  • +3
13 Comments
 
LVL 5

Expert Comment

by:cristy56
ID: 11987530
As far as I remembered. standard win 32 DLLs cannot be used in ASP. asp can only use Activex DLLs but there's a way around this... Create you own Activex DLL using Visual Basic and encapsulate the functiions of your original dll


Cristy

0
 
LVL 5

Expert Comment

by:cristy56
ID: 11987561
Compile your VB6 as an ActiveX DLL, register it on the server with regsvr32.exe...

then from ASP page create the object using the ProgID (e.g.) :

<%
        set obj = Server.CreateObject("GetTimeDLL.GetTime")
        varTime = obj.GetTheTime
        response.write varTime
        set obj = nothing
%>

========================================

Cristy
0
 
LVL 3

Expert Comment

by:Tyzer
ID: 11987718
If its for a webpage, why dont u use this small bit of javasript code.. its much lighter that using objects,dlls' ..

<input type=text name=x value=""> <input type=text name=y value="">

<script>
var oX = document.getElementById('x')
var oY = document.getElementById('y')
function fnJSWriteCoords(){
      oX.value = event.clientX;
      oY.value = event.clientY;
}

document.onmousedown = fnJSWriteCoords
</script>
0
 
LVL 7

Expert Comment

by:vnvk
ID: 11987781
Using Javascript is much easier and also no issues of security levels when you are dealing with web pages. Activex dlls may get blocked some times based on the security level.

I suggest you follow javascript if possible, ie. if not a must as per specifications to use Actvex dlls
0
 

Author Comment

by:sangack
ID: 11987894
I am using a Testing tool to test my application. My testing tool will allow only running vbs files.

So I need to execute these function in vbs file and get the coordinates.

Hope you all can understand my problem.

Is there any posibility to run as a vbs file????? if so, write the vbs code.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 11988297
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 3

Expert Comment

by:Tyzer
ID: 11990148
What kind of testing tool are you using ? Just curious.. never heard of something like that..
Testing tool or not, i'd still go with the javascript.. just open the page in your webbrowser , see if there is no javascript error-popup.. and ur finished!
0
 

Author Comment

by:sangack
ID: 12023854
Here is the VB code which I need.

For your reference....

*********************************************************************

Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Private Type GUITHREADINFO
    cbSize As Long
    flags As Long
    hwndActive As Long
    hwndFocus As Long
    hwndCapture As Long
    hwndMenuOwner As Long
    hwndMoveSize As Long
    hwndCaret As Long
    rcCaret As RECT
End Type

Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetFocus Lib "user32" () As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function GetGUIThreadInfo Lib "user32" (ByVal dwthreadid As Long, lpguithreadinfo As GUITHREADINFO) As Long

Public Sub GetFocusedControlPos(ByRef x As Integer, ByRef y As Integer)
   Dim RetInfo As GUITHREADINFO
   Dim WndHandle As Long
   Dim SelectedPID As Long
   Dim MyRect As RECT
   Dim lpClassName As String
       
   'Get active window
   WndHandle = GetForegroundWindow()
   'Get GUI PID of the selected thread
   SelectedPID = GetWindowThreadProcessId(WndHandle, 0)

   RetInfo.cbSize = LenB(RetInfo)
   
   If GetGUIThreadInfo(SelectedPID, RetInfo) = 0 Then
        MsgBox "Error while calling the function!"
        Exit Sub
    End If
   
     'Get window rectangle
   GetWindowRect RetInfo.hwndFocus, MyRect

    lpClassName = Space(256)
    'retrieve the class name
    RetVal = GetClassName(RetInfo.hwndFocus, lpClassName, 256)

    MsgBox lpClassName
   
   x = MyRect.Left
   y = MyRect.Top
End Sub

Private Sub Timer1_Timer()
   Dim x As Integer
   Dim y As Integer

   GetFocusedControlPos x, y
   Me.Caption = x & " " & y
End Sub

*********************************************************************
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12025037
That is VB code, not VBScript. So your problem is still not solved.
You cannot access DLL functions without those DynamicWrapper dll enabled on your machine (I have not tested that DLL).
0
 

Author Comment

by:sangack
ID: 12025453
ya its true...

I was searching for VBScript code because my Testing tool will accept only vbs file. It can as well call dll too. so iam writing a dll with the above and trying to call it from my tool.

I just posted the Vb code FYi. May be I am wrong in addressing it. sorry!!!!


0
 
LVL 63

Expert Comment

by:Zvonko
ID: 12704719


My proposal is:  PAQ with points refunded

This thread contains enough good stuff worth to be kept in the knowledge base.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12743116
PAQed with points refunded (300)

modulo
Community Support Moderator
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now