Solved

VBScript : How to get the cursor coordinates

Posted on 2004-09-05
13
7,376 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

632 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