博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Undocumented MessageBoxTimeOut function
阅读量:6291 次
发布时间:2019-06-22

本文共 2989 字,大约阅读时间需要 9 分钟。

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
,如需转载请自行联系原作者
你可能感兴趣的文章
(轉貼) Eclipse + CDT + MinGW 安裝方法 (C/C++) (gcc) (g++) (OS) (Windows)
查看>>
还原数据库
查看>>
作业调度框架 Quartz.NET 2.0 beta 发布
查看>>
mysql性能的检查和调优方法
查看>>
项目管理中的导向性
查看>>
Android WebView 学习
查看>>
(转)从给定的文本中,查找其中最长的重复子字符串的问题
查看>>
HDU 2159
查看>>
spring batch中用到的表
查看>>
资源文件夹res/raw和assets的使用
查看>>
UINode扩展
查看>>
LINUX常用命令
查看>>
百度云盘demo
查看>>
概率论与数理统计习题
查看>>
初学structs2,简单配置
查看>>
Laravel5.0学习--01 入门
查看>>
时间戳解读
查看>>
sbin/hadoop-daemon.sh: line 165: /tmp/hadoop-hxsyl-journalnode.pid: Permission denied
查看>>
@RequestMapping 用法详解之地址映射
查看>>
254页PPT!这是一份写给NLP研究者的编程指南
查看>>