MessageBoxTimeout

MessageBoxTimeout是一個微軟未公開的Windows API函式。實現定時訊息,功能類似於MessageBox。如果用戶不回應,能定時關閉訊息框。函式由user32.dll導出,windows2000及以下沒有此函式。

函式簡介,原型,參數,返回值,VB引用,VBA引用,C引用,易語言調用,

函式簡介

原型

int MessageBoxTimeoutA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType, WORD wLanguageId, DWORD dwMilliseconds);
int MessageBoxTimeoutW(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType, WORD wLanguageId, DWORD dwMilliseconds)

參數

hwnd
訊息框的擁有視窗。
lptext
訊息框的內容。
lpCaption
訊息框的標題。
uType
指定一個決定對話框的內容和行為的位標誌集。取值參照函式MessageBox的參數uType。
wLanguageId
函式擴展,一般取0。
dwMilliseconds
訊息框延遲關閉時間,單位:毫秒。
  

返回值

參照函式MessageBox的返回值。
如果逾時,即用戶未操作,訊息框自動關閉,返回32000。

VB引用

Private Declare Function MessageBoxTimeout Lib "user32" Alias "MessageBoxTimeoutA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long, ByVal wlange As Long, ByVal dwTimeout As Long) As Long
MessageBoxTimeout(Me.hwnd, "Hello World", "Tips", vbOKCancel, 0, 1000)'1秒後自動關閉視窗

VBA引用

#If VBA7 And Win64 Then
Private Declare PtrSafe Function MessageBoxTimeout Lib "user32" Alias "MessageBoxTimeoutA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long, ByVal wlange As Long, ByVal dwTimeout As Long) As Long
#Else
Private Declare Function MessageBoxTimeout Lib "user32" Alias "MessageBoxTimeoutA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long, ByVal wlange As Long, ByVal dwTimeout As Long) As Long
#End If
Private Sub 定時關閉MSGBox1()
x = MessageBoxTimeout(0, "Hello World", "兩秒後自動關閉", 68, 1, 20000)
Debug.Print x
End Sub
Private Sub 定時關閉MSGBox2()
x = MessageBoxTimeout(0, "Hello World", "兩秒後自動關閉", 3, 1, 20000)
Debug.Print x
End Sub
Private Sub 定時關閉MSGBox3()
MessageBoxTimeout 0, "Hello World", "兩秒後自動關閉", 0, 0, 20000
End Sub

C引用

{
int WINAPI MessageBoxTimeoutA(IN HWND hWnd, IN LPCSTR lpText, IN LPCSTR lpCaption, IN UINT uType, IN WORD wLanguageId, IN DWORD dwMilliseconds);
int WINAPI 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

易語言調用

.版本 2
.DLL命令 MessageBoxTimeoutA, 整數型, , "MessageBoxTimeoutA"
.參數 hwnd, 整數型
.參數 lpText, 文本型
.參數 lpCaption, 文本型
.參數 uType, 整數型
.參數 wlange, 整數型
.參數 dwTimeout, 整數型
用法:
MessageBoxTimeoutA (取視窗句柄 (), “Hello World”, “信息框”, 0, 0, 1000)

相關詞條

熱門詞條

聯絡我們