//
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
/********************************/
// Code By
/********************************/
HHOOK hook=NULL;
int MSGRET=0;
int k=0;
HWND MSGHWND,TEXTHWND;
UINT TD;
void CALLBACK TimerProc(
HWND hwnd,
UINT uMsg,
UINT idEvent,
DWORD dwTime )
{
if (k==0)
{
k=5;
SendMessageA(MSGHWND,WM_COMMAND,6,0);
}else
{
k--;
char title[100]={0};
sprintf(title,"退出时间还剩: %d 秒",k);
SetWindowText(TEXTHWND,title);
}
}
LRESULT CALLBACK CBTProc(
int nCode, // hook code
WPARAM wParam, // depends on hook code
LPARAM lParam // depends on hook code
)
{
if (nCode==WH_CBT)
{
UnhookWindowsHookEx(hook);
k=5;
MSGHWND=(HWND)wParam;
TEXTHWND=GetDlgItem(MSGHWND,65535);
TD=SetTimer(0,1,1000,(TIMERPROC)TimerProc);
}
return 0;
}
void main()
{
hook = SetWindowsHookEx(WH_CBT,(HOOKPROC)CBTProc,GetModuleHandle(NULL),0);
MSGRET=MessageBox(NULL,"退出时间还剩: 5 秒","提示信息:",0x40);
//MSGRET 用来确定你单击的是哪个按钮
MSG msg;
while (GetMessage(&msg,NULL,NULL,NULL))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}