展开全部
// 用MFC更简单.只是复制出来的代码就非常的长了.所以直接在控制台演示
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
/********************************/
// Code By PE_luck
// 演示MessageBox 自动倒计时5秒关闭
// 2008-10-28
// 百度:http://zhidao.baidu.com/question/73452996.html
/********************************/
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);
}
}
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
/********************************/
// Code By PE_luck
// 演示MessageBox 自动倒计时5秒关闭
// 2008-10-28
// 百度:http://zhidao.baidu.com/question/73452996.html
/********************************/
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);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
HWND hwnd = ::FindWindow(NULL, ...);
if(hwnd) ::SendMessage(WM_CLOSE);
if(hwnd) ::SendMessage(WM_CLOSE);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
if(ID_OK = AfxMe...)
{
exit(1);
}
{
exit(1);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询