코드프로젝트를 둘러보던중 재밌는 소스가 있어서 소개하고자 합니다.
입력시간 후 메세지 박스가 닫히는 기능입니다.
일단 이 방법은 문서화가 되어있지 않기 때문에 여러 운영체제에서 테스트가 필요합니다.
출처 : http://www.codeproject.com/Articles/7914/MessageBoxTimeout-API
#include <windows.h>
#include <tchar.h>
//Functions & other definitions required-->
typedef int (__stdcall *MSGBOXAAPI)(IN HWND hWnd,
IN LPCSTR lpText, IN LPCSTR lpCaption,
IN UINT uType, IN WORD wLanguageId, IN DWORD dwMilliseconds);
typedef int (__stdcall *MSGBOXWAPI)(IN HWND hWnd,
IN LPCWSTR lpText, IN LPCWSTR lpCaption,
IN UINT uType, IN WORD wLanguageId, IN DWORD dwMilliseconds);
int MessageBoxTimeoutA(IN HWND hWnd, IN LPCSTR lpText,
IN LPCSTR lpCaption, IN UINT uType,
IN WORD wLanguageId, IN DWORD dwMilliseconds);
int MessageBoxTimeoutW(IN HWND hWnd, IN LPCWSTR lpText,
IN LPCWSTR lpCaption, IN UINT uType,
IN WORD wLanguageId, IN DWORD dwMilliseconds);
#ifdef UNICODE
#define MessageBoxTimeout MessageBoxTimeoutW
#else
#define MessageBoxTimeout MessageBoxTimeoutA
#endif
#define MB_TIMEDOUT 32000
int MessageBoxTimeoutA(HWND hWnd, LPCSTR lpText,
LPCSTR lpCaption, UINT uType, WORD wLanguageId,
DWORD dwMilliseconds)
{
static MSGBOXAAPI MsgBoxTOA = NULL;
if (!MsgBoxTOA)
{
HMODULE hUser32 = GetModuleHandle(_T("user32.dll"));
if (hUser32)
{
MsgBoxTOA = (MSGBOXAAPI)GetProcAddress(hUser32,
"MessageBoxTimeoutA");
//fall through to 'if (MsgBoxTOA)...'
}
else
{
//stuff happened, add code to handle it here
//(possibly just call MessageBox())
return 0;
}
}
if (MsgBoxTOA)
{
return MsgBoxTOA(hWnd, lpText, lpCaption,
uType, wLanguageId, dwMilliseconds);
}
return 0;
}
int MessageBoxTimeoutW(HWND hWnd, LPCWSTR lpText,
LPCWSTR lpCaption, UINT uType, WORD wLanguageId, DWORD dwMilliseconds)
{
static MSGBOXWAPI MsgBoxTOW = NULL;
if (!MsgBoxTOW)
{
HMODULE hUser32 = GetModuleHandle(_T("user32.dll"));
if (hUser32)
{
MsgBoxTOW = (MSGBOXWAPI)GetProcAddress(hUser32,
"MessageBoxTimeoutW");
//fall through to 'if (MsgBoxTOW)...'
}
else
{
//stuff happened, add code to handle it here
//(possibly just call MessageBox())
return 0;
}
}
if (MsgBoxTOW)
{
return MsgBoxTOW(hWnd, lpText, lpCaption,
uType, wLanguageId, dwMilliseconds);
}
return 0;
}
//End required definitions <--
void TestMessageBox()
{
//you must load user32.dll before calling the functionHMODULE hUser32 = LoadLibrary(_T("user32.dll")); if (hUser32) { int iRet = 0; UINT uiFlags = MB_OK|MB_SETFOREGROUND|MB_SYSTEMMODAL|MB_ICONINFORMATION; iRet = MessageBoxTimeout(NULL, _T("Test a timeout of 2 seconds."), _T("MessageBoxTimeout Test"), uiFlags, 0, 2000); //iRet will = 1 uiFlags = MB_YESNO|MB_SETFOREGROUND|MB_SYSTEMMODAL|MB_ICONINFORMATION; iRet = MessageBoxTimeout(NULL, _T("Test a timeout of 5 seconds."), _T("MessageBoxTimeout Test"), uiFlags, 0, 5000); //iRet will = MB_TIMEDOUT if no buttons pressed, button values otherwise //only unload user32.dll when you have no further need //for the MessageBoxTimeout function FreeLibrary(hUser32); }
}
'프로그래밍 팁 > etc' 카테고리의 다른 글
| GetDriveTypeEx (0) | 2016.12.20 |
|---|---|
| 체크박스 WM_CTLCOLOR 사용 방법 (0) | 2013.05.31 |
| CreateCompatibleBitmap 주의사항 (2) | 2011.12.03 |
| 다이얼로그 구멍내기 (0) | 2011.11.25 |
| 비스타에서 권한무시 메세지 전송방법 (0) | 2011.10.12 |


