你的类是继承自CScrollView类对吧?那你在OnLButtonDown()函数中最开始加入如下代码:
CClientDC dc(this);
OnPrepareDC(&dc);
dcDPtoLP(&point);
接下来,point中的坐标应该就符合你的意愿了!
代码如下:
import javaawtBorderLayout;import javaawtFlowLayout;
import javaxswingJButton;
import javaxswingJDialog;
import javaxswingJFrame;
import javaxswingJPanel;
import javaxswingborderEmptyBorder;
import javaxswingJLabel;
import javaawtFont;
import javaawtPoint;
import javautilTimer;
import javautilTimerTask;
import javaawtColor;
public class MouseInfo extends JFrame {
private final JPanel contentPanel = new JPanel();
JLabel value_x = null;
JLabel value_y = null;
/
Launch the application
/
public static void main(String[] args) {
try {
MouseInfo info_frame = new MouseInfo();
info_framesetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
info_framesetVisible(true);
info_framesetAlwaysOnTop(true);
Timer timer = new Timer();
timerschedule(new TimerTask() {
@Override
public void run() {
Point point = javaawtMouseInfogetPointerInfo()getLocation();
// Systemoutprintln("Location:x=" + pointx + ", y=" +
// pointy);
info_framevalue_xsetText("" + pointx);
info_framevalue_ysetText("" + pointy);
}
}, 100, 100);
} catch (Exception e) {
eprintStackTrace();
}
}
/
Create the dialog
/
public MouseInfo() {
setTitle("\u9F20\u6807\u5750\u6807\u83B7\u53D6\u5668");
setBounds(100, 100, 217, 156);
getContentPane()setLayout(new BorderLayout());
contentPanelsetBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane()add(contentPanel, BorderLayoutCENTER);
contentPanelsetLayout(null);
JLabel lblx = new JLabel("\u5750\u6807x:");
lblxsetFont(new Font("宋体", FontPLAIN, 15));
lblxsetBounds(22, 27, 66, 31);
contentPaneladd(lblx);
JLabel lbly = new JLabel("\u5750\u6807y:");
lblysetFont(new Font("宋体", FontPLAIN, 15));
lblysetBounds(22, 68, 66, 31);
contentPaneladd(lbly);
value_x = new JLabel("0");
value_xsetForeground(ColorBLUE);
value_xsetFont(new Font("宋体", FontPLAIN, 20));
value_xsetBounds(82, 27, 66, 31);
contentPaneladd(value_x);
value_y = new JLabel("0");
value_ysetForeground(ColorBLUE);
value_ysetFont(new Font("宋体", FontPLAIN, 20));
value_ysetBounds(82, 68, 66, 31);
contentPaneladd(value_y);
}
}
Point
p
=
CursorPosition;
pX;
//当前X坐标
pY;
//当前Y坐标
以上代码在任意地方执行,就可取得鼠标在屏幕上的X
Y坐标。
<title>Js获取适时获取鼠标坐标值并显示</title>
<script type="text/javascript">
var getCoordInDocumentExample = function(){
var coords = documentgetElementById("coords");
coordsonmousemove = function(e){
var pointer = getCoordInDocument(e);
var coord = documentgetElementById("coord");
coordinnerHTML = "X,Y=("+pointerx+", "+pointery+")";
}
}
var getCoordInDocument = function(e) {
e = e || windowevent;
var x = epageX || (eclientX +
(documentdocumentElementscrollLeft
|| documentbodyscrollLeft));
var y= epageY || (eclientY +
(documentdocumentElementscrollTop
|| documentbodyscrollTop));
return {'x':x,'y':y};
}
windowonload = function(){
getCoordInDocumentExample();
};
</script>
<div id="coords" style="width:500px;height:200px;background:#F2F1D7;border:2px solid #0066cc;">
请在此移动鼠标。
</div>
<br />
<div id="coord" style="width:500px;border:2px solid #336699;"> </div>
先给X,Y赋值。假如:
x=100
y=100
GetCursorPos a, b//获取当前鼠标位置,返回变量a,b
If a = x and b = y Then
//这里添加文本输入的代码
Else
MessageBox "鼠标位置不对"
MoveTo x, y//鼠标移动到坐标100,100
End If
有点不明白你为什么不直接鼠标移动到预定坐标然后执行文本输入。。。
以上就是关于在VC中如何获取视图窗口鼠标坐标的绝对位置X,Y全部的内容,包括:在VC中如何获取视图窗口鼠标坐标的绝对位置X,Y、java怎样获取鼠标在屏幕的坐标、如何获得当前鼠标的屏幕坐标(c#)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)