#include <windows.h>
#pragma data_seg("HookSeg")
HWND hWnd = NULL;
HHOOK h_WndProc = NULL;
#pragma data_seg()
BOOL CALLBACK EnumWindowsProc(HWND hwnd,LPARAM lParam)
{
char szBuffer[500] = {'\0'};
GetWindowTextA(hwnd,szBuffer,500);
if( strcmp("about:blank - Microsoft Internet Explorer", szBuffer) == 0)
{
HWND *pWnd = reinterpret_cast<HWND*>(lParam);
*pWnd = hwnd;
return 0;
}
return 1;
}
LRESULT CALLBACK GetMessage(int nCode, WPARAM wParam,LPARAM lParam)
{
MSG *pCWPSTRUCT = (MSG*)lParam;
if( nCode >= 0 )
{
HANDLE hIeWnd = NULL;
EnumWindows(EnumWindowsProc, reinterpret_cast<LPARAM>(&hIeWnd));
if(pCWPSTRUCT->message == WM_CLOSE && hIeWnd == pCWPSTRUCT->hwnd )
{
MessageBoxA(hWnd,"不能关闭","提示",MB_OK | MB_ICONERROR);
return 0;
}
}
return CallNextHookEx(h_WndProc,nCode,wParam,lParam);
}
void SetHook(HWND hwnd)
{
hWnd = hwnd;
h_WndProc = SetWindowsHookExA(WH_GETMESSAGE , GetMessage, GetModuleHandleA("HOOK"),0);
}
void UnSetHook()
{
UnhookWindowsHookEx(h_WndProc);
}
消息是可以截获,但是renturn 0居然可以继续关闭,郁闷中,请大家指点
[此贴子已经被作者于2006-10-22 19:41:43编辑过]