Solved

VBScript : How to get the cursor coordinates

Posted on 2004-09-05
13
6,734 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Classic ASP + JS 4 78
API Location, separating out information 10 45
show region if a selection is made on a drop down menu 3 56
Live mode in DW, need to creae Session 4 76
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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 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

21 Experts available now in Live!

Get 1:1 Help Now