指定したウィンドウサイズを動的に取得マウスの位置を取得し、HWND
3435 ワード
, , , , ,
:
の具体的な解析は以下の通りである.GetCursorPos(&pNow) //
hwndPointNow = WindowFromPoint(pNow); //
::GetWindowThreadProcessId(hwndPointNow, &dwProcessID);// PID
GetWindowRect(hwndPointNow, &rect);//
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
/************************************************************************************
* filename : main.cpp
* comment : The left mouse button, right pulley, message capture, access to the mouse window handle, window position.
* author : liangqidong <[email protected]>
* History : create by liangqidong @ 2017/09/18
*************************************************************************************/
#include
#include //CreateToolhelp32Snapshot
#include
#include
using namespace std;
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0) // ,
HWND GetWindowHandleByPID(DWORD dwProcessID)
{
HWND h = GetTopWindow(0);
while (h)
{
DWORD pid = 0;
DWORD dwTheardId = GetWindowThreadProcessId(h, &pid);
if (dwTheardId != 0)
{
if (pid == dwProcessID/*your process id*/)
{
// here h is the handle to the window
if (GetTopWindow(h))
{
return h;
}
// return h;
}
}
h = ::GetNextWindow(h, GW_HWNDNEXT);
}
return NULL;
}
int main()
{
HWND hwndNow = GetWindowHandleByPID(13956);
while (1)
{
POINT pNow = { 0, 0 };
if (GetCursorPos(&pNow)) //
{
HWND hwndPointNow = NULL;
DWORD dwProcessID = 0;
RECT rect;
hwndPointNow = WindowFromPoint(pNow); //
::GetWindowThreadProcessId(hwndPointNow, &dwProcessID);
if (13956 == dwProcessID)
{
GetWindowRect(hwndPointNow, &rect);
std::cout << " :" << (int)hwndNow<< std::endl; //
std::cout << " :" << (int)hwndPointNow << "ID:" << dwProcessID << std::endl; //
std::cout << " top:" << rect.top << std::endl; //
std::cout << " bottom:" << rect.bottom << std::endl; //
std::cout << " left:" << rect.left << std::endl; //
std::cout << " right:" << rect.right << std::endl; //
std::cout << " :" << rect.right - rect.left << std::endl; //
std::cout << " :" << rect.bottom - rect.top << std::endl; //
printf(" :");
if (KEY_DOWN(MOUSE_MOVED))printf(" ");
else printf(" ");
printf("
");
printf(" :");
if (KEY_DOWN(MOUSE_EVENT))printf(" ");
else printf(" ");
printf("
");
printf(" :");
if (KEY_DOWN(MOUSE_WHEELED))printf(" ");
else printf(" ");
printf("
");
}
Sleep(1000);
system("cls");//
}
}
return 0;
}
何か欠点があれば教えてください.具体的なコードはgitを参照してください[email protected]:snippets/2580563.gitクリックでリンクを開く