📄 timed_msgbox.cpp
字号:
/*
* Copyright (C) 2003-2007 Funambol, Inc
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*/
#include <windows.h>
#include "notify/timed_msgbox.h"
static HWND g_hwndTimedOwner;
static BOOL g_bTimedOut;
/**
*
* MessageBoxTimer
*
* The timer callback function that posts the fake quit message.
* This function causes the message box to exit because the message box
* has determined that the application is exiting.
*
*/
static void CALLBACK MsgBoxTimer(HWND hw, UINT uiMsg, UINT idEv, DWORD time)
{
g_bTimedOut = TRUE;
if (g_hwndTimedOwner)
EnableWindow(g_hwndTimedOwner, TRUE);
PostQuitMessage(0);
}
/**
*
* TimedMessageBox
*
* The same as the standard MessageBox, except that TimedMessageBox
* also accepts a timeout. If the user does not respond within the
* specified timeout, the value 0 is returned instead of one of the
* ID* values.
*
*/
int TimedMessageBox(HWND hwndOwner,
LPCTSTR pszMessage,
LPCTSTR pszTitle,
UINT flags,
DWORD dwTimeout)
{
UINT idTimer;
int iResult;
g_hwndTimedOwner = NULL;
g_bTimedOut = FALSE;
if (hwndOwner && IsWindowEnabled(hwndOwner))
g_hwndTimedOwner = hwndOwner;
//
// Set a timer to dismiss the message box.
idTimer = SetTimer(NULL, 0, dwTimeout, (TIMERPROC)MsgBoxTimer);
iResult = MessageBox(hwndOwner, pszMessage, pszTitle, flags);
//
// Finished with the timer.
KillTimer(NULL, idTimer);
//
// See if there is a WM_QUIT message in the queue if we timed out.
// Eat the message so we do not quit the whole application.
if (g_bTimedOut)
{
MSG msg;
PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE);
iResult = -1;
}
return iResult;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -