⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.cpp

📁 本书《C++Builder与WindowsAPI经典范例》附含配套光盘包括132个WindowsAPI函数及206个完整、可执行的实例
💻 CPP
字号:
//---------------------------------------------------------------------------
//目的:由定时器定时检测鼠标屏幕位置,而取得其他程序窗口标题字符串
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{//将窗口永在桌面最上层与放置于右下角
FormStyle = fsStayOnTop;
Top = Screen->Height-Height;
Left = Screen->Width-Width;
Timer1->Interval = 100; //0.1秒定时器频率
}
//---------------------------------------------------------------------------
//由定时器定时检测鼠标屏幕位置,而取得窗口代码
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
POINT P;
::GetCursorPos(&P);//捕捉鼠标屏幕位置
//取得鼠标位置下窗口handle
HWND HWnd = ::WindowFromPoint(P);
//向此窗口送出"取得标题字符串"信息
char buffer[100];
SendMessage(HWnd, WM_GETTEXT, (WPARAM)100, (LPARAM)buffer);
//显现在Form1窗口的字符串对象上
StaticText2->Caption = buffer;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -