1个回答
展开全部
要拦截消息的话可以通过SetConsoleCtrlHandler和HandlerRoutine函数(msdn一下),下面是简单例子:
#include <Windows.h>
#include <stdio.h>
BOOL MyHandler( DWORD dwCtrlType )
{
if ( dwCtrlType == CTRL_CLOSE_EVENT )
{
printf("Cannot close...\n");
return TRUE;
}
return FALSE;
}
void main()
{
SetConsoleCtrlHandler((PHANDLER_ROUTINE)MyHandler, TRUE);
printf("Please try to clsoe...\n");
while(1) {};
}
要禁止关闭按钮的话可以直接从系统菜单里移除,比如:
#define _WIN32_WINNT 0x0500
#include <Windows.h>
#include <stdio.h>
void main()
{
DeleteMenu(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE, MF_BYCOMMAND);
DrawMenuBar(GetConsoleWindow());
printf("Now you cannot close this window...\n");
system("pause");
}
#include <Windows.h>
#include <stdio.h>
BOOL MyHandler( DWORD dwCtrlType )
{
if ( dwCtrlType == CTRL_CLOSE_EVENT )
{
printf("Cannot close...\n");
return TRUE;
}
return FALSE;
}
void main()
{
SetConsoleCtrlHandler((PHANDLER_ROUTINE)MyHandler, TRUE);
printf("Please try to clsoe...\n");
while(1) {};
}
要禁止关闭按钮的话可以直接从系统菜单里移除,比如:
#define _WIN32_WINNT 0x0500
#include <Windows.h>
#include <stdio.h>
void main()
{
DeleteMenu(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE, MF_BYCOMMAND);
DrawMenuBar(GetConsoleWindow());
printf("Now you cannot close this window...\n");
system("pause");
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询