Undocumented MessageBoxTimeOut function

简介:
There are lots of neat little things that are in many of the DLLs that Microsoft has installed in Windows. Most of them are documented in the Win32 API. However, there are a lot of them that are undocumented. This article shows how to use one of the undocumented functions available in user32.dll, MessageBoxTimeOut. 

This type of functionality for a MessageBox has been requested on the Delphi newsgroups many times and there have been several solutions written. After being introduced in XP, this functionality is now available to developers using this undocumented API. 

Since this function is not documented, it is not found in Windows.pas, so it has to be defined. It is identical to the MessageBox API definition except it has two more parameters, wLanguageID and dmMilliseconds. 

function MessageBoxTimeOut(
      hWnd: HWND; lpText: PChar; lpCaption: PChar;
      uType: UINT; wLanguageId: WORD; dwMilliseconds: DWORD): Integer; stdcall;
      external user32 name 'MessageBoxTimeoutA';
function MessageBoxTimeOutA(
      hWnd: HWND; lpText: PChar; lpCaption: PChar;
      uType: UINT; wLanguageId: WORD; dwMilliseconds: DWORD): Integer; stdcall;
      external user32 name 'MessageBoxTimeoutA';
function MessageBoxTimeOutW(
      hWnd: HWND; lpText: PWideChar; lpCaption: PWideChar;
      uType: UINT; wLanguageId: WORD; dwMilliseconds: DWORD): Integer; stdcall;
      external user32 name 'MessageBoxTimeoutW';

// this const is not defined in Windows.pas 
const 
  MB_TIMEDOUT = 32000; 

Now, to call the function, it is as easy as setting the flags and making the call. There may be other results returned that I am not aware of besides the standard IDxxx return values and the MB_TIMEDOUT result defined above. 

implementation

{$R 
* .dfm}
// interface declaration
function MessageBoxTimeOut(
      hWnd: HWND; lpText: PChar; lpCaption: PChar;
      uType: UINT; wLanguageId: WORD; dwMilliseconds: DWORD): Integer; stdcall;
      external user32 name 
' MessageBoxTimeoutA ' ;
function MessageBoxTimeOutA(
      hWnd: HWND; lpText: PChar; lpCaption: PChar;
      uType: UINT; wLanguageId: WORD; dwMilliseconds: DWORD): Integer; stdcall;
      external user32 name 
' MessageBoxTimeoutA ' ;
function MessageBoxTimeOutW(
      hWnd: HWND; lpText: PWideChar; lpCaption: PWideChar;
      uType: UINT; wLanguageId: WORD; dwMilliseconds: DWORD): Integer; stdcall;
      external user32 name 
' MessageBoxTimeoutW ' ;
const
  MB_TIMEDOUT 
=   32000 ;


procedure TForm3.Button1Click(Sender: TObject);
var
  iRet: Integer;
  iFlags: Integer;
begin
  iFlags :
=  MB_OK or MB_ICONINFORMATION;
  MessageBoxTimeout(Application.Handle, 
' Test a timeout of 2 seconds.  ' ' MessageBoxTimeout Test ' , iFlags,  0 2000 ) ;
  
  iFlags :
=  MB_YESNO or MB_ICONINFORMATION;
  iRet :
=  MessageBoxTimeout(Application.Handle,  ' Test a timeout of 5 seconds. ' ' MessageBoxTimeout Test ' , iFlags,  0 5000 ) ;   
  
case  iRet of  
    IDYES:
      ShowMessage(
' Yes ' );   
    IDNO:   
      ShowMessage(
' No ' );   
    MB_TIMEDOUT:   
      ShowMessage(
' TimedOut ' );   
  end;   

end;

end.




    本文转自 OldHawk  博客园博客,原文链接:http://www.cnblogs.com/taobataoma/archive/2007/08/15/856385.html ,如需转载请自行联系原作者

相关文章
|
9天前
|
数据处理
【报错】value.toFixed is not a function
在处理数据时遇到`value.toFixed is not a function`错误,原因在于`value`是字符串类型而非数字。通过`typeof(value)`确认其为string。解决方法是先将`value`转换为Number类型,如使用`parseFloat()`,再执行小数位处理。
|
5月前
|
Java
Function
Function
43 1
Function
|
7月前
|
JavaScript 前端开发
原型链中:为什么Function.proto==Function.prototype?
原型链中:为什么Function.proto==Function.prototype?
|
测试技术 C语言
Function(函数)
Function(函数)
77 0
报错:loaderContext.getResolve is not a function
报错:loaderContext.getResolve is not a function
|
Web App开发 JavaScript
$(...).find is not a function
$(...).find is not a function
165 0
|
Web App开发 JavaScript 前端开发
三千文字,也没写好 Function.prototype.call
Function.prototype.call,手写系列,万文面试系列,必会系列必包含的内容,足见其在前端的分量。 本文基于MDN 和 ECMA 标准,和大家一起从新认识call。
132 0
三千文字,也没写好 Function.prototype.call
ES6 箭头函数: () => {} 与匿名函数 function() {}
function foo() { setTimeout( () => { console.log("id:", this.id); },100); } foo.
1534 0