根据窗口句柄获取应用程序实例句柄失败
#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++工具看到的不一样。
请大神们指点迷津。谢谢!
相关推荐
win32+sdk教程与基础
这个资料是从最基础的window程序写的。然后,还有sdk的一些资料。;希望这个可以帮助大家打下基础
windows窗口创建代码
用vc编写创建窗口的代码,先对txt控件建立变量,对应变量设置为字符串型:m_strPassword,然后updatedata()一下,将用户输入的文字赋予m_strPassword变量,然后对字符串进行验证就可以了
Delphi下用WindowsAPI创建窗体.net-电脑资料.pdf
。。。
Win32窗口事例.txt
Win32下简单窗口实例 外加部分注解 希望大家喜欢
VC++常用函数
VC++常用函数一应俱全 内容举例: 在状态栏中添加时间 1)在String Table中添加New String,在此定义为ID_INDICATOR_CLOCK, 将其Caption设为00:00:00(由于状态栏根据Caption确定时间窗格的缺 省宽度,使用此值将为时间的显示预留空间)。注 2)在MainFrm.cpp中indicators声明处添加ID_INDICATOR_CLOCK,代 码如下: 这一步中ID_INDICATOR_CLOCK的插入位置将影响时间窗格在状态栏中 的显示位置。 3)安装定时器:在MainFrm.cpp中OnCreate函数处添加代码如下: int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { …… SetTimer(1,1000,NULL);//安装定时器,并将其时间间隔设为1000毫秒 return 0; } 4)编写时间处理函数:利用ClassWizard为CMainFrame类加入WM_TIMER 的消息处理函数OnTimer,并添加代码如下: void CMainFrame::OnTimer(UINT nIDEvent) {// TODO: Add your message handler code here and/or call default CTime time; time=CTime::GetCurrentTime();//得到当前时间 CString s=time.Format(″%H:%M:%S″);//转换时间格式,这里格式一定要大写 m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIn- dex(ID_INDICATOR_CLOCK),s); //显示时钟 CFrameWnd::OnTimer(nIDEvent);} 5)销毁定时器:利用ClassWizard为CMainFrame类加入WM_CLOSE的消息处理 函数OnClose,并添加代码如下: void CMainFrame::OnClose() {// TODO: Add your message handler code here and/or call default KillTimer(1);//销毁定时器


其它技术问题
