Using Mouse Event to get pixel position
Dear Sir,
I want to use the mouse event to directly click to get the pixel position. Using clickonworkspace is not convenient.
McWindows event is return windows position.
Can I use McWindows event to get the pixel position on the ActiveMcImage?
[code]
By Wesan
I want to use the mouse event to directly click to get the pixel position. Using clickonworkspace is not convenient.
McWindows event is return windows position.
Can I use McWindows event to get the pixel position on the ActiveMcImage?
[code]
Private WithEvents m_Windows As Mediacy.IQL.Application.McWindows Public Sub GetMcWindowsControl m_Windows=ThisApplication.WindowsEx End Sub Private Sub m_Windows_MouseDown(ByVal Window As IMcWindow, ByVal lMouseButton As Integer, ByVal lShift As Integer, ByVal lMouseX As Integer, ByVal lMouseY As Integer, ByRef bHandled As Boolean) Handles m_Windows.MouseDown Debug.Print (lMouseX.ToString & "," & lMouseY.ToString & ">>>" & m_Windows.ActiveWindow.Document.DisplayName) End Sub
By Wesan
0
Best Answer
-
Hi Wesan,
You can track mouse events of the active window and get click coordinates. You can also get Image coordinates at the click position, in that case you have to use McView.MapZoomedToImage function, here is a sample code:Public Module Module1 Public WithEvents _actWindow As McWindow Public Sub ThisApplication_SelectedDataChanged(ByVal Flags As MediaCy.IQL.Application.IMcData.DataTypes) Handles ThisApplication.SelectedDataChanged 'track active window events _actWindow=ThisApplication.ActiveWindow End Sub Public Sub ThisProject_Loading() Handles ThisProject.Loading 'track active window events _actWindow=ThisApplication.ActiveWindow End Sub Private Sub _actWindow_MouseDown(ByVal Window As Interop.IMcWindow, ByVal lMouseButton As Integer, ByVal lShift As Integer, ByVal lMouseX As Integer, ByVal lMouseY As Integer, ByRef bHandled As Boolean) Handles _actWindow.MouseDown ThisApplication.Output.Show ThisApplication.Output.PrintMessage "Mouse click on " & _actWindow.Caption & " at X/Y " & lMouseX & " / " & lMouseY If _actWindow.ImageView IsNot Nothing Then 'check image coordinates at click position Dim view As Mediacy.IQL.Display.Viewer.McView=_actWindow.ImageView Dim pIn As MediaCy.IQL.ObjectManager.LONGPOINT pIn.x = lMouseX pIn.y = lMouseY Dim pOut As Object = Nothing ' Single(,) view.MapZoomedToImage(pIn, pOut)'convert to image coordinates ThisApplication.Output.PrintMessage "Image coordinates X/Y " & pOut(0,0) & " / " & pOut(1,0) End If End Sub End Module
The Output window result will look like this:
Mouse click on SPOTS.TIF at X/Y 1040 / 343Image coordinates X/Y 212 / 203,6783Mouse click on SPOTS.TIF at X/Y 951 / 461Image coordinates X/Y 159,0979 / 273,8182
I've also attached the project.
Yuri0
Answers
If you just need to get a clicked mouse point, the code below works nicely for me:
Private Function GetClickedPoint(prompt As String) As System.Drawing.PointF Dim window1, doc1 Dim clickedPoint As System.Drawing.PointF With Application.WindowCommands.Active(Nothing) .Run(window1) End With With Automate.ScriptingCommands.ClickOnWorkspace(Nothing) .Prompt = prompt .SelectDocuments = True ' The output can be a document or a window .Run(window1, doc1, Nothing) If .Status=McCommand.TaskStatus.IsProcessed Then clickedPoint = .PixelLocation.Value End If End With Return clickedPoint End Function Public Function PrintPoint() Dim point As System.Drawing.PointF point = GetClickedPoint("Test Get Point") Debug.Print(point.X) Debug.Print(point.Y) End Function
If you just need to get a clicked mouse point, the code below works nicely for me:
Private Function GetClickedPoint(prompt As String) As System.Drawing.PointF Dim window1, doc1 Dim clickedPoint As System.Drawing.PointF With Application.WindowCommands.Active(Nothing) .Run(window1) End With With Automate.ScriptingCommands.ClickOnWorkspace(Nothing) .Prompt = prompt .SelectDocuments = True ' The output can be a document or a window .Run(window1, doc1, Nothing) If .Status=McCommand.TaskStatus.IsProcessed Then clickedPoint = .PixelLocation.Value End If End With Return clickedPoint End Function Public Function PrintPoint() Dim point As System.Drawing.PointF point = GetClickedPoint("Test Get Point") Debug.Print(point.X) Debug.Print(point.Y) End Function
Thank you for your suggestions.
I would like to know like McWindows event, you can click directly to return the coordinates immediately, without call script command every time.
By Wesan