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 ,如需转载请自行联系原作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Undocumented_Secrets_of_MATLAB_Java_Programming.part2 Undocumented_Secrets_of_MATLAB_Java_Programming 第2部分(共3部分) http://undocumentedmatlab.com/books/matlab-java This book shows how using Java can significantly improve Matlab program appearance and functionality. This can be done easily and even without any prior Java knowledge. Readers are led step-by-step from simple to complex customizations. Within the book’s 700 pages, thousands of code snippets, hundreds of screenshots and ~1500 online references are provided to enable the utilization of this book as both a sequential tutorial and as a random-access reference suited for immediate use. This book demonstrates how: The Matlab programming environment relies on Java for numerous tasks, including networking, data-processing algorithms and graphical user-interface (GUI) We can use Matlab for easy access to external Java functionality, either third-party or user-created Using Java, we can extensively customize the Matlab environment and application GUI, enabling the creation of visually appealing and usable applications No prior Java knowledge is required. All code snippets and examples are self-contained and can generally be used as-is. Advanced Java concepts are sometimes used, but understanding them is not required to run the code. Java-savvy readers will find it easy to tailor code samples for their particular needs; for Java newcomers, an introduction to Java and numerous online references are provided. No toolbox, Simulink or Stateflow is necessary for using this book – only the core Matlab product. These extra tools indeed contain many other Java-based aspects, but they are not covered in this book. Perhaps a future book will describe them. This book shows readers how to use and discover the described components, using nothing but Matlab itself as the discovery tool. In no case is illegal hacking implied or necessary for the discovery or usage of anything presented in this book. As far as I know, everything in this book is legal and within the bounds of the Matlab license agreement.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值