处理wh_shell的窗口销毁消息 [英] Handling wh_shell's window destroy message

查看:146
本文介绍了处理wh_shell的窗口销毁消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了WH_SHELL和WH_CBT钩子的应用程序,这个应用程序的问题是我能够挂钩窗口创建的消息但是对于窗口销毁消息我的应用程序只是崩溃,如果我评论窗口销毁代码应用程序工作很好,我已谷歌它,并没有找到解决方案。我最终关注的是如何在这个应用程序中处理窗口销毁消息。在下面提供必要的代码片段

这是我的挂钩dll

 LRESULT CALLBACK HookProc( int  nCode,WPARAM wParam,LPARAM lParam)
{
if (nCode == HCBT_KEYSKIPPED&&(lParam& 0x40000000))
{

}
else if (nCode == HCBT_SETFOCUS)
{
:: PostMessage(g_hSpyWin,MSG_MY_WM_SETFOCUS,wParam ,lParam);

}
其他 如果(nCode == HSHELL_WINDOWCREATED)
{
:: PostMessage(g_hSpyWin,MSG_MY_WM_ACTIVATE,wParam,lParam);
}
else if (nCode == HSHELL_WINDOWDESTROYED)
{
:: PostMessage(g_hSpyWin,MSG_MY_WM_DESTROY,wParam,lParam);
}
return CallNextHookEx( 0 ,nCode,wParam,lParam);
}



这是我的主要功能,这里我调用另一个函数OnNewCreateWindow()除了将创建窗口的信息写入文件外什么都不做。

 LRESULT OnNewWindowCreate(WPARAM wParam,LPARAM lParam)
{

thwnd =(HWND)wParam;
OnNewCreateWindow1(thwnd);
return S_OK;
}

LRESULT On_WindowDestroy(WPARAM wParam,LPARAM lParam)
{
dHwnd =(HWND)wParam;
MessageBox(NULL, 进入销毁窗口函数 销毁,MB_OK);
// OnWindowDestroy1(dHwnd);
返回 S_OK;
}
LRESULT CALLBACK WndProc(HWND hWnd,UINT消息,WPARAM wParam,LPARAM lParam)
{
if ( message == MSG_MY_WM_KEYDOWN)
return OnInterceptKeyStroke(wParam,lParam);

if (message == MSG_MY_WM_SETFOCUS)
return OnSetKeyboardFocus( wParam,lParam);

if (message == MSG_MY_WM_ACTIVATE)
return OnNewWindowCreate( wParam中,LPARAM);

if (message = MSG_MY_WM_DESTROY)
return On_WindowDestroy(wParam ,LPARAM);


开关(消息)
{
case WM_DESTROY:
PostQuitMessage( 0 );
break ;

默认
return DefWindowProc(hWnd,message,wParam ,lParam);
}
return 0 ;
}





这里在destroywindow函数中我输入了一个messagebox()当我执行应用程序时它只显示了消息框两次,然后存在application.i不知道我哪里出错或者我应该做些什么来处理毁灭窗口msg,如果我使用

解决方案

< blockquote> HEY终于找到了一个解决方法,而不是挂钩HSHELL_WINDOWDESTROY消息我只是使用从HSHELL_WINDOWCREATED返回的句柄来获取进程ID,我可以使用它来获取进程的句柄,我存储了进程id,句柄处理单个链接列表,然后在线程中写入一个检查函数,它将检查进程终止或不使用值进程id和句柄从链接列表处理的每1000毫秒,如果它终止我只是检索它的结束时间并将其存储为相同在链接列表中输入。我可以同时获得该过程的开始和结束时间......

我以为而不是思考解决方案为什么不解决问题...

谢谢你们......


i have written application for WH_SHELL and WH_CBT hooking,the problem with this application is that i''m able to hook window created messages but for window destroy messages my application just crashes,if i comment the window destroy code the application works fine,i have google it and found no solution.My ultimate concern is how can i handle window destroy message in this application.Posting the necessary code snippet below
this is my hooking dll

LRESULT CALLBACK HookProc (int nCode, WPARAM wParam, LPARAM lParam )
{		        
	if (nCode == HCBT_KEYSKIPPED && (lParam & 0x40000000))
	{        
		
	}
	else if (nCode == HCBT_SETFOCUS)
	{
		::PostMessage(g_hSpyWin, MSG_MY_WM_SETFOCUS, wParam, lParam);
	
	}
	else if(nCode==HSHELL_WINDOWCREATED)
	{
		::PostMessage(g_hSpyWin,MSG_MY_WM_ACTIVATE,wParam,lParam);
	}
	else if(nCode==HSHELL_WINDOWDESTROYED)
	{
		::PostMessage(g_hSpyWin,MSG_MY_WM_DESTROY,wParam,lParam);
	}
	return CallNextHookEx( 0, nCode, wParam, lParam);
}


this is my main function,here i call another function OnNewCreateWindow() which does nothing but writes information about created window into file.

LRESULT OnNewWindowCreate(WPARAM wParam,LPARAM lParam)
{
	
	thwnd=(HWND)wParam;
	OnNewCreateWindow1(thwnd);
	return S_OK;
}

LRESULT On_WindowDestroy(WPARAM wParam,LPARAM lParam)
{
	dHwnd=(HWND)wParam;
	MessageBox(NULL,"Into destroy window function","Destroy",MB_OK);
	//OnWindowDestroy1(dHwnd);
	return S_OK;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	if (message == MSG_MY_WM_KEYDOWN)
		return OnInterceptKeyStroke(wParam, lParam);

	if (message == MSG_MY_WM_SETFOCUS)
		return OnSetKeyboardFocus(wParam, lParam);

	if(message==MSG_MY_WM_ACTIVATE)
		return OnNewWindowCreate(wParam,lParam);

	if(message=MSG_MY_WM_DESTROY)
		return On_WindowDestroy(wParam,lParam);
		

	switch (message)
	{	
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
		
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}



Here in the destroywindow function i have entered a messagebox() when i execute the application it just shows the messagebox twice and then exists the application.i dont know where i''m going wrong or what should i do more to handle the destroy window msg,same happens if i use

解决方案

HEY finally found a work around,instead of hooking HSHELL_WINDOWDESTROY message i just use the handle returned from HSHELL_WINDOWCREATED to get the process id using which i could get the handle to process,i stored the process id,handle to process in a singly link list and then wrote a checking function in thread which would check every 1000 ms that a process is terminated or not using the values process id and handle to process from link list,if its terminated i simply retrieve its End time and store it for the same entry in the link list.Hence i could get both the start and end time of the process...
I thought instead of pondering on solution why not get a work around...
Thank you guys...


这篇关于处理wh_shell的窗口销毁消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆