3,881
社区成员
发帖
与我相关
我的任务
分享
#include <windows.h>
#include <iostream>
using namespace std;
void testGetInstance()
{
const char *className = "TaskSwitcherWnd";
const char *windName = "任务切换";
HWND hWnd = FindWindow(className, windName);
cout << "window handle: " << hWnd << endl;
uint64_t tempHandle = GetWindowLongPtr(hWnd, GWLP_HWNDPARENT);
HWND hpWnd = *(HWND *)(&tempHandle);
cout << "parent window handle(from GetWindowLongPtr): " << hpWnd << endl;
hpWnd = GetParent(hWnd);
cout << "parent window handle(from GetParent): " << hpWnd << endl;
tempHandle = GetWindowLongPtr(hWnd, GWLP_HINSTANCE);
if (tempHandle == 0)
{
DWORD errorCode = GetLastError();
cout << "get instance handle error: " << errorCode << endl;
}
else
{
HINSTANCE hInst = *(HINSTANCE *)(&tempHandle);
cout << "instance handle: " << hInst << endl;
}
}
int main(int argc, char **argv)
{
testGetInstance();
}
const char *className = "TaskSwitcherWnd";
const char *windName = "任务切换";
HWND hWnd = FindWindow(NULL, windName);