Einzelnen Beitrag anzeigen

Benutzerbild von juergen
juergen

Registriert seit: 10. Jan 2005
Ort: Bönen
1.164 Beiträge
 
Delphi 11 Alexandria
 
#13

Re: [Artikel] Selbst-schließende Messagebox - MessageBoxTime

  Alt 20. Okt 2008, 19:55
Hallo zusammmen,

hmm, interessant.
Bei Codegear habe ich noch folgendes gefunden (2 Flüchtigkeitsfehler wurden hierbei in meinem Beispielcode -ausgehend vom Code auf der Codegearseite- korrigiert):
Link zu Codegear
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    btn1: TButton;
    procedure btn1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

function MessageBoxTimeOut(hWnd: HWND; lpText: PChar; lpCaption: PChar;
                           uType: UINT; wLanguageId: WORD; dwMilliseconds: DWORD): Integer; stdcall;
function MessageBoxTimeOutA(hWnd: HWND; lpText: PChar; lpCaption: PChar;
                            uType: UINT; wLanguageId: WORD; dwMilliseconds: DWORD): Integer; stdcall;

function MessageBoxTimeOutW(hWnd: HWND; lpText: PWideChar; lpCaption: PWideChar;
                            uType: UINT; wLanguageId: WORD; dwMilliseconds: DWORD): Integer; stdcall;

implementation
 {$R *.dfm}

// this const is not defined in Windows.pas
const
  MB_TIMEDOUT = 32000;
function MessageBoxTimeOut; external user32 name 'MessageBoxTimeoutA';
function MessageBoxTimeOutA; external user32 name 'MessageBoxTimeoutA';
function MessageBoxTimeOutW; external user32 name 'MessageBoxTimeoutW';
//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.

procedure TForm1.btn1Click(Sender: TObject);
var
  iResult: Integer;
  iFlags: Integer;
begin
  // Define a MessagBox with an OK button and a timeout of 2 seconds
  iFlags := MB_OK or MB_SETFOREGROUND or MB_SYSTEMMODAL or MB_ICONINFORMATION;
  iResult := MessageBoxTimeout(Application.Handle, 'Test a timeout of 2 seconds.',
                             'MessageBoxTimeout Test', iFlags, 0, 2000);
  // iResult will = 1 (IDOK)
  ShowMessage(IntToStr(iResult));

  // Define a MessageBox with a Yes and No button and a timeout of 5 seconds
  iFlags := MB_YESNO or MB_SETFOREGROUND or MB_SYSTEMMODAL or MB_ICONINFORMATION;
  iResult := MessageBoxTimeout(Application.Handle, 'Test a timeout of 5 seconds.',
                              'MessageBoxTimeout Test', iFlags, 0, 5000);
  // iResult = MB_TIMEDOUT if no buttons clicked, otherwise
  // iResult will return the value of the button clicked
  case iResult of
  IDYES: // Pressed Yes button
    ShowMessage('Yes');
  IDNO: // Pressed the No button
    ShowMessage('No');
  MB_TIMEDOUT: // MessageBox timed out
    ShowMessage('TimedOut');
  end;
end;

end.
Jürgen
Indes sie forschten, röntgten, filmten, funkten, entstand von selbst die köstlichste Erfindung: der Umweg als die kürzeste Verbindung zwischen zwei Punkten. (Erich Kästner)
  Mit Zitat antworten Zitat