Solved

VBScript : How to get the cursor coordinates

Posted on 2004-09-05
13
6,993 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

820 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