윈도우즈가 설치되면 수많은 Dll 들이 설치가 되는데 대부분의 함수들은 Windows API 문서에 기술이 되지만 그렇지 않은 함수들도 많이 존재한다.
그런 함수들 중 하나로 일정 시간 지나면 스스로 사라지는 메세지박스가 user32.dll에 포함되어 있다.
MessageBoxTimeout 함수는 다음과 같다.
1 |
int MessageBoxTimeoutA(IN HWND hWnd, IN LPCSTR lpText, |
2 |
IN LPCSTR lpCaption, IN UINT uType, |
3 |
IN WORD wLanguageId, IN DWORD dwMilliseconds); |
4 |
int MessageBoxTimeoutW(IN HWND hWnd, IN LPCWSTR lpText, |
5 |
IN LPCWSTR lpCaption, IN UINT uType, |
6 |
IN WORD wLanguageId, IN DWORD dwMilliseconds); |
이 함수를 이용하기 위해서는 라이브러리를 읽어와서 함수 포인터를 연결해 주어야한다.
1 |
static MSGBOXAAPI MsgBoxTOA = NULL; |
3 |
HMODULE hUser32 = GetModuleHandle(_T( "user32.dll" )); |
6 |
MsgBoxTOA = (MSGBOXAAPI)GetProcAddress(hUser32, |
MessageBoxTimeout 함수의 반환값 보통 메세지 박스와 같지만 시간이 경과하여 자동으로 사라질 경우에는 OK 버튼일 경우 1을 넘겨주고 YESNO 같은 선택형일 경우 MB_TIMEOUT(=3200) 값을 넘겨준다.
MessageBoxTimeout 함수를 편하게 사용하도록 정리된 헤더파일
06 |
typedef int (__stdcall *MSGBOXAAPI)(IN HWND hWnd, |
07 |
IN LPCSTR lpText, IN LPCSTR lpCaption, |
08 |
IN UINT uType, IN WORD wLanguageId, |
09 |
IN DWORD dwMilliseconds); |
10 |
typedef int (__stdcall *MSGBOXWAPI)(IN HWND hWnd, |
11 |
IN LPCWSTR lpText, IN LPCWSTR lpCaption, |
12 |
IN UINT uType, IN WORD wLanguageId, |
13 |
IN DWORD dwMilliseconds); |
15 |
int MessageBoxTimeoutA(IN HWND hWnd, IN LPCSTR lpText, |
16 |
IN LPCSTR lpCaption, IN UINT uType, |
17 |
IN WORD wLanguageId, IN DWORD dwMilliseconds); |
18 |
int MessageBoxTimeoutW(IN HWND hWnd, IN LPCWSTR lpText, |
19 |
IN LPCWSTR lpCaption, IN UINT uType, |
20 |
IN WORD wLanguageId, IN DWORD dwMilliseconds); |
23 |
#define MessageBoxTimeout MessageBoxTimeoutW |
25 |
#define MessageBoxTimeout MessageBoxTimeoutA |
28 |
#define MB_TIMEDOUT 32000 |
30 |
int MessageBoxTimeoutA( HWND hWnd, LPCSTR lpText, |
31 |
LPCSTR lpCaption, UINT uType, WORD wLanguageId, |
34 |
static MSGBOXAAPI MsgBoxTOA = NULL; |
38 |
HMODULE hUser32 = GetModuleHandle(_T( "user32.dll" )); |
41 |
MsgBoxTOA = (MSGBOXAAPI)GetProcAddress(hUser32, |
42 |
"MessageBoxTimeoutA" ); |
55 |
return MsgBoxTOA(hWnd, lpText, lpCaption, |
56 |
uType, wLanguageId, dwMilliseconds); |
62 |
int MessageBoxTimeoutW( HWND hWnd, LPCWSTR lpText, |
63 |
LPCWSTR lpCaption, UINT uType, WORD wLanguageId, |
66 |
static MSGBOXWAPI MsgBoxTOW = NULL; |
70 |
HMODULE hUser32 = GetModuleHandle(_T( "user32.dll" )); |
73 |
MsgBoxTOW = (MSGBOXWAPI)GetProcAddress(hUser32, |
74 |
"MessageBoxTimeoutW" ); |
87 |
return MsgBoxTOW(hWnd, lpText, lpCaption, |
88 |
uType, wLanguageId, dwMilliseconds); |
실제 함수 사용 예
02 |
UINT uiFlags = MB_OK | MB_SETFOREGROUND | |
03 |
MB_SYSTEMMODAL | MB_ICONINFORMATION; |
05 |
iRet = MessageBoxTimeout(NULL, _T( "Test a timeout of 2 seconds." ), |
06 |
_T( "MessageBoxTimeout Test" ), uiFlags, 0, 2000); |
08 |
uiFlags = MB_YESNO | MB_SETFOREGROUND | |
09 |
MB_SYSTEMMODAL | MB_ICONINFORMATION; |
10 |
iRet = MessageBoxTimeout(NULL, _T( "Test a timeout of 5 seconds." ), |
11 |
_T( "MessageBoxTimeout Test" ), uiFlags, 0, 5000); |
댓글