将Delphi代码转换为C#(从鼠标光标获取Google地球坐标 - 包含代码) [英] Converting Delphi code to C# (Getting Google earth coordinates from mouse cursor - Code included)

查看:102
本文介绍了将Delphi代码转换为C#(从鼠标光标获取Google地球坐标 - 包含代码)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在开发一个使用谷歌COM API的小工具(我知道它已经过时了,但它确实有效)和一个它所做的任务是从特定点获取坐标。

我正在使用这种方法:

///////// /////////////////////////

Hi all,

I''m develpoing a small tool using google COM API (I know it''s obsolete somehow but it works though)and one of the tasks it does it''s to get coordinates from a specific point.
I''m using this method:
//////////////////////////////////

GetPointOnTerrainFromScreenCoords(0,0)





关于方法:

此方法允许外部应用程序查询由其标准化屏幕坐标(screen_x,screen_y)标识的3D视点中的点的地理位置和地形高度,范围为(-1, - 1)到(+ 1,+ 1)包含。

以下是一些例子:



(-1,-1) - 底部屏幕的左上角。

(0,0) - 屏幕中央。

(1,1) - 屏幕的右上角。

////////////////////////////////////



来获取中心屏幕的坐标,但我需要的是根据鼠标光标获取坐标,我花了很多时间来寻找C#中的代码,但除了这个delphi代码之外我找不到任何东西:





Info about the method:
This method allows an external application to query the geolocation and terrain altitude of a point in the 3D viewpoint identified by its normalized screen coordinates (screen_x, screen_y), ranging from (-1, -1) to (+1, +1) inclusive.
Here are some examples:

(-1, -1) - bottom left hand corner of the screen.
(0,0) - center of the screen.
(1, 1) - top right hand corner of the screen.
//////////////////////////////////

to get the coordinates of the center screen but what I need is to get the coordinates based on the mouse cursor, I''ve spent much time searching to get the code in C# but I haven''t found anything but this delphi code:

+LButton::
GE := ComObjCreate("GoogleEarth.ApplicationGE")
CoordMode, Mouse, Relative

    Sleep, 100
    MouseGetPos,MouseX ,MouseY , WhichWindow, WhichControl
    ControlGetPos, RendX, RendY, RendW, RendH, %WhichControl%, ahk_id %WhichWindow%
	ParamX :=  (((2*(MouseX - RendX)) / RendW ) - 1)
	ParamY := -(((2*(MouseY - RendY)) / RendH ) - 1)
	CursPos := GE.GetPointOnTerrainFromScreenCoords(ParamX,ParamY)
    CursLat  := CursPos.Latitude 
    CursLong :=	CursPos.Longitude
	CursAlt  := CursPos.Altitude
	clipboard := Curslat . "," . CursLong . "," . CursAlt
    msgbox, CursLat %CursLat%`nCursLong %CursLong%`nCursAlt %CursAlt%







所以我现在需要的是将这个块转换为C#,以便我可以使用它知道我没有任何正在使用的转换工具..



非常感谢。




So what I need now is to convert this block into C# so that I can use it knoing that I havent foung any working converting tool..

Much Thanks.

推荐答案

您的窗口必须订阅鼠标事件,例如 MouseClick MouseDown MouseMove 。该事件的 EventArgs 将告诉您鼠标坐标 - 已经相对于您的窗口,而不是像Delphi函数那样的屏幕。因此,没有必要减去窗口的位置( RendX RendY ); RendW RendH 可以替换为 ClientRectangle.Width ClientRectangle.Height 您窗口的属性。
Your window must subscribe to a mouse event, e.g. MouseClick, MouseDown, or MouseMove. The EventArgs of that event will tell you the mouse coordinates - already relative to your window, not to the screen as with the Delphi function. Hence there''s no need to substract the position (RendX, RendY) of the window; RendW and RendH can be replaced by the ClientRectangle.Width and ClientRectangle.Height properties of your window.


这篇关于将Delphi代码转换为C#(从鼠标光标获取Google地球坐标 - 包含代码)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆