如題,呼叫GetWindowLongPtr(hWnd, GWLP_HINSTANCE)時回傳0,通用GetLastError獲取錯誤代碼,竟然也是0。完整代碼如下:
#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();
}
這里還有個問題,就是呼叫GetParent(hWnd);和GetWindowLongPtr(hWnd, GWLP_HWNDPARENT);獲得的父視窗句柄與Visual Studio 2017所帶的Spy++工具看到的不一樣。
請大神們指點迷津。謝謝!
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/282746.html
標籤:其它技術問題
上一篇:登錄器怎么拒絕三方軟體訪問
下一篇:C語言編程題,不會呀
