Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Tutorials und Kurse (https://www.delphipraxis.net/36-tutorials-und-kurse/)
-   -   [Artikel] Selbst-schließende Messagebox - MessageBoxTimeout (https://www.delphipraxis.net/72859-%5Bartikel%5D-selbst-schliessende-messagebox-messageboxtimeout.html)

OG Karotte 20. Okt 2008 15:57

Re: [Artikel] Selbst-schließende Messagebox - MessageBoxTime
 
Hier ist er...

[Edit] Mist, zu langsam (und das auch noch ohne Google)...[/Edit]

fkerber 20. Okt 2008 16:44

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

Habe den Link im ersten Beitrag angepasst!


Ciao, Frederic

juergen 20. Okt 2008 19:55

Re: [Artikel] Selbst-schließende Messagebox - MessageBoxTime
 
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.


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:47 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz