Einzelnen Beitrag anzeigen

Benutzerbild von turboPASCAL
turboPASCAL

Registriert seit: 8. Mai 2005
Ort: Sondershausen
4.274 Beiträge
 
Delphi 6 Personal
 
#2

AW: WINDOWS.BEEP für WINDOWS 7

  Alt 9. Jul 2010, 19:00
Wäre es so:
Delphi-Quellcode:
type
  BEEP_SET_PARAMETERS = record
    Frequency, Duration: cardinal;
  end;

const
  IOCTL_BEEP_SET = $10000;
  FNStr: array[0..9] of char = '\\.\piep'#0;
  FN: PChar = @FNStr[0];
  DEVNAME: PChar = @FNStr[3];

var
  DEVPATH: array[0..MAX_PATH] of char;

implementation

{$R *.dfm}

function WindowsBeep(Freq, Duration: cardinal): longint;
var
  hBeep, bRET: cardinal;
  BSP: BEEP_SET_PARAMETERS;
  ODN: longbool;
begin
  if (Freq = 0) and (Duration > 0) then
  begin
    Sleep(Duration);
    Result := S_OK;
  end else
  begin
    ODN := false;
    if QueryDosDevice(DEVNAME, DEVPATH, MAX_PATH) = 0 then
    begin
      DefineDosDevice(DDD_RAW_TARGET_PATH, DEVNAME, '\Device\Beep');
      ODN := true;
    end;
    hBeep := CreateFile(FN, GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, 0, 0);
    if hBeep <> INVALID_HANDLE_VALUE then
    begin
      BSP.Frequency := Freq;
      BSP.Duration := Duration;
      DeviceIOControl(hBeep, IOCTL_BEEP_SET, @Freq, sizeof(BSP), nil, 0, bRET, nil);
      if ODN then DefineDosDevice(DDD_REMOVE_DEFINITION, DEVNAME, nil);
      Sleep(BSP.Duration);
      CloseHandle(hBeep);
      Result := S_OK;
    end else
      Result := E_FAIL;
  end;
end;

function Beep(Freq, Duration: cardinal): Bool;
begin
  Result := WindowsBeep(Freq, Duration) = S_OK;
  sleep(0);
end;
nicht besser ?
Matti
Meine Software-Projekte - Homepage - Grüße vom Rüsselmops -Mops Mopser
  Mit Zitat antworten Zitat