faq23.htm
来自「C++builder学习资料C++builder」· HTM 代码 · 共 48 行
HTM
48 行
<HTML>
<HEAD>
<TITLE>Determine the location of the mouse.</TITLE>
<META NAME="Author" CONTENT="Harold Howe">
</HEAD>
<BODY BGCOLOR="WHITE">
<CENTER>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH="640">
<TR>
<TD>
<H3>
Determine the location of the mouse.
</H3>
<P>
Call the API <TT>GetCursorPos</TT> function. You pass the function a
pointer to a windows <TT>POINT</TT> structure (in BCB, <TT>TPoint</TT> is the same
thing as the windows <TT>POINT</TT> structure). Here is a code example. To use
this code, create a new project, place a <TT>TLabel</TT> and a <TT>TTimer</TT>
on the form, and place the code inside the <TT>OnTimer</TT> event of the <TT>TTimer</TT>
control. The program will display the mouse coordinates as you move the mouse.
</P>
<pre>
<b>void</b> <b>__fastcall</b> TForm1<b>:</b><b>:</b>Timer1Timer<b>(</b>TObject <b>*</b>Sender<b>)</b>
<b>{</b>
TPoint pt<b>;</b>
GetCursorPos<b>(</b><b>&</b>pt<b>)</b><b>;</b>
Label1<b>-></b>Caption <b>=</b> <font color="blue">"("</font> <b>+</b>
IntToStr<b>(</b>pt<b>.</b>x<b>)</b> <b>+</b>
<font color="blue">")("</font> <b>+</b>
IntToStr<b>(</b>pt<b>.</b>y<b>)</b> <b>+</b>
<font color="blue">")"</font><b>;</b>
<b>}</b>
</pre>
</TD> </TR>
</TABLE>
</CENTER>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?