MMCstDlg.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:57k
- {========================================================================}
- {= (c) 1995-98 SwiftSoft Ronald Dittrich =}
- {========================================================================}
- {= All Rights Reserved =}
- {========================================================================}
- {= D 01099 Dresden = Fax.: +49(0)351-8037944 =}
- {= Loewenstr.7a = info@swiftsoft.de =}
- {========================================================================}
- {= Actual versions on http://www.swiftsoft.de/index.html =}
- {========================================================================}
- {= This code is for reference purposes only and may not be copied or =}
- {= distributed in any format electronic or otherwise except one copy =}
- {= for backup purposes. =}
- {= =}
- {= No Delphi Component Kit or Component individually or in a collection=}
- {= subclassed or otherwise from the code in this unit, or associated =}
- {= .pas, .dfm, .dcu, .asm or .obj files may be sold or distributed =}
- {= without express permission from SwiftSoft. =}
- {= =}
- {= For more licence informations please refer to the associated =}
- {= HelpFile. =}
- {========================================================================}
- {= $Date: 20.10.98 - 16:34:15 $ =}
- {========================================================================}
- unit MMCstDlg;
- {$I COMPILER.INC}
- interface
- uses
- {$IFDEF WIN32}
- Windows,
- {$ELSE}
- WinProcs,
- WinTypes,
- {$ENDIF}
- Messages,
- SysUtils,
- Classes,
- Graphics,
- Controls,
- Forms,
- Dialogs,
- CommDlg,
- ExtCtrls,
- MMObj,
- MMWave,
- MMWavOut,
- MMPCMSup,
- MMWaveIO,
- MMRiff,
- MMMulDiv,
- MMUtils,
- MMString,
- MMACMDlg,
- MMADCvt,
- MMDIB;
- type
- {$IFNDEF WIN32}
- POpenFilenameA = ^TOpenFilenameA;
- TOpenFilenameA = record
- lStructSize: Longint;
- hWndOwner: HWnd;
- hInstance: THandle;
- lpstrFilter: PChar;
- lpstrCustomFilter: PChar;
- nMaxCustFilter: Longint;
- nFilterIndex: Longint;
- lpstrFile: PChar;
- nMaxFile: Longint;
- lpstrFileTitle: PChar;
- nMaxFileTitle: Longint;
- lpstrInitialDir: PChar;
- lpstrTitle: PChar;
- Flags: Longint;
- nFileOffset: Word;
- nFileExtension: Word;
- lpstrDefExt: PChar;
- lCustData: Longint;
- lpfnHook: function (Wnd: HWnd; Msg, wParam: Word; lParam: Longint): Word;
- lpTemplateName: PChar;
- end;
- {$ENDIF}
- TSelChangeEvent= procedure(Sender : TObject; Filename: String) of Object;
- TFileOKEvent = procedure(Sender : TObject; Filename: String; var IsOk: Boolean) of Object;
- TCommandEvent = procedure(Sender : TObject; Wnd,Parent,cmd: Integer) of Object;
- {-- TMMCustomOpenDialog -----------------------------------------------------}
- TMMCustomOpenDialog = class(TMMCommonDialog)
- private
- FHwnd : Hwnd; { Window handle for hook }
- FTemplateName : String; { Dialog template name }
- FHistoryList : TStrings;
- FOptions : TOpenOptions;
- FFilter : String;
- FFilterIndex : Integer;
- FInitialDir : String;
- FTitle : String;
- FDefaultExt : String;
- FFileName : TFileName;
- FFiles : TStrings;
- FTempFiles : TStringList;
- {$IFNDEF DELPHI4}
- FSizing : Boolean;
- {$ENDIF}
- { Custom event handlers }
- FOnCreate : TNotifyEvent;
- FOnDestroy : TNotifyEvent;
- FOnFileOK : TFileOkEvent;
- FOnSelChange : TSelChangeEvent;
- FOnCommand : TCommandEvent;
- procedure SetHistoryList(Value: TStrings);
- procedure SetInitialDir(const Value: string);
- protected
- function DoExecute(Func: Pointer): Bool;
- procedure DoCreate; dynamic;
- procedure DoDestroy; dynamic;
- procedure DoFileOK(FName: String; var IsOk: Boolean);dynamic;
- procedure DoSelChanged(FName: String);dynamic;
- procedure DoCommand(Wnd,Parent: Hwnd; cmd: Integer); dynamic;
- property OnCreate: TNotifyEvent read FOnCreate write FOnCreate;
- property OnDestroy: TNotifyEvent read FOnDestroy write FOnDestroy;
- property OnFileOK: TFileOKEvent read FOnFileOK write FOnFileOK;
- property OnSelChange: TSelChangeEvent read FOnSelChange write FOnSelChange;
- property OnCommand: TCommandEvent read FOnCommand write FOnCommand;
- property DefaultExt: string read FDefaultExt write FDefaultExt;
- property FileName: TFileName read FFileName write FFileName;
- property Filter: String read FFilter write FFilter;
- property FilterIndex: Integer read FFilterIndex write FFilterIndex default 1;
- property HistoryList: TStrings read FHistoryList write SetHistoryList;
- property InitialDir: string read FInitialDir write SetInitialDir;
- property Options: TOpenOptions read FOptions write FOptions default [];
- property Title: string read FTitle write FTitle;
- property TemplateName: string read FTemplateName write FTemplateName;
- {$IFNDEF DELPHI4}
- property EnableSizing: Boolean read FSizing write FSizing default False;
- {$ENDIF}
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- function Execute: Boolean; override;
- property Files: TStrings read FFiles;
- property Wnd: HWnd read FHWnd write FHWnd;
- end;
- {-- TMMWaveOpenDialog -------------------------------------------------------}
- TMMWaveOpenDialog = class(TMMCustomOpenDialog)
- private
- FWaveFile : TMMWaveFile;
- FADPCMConvert: TMMADPCMConverter;
- FWaveOut : TMMWaveOut;
- FDeviceID : integer;
- FTimer : TTimer;
- FData : Pointer;
- FForeColor : TColor;
- FColor : TColor;
- FLocatorColor: TColor;
- FPreview : Boolean;
- FAutoPlay : Boolean;
- FUpdating : Boolean;
- FOldPos : Longint;
- FScopeWnd : HWND;
- FScopeDefProc: TFarProc;
- FScopeOldProc: Longint;
- FDIBWnd : HWND;
- FDIBDefProc : TFarProc;
- FDIBOldProc : Longint;
- procedure WaveOutStart(Sender: TObject);
- procedure WaveOutStop(Sender: TObject);
- procedure TimerExpired(Sender: TObject);
- procedure UpdateWave;
- procedure UpdatePlayParams;
- procedure DrawLocator(var OldPos: Longint; NewPos: Longint);
- procedure CreatePCMData(DC: HDC; aRect: TRect);
- procedure DrawPCMData(DC: HDC; aRect: TRect);
- procedure DrawDISP(DC: HDC; aRect: TRect);
- procedure ScopeWndHookProc(var Message: TMessage);
- procedure DIBWndHookProc(var Message: TMessage);
- protected
- procedure DoCreate;override;
- procedure DoDestroy;override;
- procedure DoFileOK(FName: String; var IsOk: Boolean);override;
- procedure DoSelChanged(FName: String);override;
- procedure DoCommand(Wnd,Parent: Hwnd; cmd: Integer);override;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- published
- property OnFileOK: TFileOKEvent read FOnFileOK write FOnFileOK;
- property FileName;
- property Filter;
- property FilterIndex;
- property InitialDir;
- property Title;
- {$IFNDEF DELPHI4}
- property EnableSizing;
- {$ENDIF}
- property Options;
- property Color: TColor read FColor write FColor default clBlack;
- property ForeColor: TColor read FForeColor write FForeColor default clLime;
- property LocatorColor: TColor read FLocatorColor write FLocatorColor default clRed;
- property Preview: Boolean read FPreview write FPreview default False;
- property AutoPlay: Boolean read FAutoPlay write FAutoPlay default False;
- property DeviceID: integer read FDeviceID write FDeviceID default -1;
- end;
- {-- TMMWaveSaveDialog -------------------------------------------------------}
- TMMWaveSaveDialog = class(TMMWaveOpenDialog)
- public
- constructor Create(AOwner: TComponent); override;
- function Execute: Boolean; override;
- end;
- {-- TMMPictureOpenDialog ----------------------------------------------------}
- TMMPictureOpenDialog = class(TMMCustomOpenDialog)
- private
- FBitmap : TBitmap;
- FPicture : TPicture;
- FPreview : Boolean;
- FColor : TColor;
- FHookWnd : HWND;
- FDefProc : TFarProc;
- FOldProc : Longint;
- FLastFile : string;
- procedure UpdatePicture;
- procedure DrawPicture(DC: HDC; aRect: TRect);
- procedure WndHookProc(var Message: TMessage);
- protected
- procedure DoCreate;override;
- procedure DoDestroy;override;
- procedure DoFileOK(FName: String; var IsOk: Boolean);override;
- procedure DoSelChanged(FName: String);override;
- procedure DoCommand(Wnd,Parent: Hwnd; cmd: Integer);override;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- published
- property OnFileOK: TFileOKEvent read FOnFileOK write FOnFileOK;
- property DefaultExt;
- property FileName;
- property Filter;
- property FilterIndex default 1;
- property InitialDir;
- property Title;
- property Options;
- property Color: TColor read FColor write FColor default clWindow;
- property Preview: Boolean read FPreview write FPreview default False;
- end;
- {-- TMMPictureSaveDialog ----------------------------------------------------}
- TMMPictureSaveDialog = class(TMMPictureOpenDialog)
- public
- constructor Create(AOwner: TComponent); override;
- function Execute: Boolean; override;
- end;
- implementation
- {$IFDEF WIN32}
- {$R MMCSTDLG.D32}
- {$ELSE}
- {$R MMCSTDLG.D16}
- {$ENDIF}
- type
- TDisplayRec = packed record
- LeftMin : SmallInt;
- LeftMax : SmallInt;
- RightMin: SmallInt;
- RightMax: SmallInt;
- end;
- PDisplayData = ^TDisplayData;
- TDisplayData = array[0..0] of TDisplayRec;
- const
- lst1 = $0460; { FileListBox ID }
- lst2 = $0461; { DirListBox ID }
- cmb2 = $0471; { DriveListBox ID }
- BT_PLAY = 1000;
- CB_PREVIEW = 1001;
- CB_AUTOPLAY= 1002;
- LT_FORMAT = 1003;
- ST_SCOPE = 1004;
- ST_DIB = 1005;
- ST_PICTURE = 1000; { Preview window for Picture Dialog }
- Obj: TMMCustomOpenDialog = nil;
- const
- HookCtl3D: Boolean = False;
- DialogTitle: PChar = nil;
- var
- CD_LBSelCh: Word;
- CD_ShareVi: Word;
- CD_FileOK : Word;
- procedure InitDialogs;
- begin
- CD_LBSelCh := RegisterWindowMessage(LBSelChString);
- CD_ShareVi := RegisterWindowMessage(ShareViString);
- CD_FileOK := RegisterWindowMessage(FileOKString);
- end;
- {-- Center the given window on the screen -------------------------------------}
- procedure CenterWindow(Wnd: HWnd);
- var
- Rect: TRect;
- begin
- GetWindowRect(Wnd, Rect);
- SetWindowPos(Wnd, 0,
- (GetSystemMetrics(SM_CXSCREEN) - Rect.Right + Rect.Left) div 2,
- (GetSystemMetrics(SM_CYSCREEN) - Rect.Bottom + Rect.Top) div 3,
- 0, 0, SWP_NOACTIVATE or SWP_NOSIZE or SWP_NOZORDER);
- end;
- {$IFNDEF WIN32}
- function TaskModalDialog(DialogFunc: Pointer; var DialogData): Bool;
- type
- TDialogFunc = function(var DialogData): Bool;
- var
- ActiveWindow: HWnd;
- WindowList: Pointer;
- begin
- ActiveWindow := GetActiveWindow;
- WindowList := DisableTaskWindows(0);
- try
- Result := TDialogFunc(DialogFunc)(DialogData);
- finally
- EnableTaskWindows(WindowList);
- SetActiveWindow(ActiveWindow);
- end;
- end;
- {$ENDIF}
- {------------------------------------------------------------------------------}
- function ExtractFileName_A(P: PChar; var S: String): PChar;
- var
- Separator: Char;
- begin
- Separator := #0;
- Result := P;
- while (Result[0] <> #0) and (Result[0] <> Separator) do Inc(Result);
- SetString(S, P, Result - P);
- if Result[0] = Separator then Inc(Result);
- end;
- {------------------------------------------------------------------------------}
- function ExtractFileName_B(P: PChar; var S: string): PChar;
- var
- Separator: Char;
- begin
- Separator := '"';
- Result := P;
- while (Result[0] <> #0) and (Result[0] <> Separator) do Inc(Result);
- SetString(S, P, Result - P);
- while (Result[0] = Separator) or (Result[0] = ' ') do inc(Result);
- end;
- {------------------------------------------------------------------------------}
- procedure ExtractFileNames(P: PChar; FileList: TStringList);
- var
- DirName, FileName: string;
- begin
- FileList.Clear;
- P := ExtractFileName_A(P, DirName);
- P := ExtractFileName_A(P, FileName);
- if FileName = '' then
- FileList.Add(DirName)
- else
- repeat
- if (FileName[1] <> '') and ((Length(FileName) <= 3) or
- (FileName[2] <> ':') or (FileName[3] <> '')) then
- FileName := CheckPath(DirName,True) + FileName;
- FileList.Add(FileName);
- P := ExtractFileName_A(P, FileName);
- until FileName = '';
- end;
- {------------------------------------------------------------------------------}
- function FindLastFileName(FName: string): string;
- var
- DirName, FileName: string;
- Buf,P: PChar;
- begin
- Result := '';
- if (FName <> '') then
- begin
- Buf := StrAlloc(8192);
- try
- P := Buf;
- StrPCopy(P, FName);
- P := ExtractFileName_B(P, DirName);
- if DirName[Length(DirName)] = '' then SetLength(DirName, Length(DirName)-1);
- P := ExtractFileName_B(P, FileName);
- if FileName = '' then
- Result := DirName
- else
- repeat
- if (FileName[1] <> '') and ((Length(FileName) <= 3) or
- (FileName[2] <> ':') or (FileName[3] <> '')) then
- FileName := CheckPath(DirName,True) + FileName;
- Result := FileName;
- P := ExtractFileName_B(P, FileName);
- until FileName = '';
- finally
- StrDispose(Buf);
- end;
- end;
- end;
- {------------------------------------------------------------------------------}
- { Explorer hook. Centers the dialog on the screen in response to
- the WM_INITDIALOG message also distributes events}
- {$IFDEF WIN32}
- function ExplorerHook(Wnd: HWnd; Msg: UINT; WParam: WPARAM; LParam: LPARAM): UINT;stdcall;
- {$ELSE}
- function ExplorerHook(Wnd: HWnd; Msg, WParam: Word; LParam: Longint): Word; export;
- {$ENDIF}
- const
- BufSize = 8192;
- var
- Parent: HWnd;
- ofn : ^TOpenFileName;
- Len: Integer;
- FName: String;
- aResult: Boolean;
- Buf: PChar;
- i: integer;
- begin
- Result := 0;
- try
- Parent := GetParent(Wnd);
- case Msg of
- WM_INITDIALOG:
- begin
- if HookCtl3D then
- begin
- Subclass3DDlg(Wnd, CTL3D_ALL);
- SetAutoSubClass(True);
- end;
- {$IFDEF WIN32}
- if not NewStyleControls then
- {$ENDIF}
- CenterWindow(Wnd);
- ofn := Pointer(LParam); {remember object pointer }
- obj := Pointer(ofn^.lCustData);
- obj.FHWnd := Wnd;
- obj.DoCreate;
- Result := 1;
- end;
- WM_Destroy:
- begin
- {clean up }
- if assigned(obj) then
- begin
- obj.DoDestroy;
- obj.FHWND := 0;
- obj := nil;
- end;
- if HookCtl3D then SetAutoSubClass(False);
- end;
- WM_CTLCOLOR:
- if HookCtl3D and (@Ctl3DCtlColorEx <> nil) then
- Result := Ctl3DCtlColorEx(Wnd, Msg, WParam, LParam);
- {$IFDEF WIN32}
- { route notifications }
- WM_NOTIFY:
- begin
- { Center after INIT if requested }
- if (POFNotify(LParam)^.hdr.code = CDN_INITDONE) then
- CenterWindow(GetWindowLong(Wnd, GWL_HWNDPARENT));
- if assigned(obj) then
- begin
- { Dispatch each event }
- if (POFNotify(LParam)^.hdr.code = CDN_FILEOK) then
- begin
- aResult := True;
- if (ofAllowMultiSelect in obj.FOptions) then
- begin
- ExtractFileNames(POFNotify(LParam).lpOFN.lpstrFile, obj.FTempFiles);
- for i := 0 to obj.FTempFiles.Count-1 do
- begin
- obj.DoFileOK(obj.FTempFiles[i],aResult);
- if not aResult then break;
- end
- end
- else
- begin
- SetString(FName, POFNotify(LParam).lpOFN.lpstrFile,
- StrLen(POFNotify(LParam).lpOFN.lpstrFile));
- obj.DoFileOK(FName,aResult);
- end;
- Result := ord(not aResult);
- SetWindowLong(Wnd, DWL_MSGRESULT, ord(not aResult));
- end;
- if (POFNotify(LParam)^.hdr.code = CDN_SELCHANGE) then
- begin
- Buf := StrAlloc(BufSize);
- try
- Len := SendMessage(GetParent(Wnd),CDM_GETFILEPATH,BufSize,LongInt(Buf));
- SetString(FName,Buf,Len-1);
- obj.DoSelChanged(FName);
- finally
- StrDispose(Buf);
- end;
- end;
- end;
- end;
- {$ENDIF}
- { dispatch WM_COMMAND }
- WM_COMMAND:
- if assigned(obj) then obj.DoCommand(Wnd,Parent,LOWORD(WParam));
- {$IFNDEF WIN32}
- WM_NCACTIVATE,
- WM_NCPAINT,
- WM_SETTEXT:
- if HookCtl3D and (@Ctl3DDlgFramePaint <> nil) then
- begin
- { The following fixes a Ctrl3D bug under Windows NT }
- if (GetWinFlags and $4000 <> 0) and (Msg = WM_SETTEXT) and
- (DialogTitle <> nil) then
- LParam := Longint(DialogTitle);
- SetWindowLong(Wnd, DWL_MSGRESULT, Ctl3DDlgFramePaint(Wnd, Msg,
- WParam, LParam));
- Result := 1;
- end;
- {$ENDIF}
- else
- {$IFDEF WIN32}
- if not NewStyleControls then
- {$ENDIF}
- begin
- if (Msg = CD_FILEOK) then
- begin
- if assigned(obj) then
- begin
- aResult := True;
- if (ofAllowMultiSelect in obj.FOptions) then
- begin
- ExtractFileNames(POpenFileNameA(LParam)^.lpstrFile, obj.FTempFiles);
- for i := 0 to obj.FTempFiles.Count-1 do
- begin
- obj.DoFileOK(obj.FTempFiles[i],aResult);
- if not aResult then break;
- end;
- end
- else
- begin
- FName := StrPas(POpenFileNameA(LParam)^.lpstrFile);
- obj.DoFileOK(FName,aResult);
- end;
- Result := ord(not aResult);
- SetWindowLong(Wnd, DWL_MSGRESULT, ord(not aResult));
- end;
- end;
- if (Msg = CD_LBSelCh) then
- begin
- if (wParam = lst1) and assigned(obj) then
- begin
- Buf := StrAlloc(BufSize);
- try
- Len := SendDlgItemMessage(Wnd,lst1, LB_GETTEXT, LoWord(lParam), Longint(Buf));
- if (Len <> LB_Err) then
- begin
- FName := ExpandUNCFileName(StrPas(Buf));
- obj.DoSelChanged(FName);
- end;
- finally
- StrDispose(Buf);
- end;
- end;
- end;
- end;
- end;
- except
- Application.HandleException(nil);
- end;
- end;
- {== TMMCustomOpenDialog =======================================================}
- constructor TMMCustomOpenDialog.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- FHistoryList := TStringList.Create;
- FFiles := TStringList.Create;
- FTempFiles := TStringList.Create;
- FFilterIndex := 1;
- {$IFNDEF DELPHI4}
- FSizing := False;
- {$ENDIF}
- ErrorCode := ComponentRegistered(InitCode, Self, ClassName);
- if (ErrorCode <> 0) then RegisterFailed(InitCode, Self , ClassName);
- end;
- {-- TMMCustomOpenDialog -------------------------------------------------------}
- destructor TMMCustomOpenDialog.Destroy;
- begin
- FFiles.Free;
- FTempFiles.Free;
- FHistoryList.Free;
- inherited Destroy;
- end;
- {-- TMMCustomOpenDialog -------------------------------------------------------}
- function TMMCustomOpenDialog.DoExecute(Func: Pointer): Bool;
- const
- {$IFNDEF DELPHI4}
- OFN_ENABLESIZING = $00800000;
- {$ENDIF}
- {$IFNDEF DELPHI6}
- OFN_DONTADDTORECENT = $02000000;
- OFN_FORCESHOWHIDDEN = $10000000;
- {$ENDIF}
- {$IFDEF WIN32}
- {$IFDEF DELPHI6}
- MultiSelectBufferSize = High(Word) - 16;
- {$ELSE}
- MultiSelectBufferSize = 8192;
- {$ENDIF}
- OpenOptions: array [TOpenOption] of DWORD = (
- OFN_READONLY, OFN_OVERWRITEPROMPT, OFN_HIDEREADONLY,
- OFN_NOCHANGEDIR, OFN_SHOWHELP, OFN_NOVALIDATE, OFN_ALLOWMULTISELECT,
- OFN_EXTENSIONDIFFERENT, OFN_PATHMUSTEXIST, OFN_FILEMUSTEXIST,
- OFN_CREATEPROMPT, OFN_SHAREAWARE, OFN_NOREADONLYRETURN,
- OFN_NOTESTFILECREATE, OFN_NONETWORKBUTTON, OFN_NOLONGNAMES,
- OFN_EXPLORER, OFN_NODEREFERENCELINKS
- {$IFDEF DELPHI4}
- ,OFN_ENABLEINCLUDENOTIFY,
- OFN_ENABLESIZING
- {$ENDIF}
- {$IFDEF DELPHI6}
- ,OFN_DONTADDTORECENT,
- OFN_FORCESHOWHIDDEN
- {$ENDIF}
- );
- {$ELSE}
- MultiSelectBufferSize = 1000;
- OpenOptions: array [TOpenOption] of Longint = (
- OFN_READONLY, OFN_OVERWRITEPROMPT, OFN_HIDEREADONLY,
- OFN_NOCHANGEDIR, OFN_SHOWHELP, OFN_NOVALIDATE, OFN_ALLOWMULTISELECT,
- OFN_EXTENSIONDIFFERENT, OFN_PATHMUSTEXIST, OFN_FILEMUSTEXIST,
- OFN_CREATEPROMPT, OFN_SHAREAWARE, OFN_NOREADONLYRETURN,
- OFN_NOTEXTFILECREATE);
- {$ENDIF}
- var
- OpenFilename: TOpenFilename;
- Option: TOpenOption;
- CDefaultExt: array[0..3] of Char;
- CInitialDir: array[0..79] of Char;
- CTitle: array[0..79] of Char;
- CFilter: array[0..1023] of Char;
- CTemplate: array[0..257] of Char;
- S: string;
- function StrFilterCopy(P: PChar; const S: string): PChar;
- begin
- Result := nil;
- if S <> '' then
- begin
- {$IFDEF WIN32}
- { Because StrPCopy truncates 256 characters }
- Result := StrCopy(P,PChar(S));
- {$ELSE}
- Result := StrPCopy(P, S);
- {$ENDIF}
- while P^ <> #0 do
- begin
- if P^ = '|' then P^ := #0;
- Inc(P);
- end;
- Inc(P);
- P^ := #0;
- end;
- end;
- begin
- FFiles.Clear;
- FillChar(OpenFileName, SizeOf(OpenFileName), 0);
- with OpenFilename do
- try
- lStructSize := SizeOf(TOpenFilename);
- hInstance := {$IFDEF DELPHI3}SysInit.HInstance{$ELSE}System.HInstance{$ENDIF};
- lpstrFilter := StrFilterCopy(CFilter, FFilter);
- nFilterIndex := FFilterIndex;
- if ofAllowMultiSelect in FOptions then
- nMaxFile := MultiSelectBufferSize
- else
- {$IFDEF WIN32}
- nMaxFile := MAX_PATH;
- {$ELSE}
- nMaxFile := sizeof(TFileName);
- {$ENDIF}
- GetMem(lpstrFile, nMaxFile + 2);
- FillChar(lpstrFile^, nMaxFile + 2, 0);
- StrPCopy(lpstrFile, FFileName);
- lpstrInitialDir := StrPLCopy(CInitialDir, FInitialDir,
- SizeOf(CInitialDir) - 1);
- lpstrTitle := StrPLCopy(CTitle, FTitle, SizeOf(CTitle) - 1);
- if Length(FTitle) > 0 then DialogTitle := lpstrTitle;
- { Always enable hook }
- Flags := OFN_ENABLEHOOK;
- for Option := Low(Option) to High(Option) do
- if Option in FOptions then
- Flags := Flags or OpenOptions[Option];
- {$IFDEF WIN32}
- if NewStyleControls then
- begin
- Flags := Flags or OFN_EXPLORER;
- {$IFNDEF DELPHI4}
- if FSizing then Flags := Flags or OFN_ENABLESIZING;
- {$ENDIF}
- end
- else
- Flags := Flags and not OFN_EXPLORER;
- {$ENDIF}
- lpstrDefExt := StrPCopy(CDefaultExt, FDefaultExt);
- { add custom callback }
- lpfnHook := ExplorerHook;
- {$IFDEF WIN32}
- if NewStyleControls then
- HookCtl3D := False
- else
- {$ENDIF}
- HookCtl3D := Ctl3D;
- { add custom resource }
- if FTemplateName <> '' then
- begin
- lpTemplateName:= StrPLCopy(CTemplate, FTemplateName, SizeOf(CTemplate)-1);
- Flags := Flags or OFN_ENABLETEMPLATE;
- {$IFDEF WIN32}
- if not NewStyleControls then
- StrLCat(lpTemplateName,'OLD',SizeOf(CTemplate)-1);
- {$ENDIF}
- end;
- {$IFDEF WIN32}
- {$IFDEF TRIAL}
- {$DEFINE _HACK2}
- {$I MMHACK.INC}
- {$ENDIF}
- {$ENDIF}
- { allow callback to find object }
- lCustData:=LongInt(Self);
- hWndOwner := Application.Handle;
- Result := TaskModalDialog(Func, OpenFileName);
- DialogTitle := nil;
- if Result then
- begin
- if ofAllowMultiSelect in FOptions then
- begin
- ExtractFileNames(lpstrFile,TStringList(FFiles));
- FFileName := FFiles[0];
- end
- else
- begin
- ExtractFileName_A(lpstrFile, S);
- FFileName := S;
- FFiles.Add(FFileName);
- end;
- if (Flags and OFN_EXTENSIONDIFFERENT) <> 0 then
- Include(FOptions, ofExtensionDifferent)
- else
- Exclude(FOptions, ofExtensionDifferent);
- if (Flags and OFN_READONLY) <> 0 then
- Include(FOptions, ofReadOnly)
- else
- Exclude(FOptions, ofReadOnly);
- FFilterIndex := nFilterIndex;
- end;
- finally
- if lpstrFile <> nil then FreeMem(lpstrFile, nMaxFile + 2);
- end;
- end;
- {-- TMMCustomOpenDialog -------------------------------------------------------}
- procedure TMMCustomOpenDialog.SetHistoryList(Value: TStrings);
- begin
- {$IFDEF WIN32}
- {$IFDEF TRIAL}
- {$DEFINE _HACK1}
- {$I MMHACK.INC}
- {$ENDIF}
- {$ENDIF}
- FHistoryList.Assign(Value);
- end;
- {-- TMMCustomOpenDialog -------------------------------------------------------}
- procedure TMMCustomOpenDialog.SetInitialDir(const Value: string);
- var
- L: Integer;
- begin
- L := Length(Value);
- if (L > 1) and (Value[L] = '') and (Value[L - 1] <> ':') then Dec(L);
- FInitialDir := Copy(Value, 1, L);
- {$IFDEF WIN32}
- {$IFDEF TRIAL}
- {$DEFINE _HACK3}
- {$I MMHACK.INC}
- {$ENDIF}
- {$ENDIF}
- end;
- {-- TMMCustomOpenDialog -------------------------------------------------------}
- function TMMCustomOpenDialog.Execute: Boolean;
- begin
- Result := DoExecute(@GetOpenFileName);
- end;
- {-- TMMCustomOpenDialog -------------------------------------------------------}
- procedure TMMCustomOpenDialog.DoCreate;
- begin
- if assigned(FOnCreate) then
- FOnCreate(Self);
- end;
- {-- TMMCustomOpenDialog -------------------------------------------------------}
- procedure TMMCustomOpenDialog.DoDestroy;
- begin
- if assigned(FOnDestroy) then
- FOnDestroy(Self);
- end;
- {-- TMMCustomOpenDialog -------------------------------------------------------}
- procedure TMMCustomOpenDialog.DoFileOK(FName: String; var IsOk: Boolean);
- begin
- if assigned(FOnFileOK) then
- FOnFileOK(Self,FName,IsOK);
- end;
- {-- TMMCustomOpenDialog -------------------------------------------------------}
- procedure TMMCustomOpenDialog.DoSelChanged(FName: String);
- begin
- if assigned(FOnSelChange) then
- FOnSelChange(Self,FName);
- end;
- {-- TMMCustomOpenDialog -------------------------------------------------------}
- procedure TMMCustomOpenDialog.DoCommand(Wnd,Parent: Hwnd; cmd: Integer);
- begin
- if assigned(FOnCommand) then
- FOnCommand(Self,Wnd,Parent,cmd);
- end;
- {== TMMWaveOpenDialog =========================================================}
- constructor TMMWaveOpenDialog.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- Options := Options + [ofHideReadOnly];
- {$IFDEF WIN32}
- Options := Options + [ofNoNetworkButton];
- {$ENDIF}
- FPreview := False;
- FAutoPlay:=False;
- FDeviceID:= -1;
- FUpdating := False;
- FColor := clBlack;
- FForeColor := clLime;
- FLocatorColor := clRed;
- FData := nil;
- Title := LoadResStr(IDS_WAVEOPEN);
- DefaultExt:= 'wav';
- Filter := LoadResStr(IDS_WAVEFILTER);
- FScopeWnd := 0;
- FDIBWnd := 0;
- {$IFNDEF WIN32}
- if _WINNT_ then
- TemplateName := 'CustomWaveOpenDlgNT'
- else
- {$ENDIF}
- TemplateName := 'CustomWaveOpenDlg';
- end;
- {-- TMMWaveOpenDialog ---------------------------------------------------------}
- destructor TMMWaveOpenDialog.Destroy;
- begin
- DoDestroy;
- inherited Destroy;
- end;
- {-- TMMWaveOpenDialog ---------------------------------------------------------}
- procedure TMMWaveOpenDialog.DoCreate;
- var
- aRect: TRect;
- aBuf: array[0..20] of Char;
- begin
- if (FScopeWnd = 0) then
- begin
- FScopeWnd := GetDlgItem(Wnd,ST_SCOPE);
- FScopeDefProc := Pointer(GetWindowLong(FScopeWnd,GWL_WNDPROC));
- FScopeOldProc := SetWindowLong(FScopeWnd,GWL_WNDPROC,
- Longint(MakeObjectInstance(ScopeWndHookProc)));
- end;
- if (FDIBWnd = 0) then
- begin
- FDIBWnd := GetDlgItem(Wnd,ST_DIB);
- FDIBDefProc := Pointer(GetWindowLong(FDIBWnd,GWL_WNDPROC));
- FDIBOldProc := SetWindowLong(FDIBWnd,GWL_WNDPROC,
- Longint(MakeObjectInstance(DIBWndHookProc)));
- end;
- if (FData = nil) then
- begin
- { alloc the data buffer for the scope data }
- {$IFDEF WIN32}
- Windows.GetClientRect(FScopeWnd, aRect);
- {$ELSE}
- WinProcs.GetClientRect(FScopeWnd, aRect);
- {$ENDIF}
- FData := GlobalAllocPtr(GPTR, (aRect.Right-aRect.Left)*sizeOf(TDisplayRec));
- { now create some components }
- FWaveFile := TMMWaveFile.Create(Self);
- FWaveFile.Wave.TimeFormat := tfByte;
- FWaveFile.Wave.IOBufferSize := 4*32768;
- FADPCMConvert := TMMADPCMConverter.Create(Self);
- FADPCMConvert.Input := FWaveFile;
- FWaveOut := TMMWaveOut.Create(Self);
- FWaveOut.Input := FADPCMConvert;
- FWaveOut.OnStart := WaveOutStart;
- FWaveOut.OnStop := WaveOutStop;
- FWaveOut.BufferSize := 32768;
- FWaveOut.NumBuffers := 10;
- FWaveOut.TimeFormat := tfByte;
- if FWaveOut.NumDevs > 0 then
- FWaveOut.DeviceID := FDeviceId
- else EnableWindow(GetDlgItem(Wnd,CB_AutoPlay), False);
- FTimer := TTimer.Create(Self);
- FTimer.Enabled := False;
- FTimer.Interval := 50;
- FTimer.OnTimer := TimerExpired;
- end;
- EnableWindow(GetDlgItem(Wnd,BT_Play), False);
- EnableWindow(GetDlgItem(Wnd,CB_PREVIEW), False);
- SetDlgItemText(Wnd,CB_PREVIEW,StrPCopy(aBuf,LoadResStr(IDS_PREVIEW)));
- SendDlgItemMessage(Wnd,CB_PREVIEW, BM_SETCHECK, Ord(FPReview), 0);
- SendDlgItemMessage(Wnd,CB_AUTOPLAY, BM_SETCHECK, Ord(FAutoPlay), 0);
- {$IFDEF WIN32}
- if not NewStyleControls then
- {$ENDIF}
- begin
- { TODO: hier Texte im Dialog lokalisieren !!!
- oder gleich englische Resource verwenden }
- end;
- inherited DoCreate;
- end;
- {-- TMMWaveOpenDialog ---------------------------------------------------------}
- procedure TMMWaveOpenDialog.DoDestroy;
- begin
- if (FData <> nil) then
- begin
- { free the data buffer }
- GlobalFreePtr(FData);
- FData := nil;
- end;
- if (FWaveOut <> nil) then
- begin
- FWaveOut.Close;
- FWaveOut.Free;
- FWaveOut := nil;
- end;
- if (FADPCMConvert <> nil) then
- begin
- FADPCMConvert.Close;
- FADPCMConvert.Free;
- FADPCMConvert := nil;
- end;
- if (FWaveFile <> nil) then
- begin
- FWaveFile.Wave.FreeWave;
- FWaveFile.Free;
- FWaveFile := nil;
- end;
- if (FTimer <> nil) then
- begin
- FTimer.Free;
- FTimer := nil;
- end;
- if (FScopeWnd <> 0) then
- begin
- FreeObjectInstance(Pointer(SetWindowLong(FScopeWnd,GWL_WNDPROC,FScopeOldProc)));
- FScopeWnd := 0;
- end;
- if (FDIBWnd <> 0) then
- begin
- FreeObjectInstance(Pointer(SetWindowLong(FDIBWnd,GWL_WNDPROC,FDIBOldProc)));
- FDIBWnd := 0;
- end;
- inherited DoDestroy;
- end;
- {-- TMMWaveOpenDialog ---------------------------------------------------------}
- procedure TMMWaveOpenDialog.DoFileOK(FName: String; var IsOk: Boolean);
- begin
- if not (Self is TMMWaveSaveDialog) then
- begin
- IsOK := wioIsWaveFile(FName, RIFF_FILE);
- if not IsOK then
- MessageDlg(LoadResStr(IDS_WAVEINVALID), mtError, [mbOK], 0)
- else
- inherited DoFileOK(FName, IsOK);
- end
- else inherited DoFileOK(FName, IsOK);
- end;
- {-- TMMWaveOpenDialog ---------------------------------------------------------}
- procedure TMMWaveOpenDialog.DoSelChanged(FName: String);
- var
- LastName: String;
- begin
- if assigned(FWaveFile) then
- begin
- LastName := FindLastFileName(FName);
- if (LastName <> FWaveFile.Wave.FileName) then
- begin
- FWaveOut.Close;
- if wioIsWaveFile(LastName, RIFF_FILE) then
- begin
- FWaveFile.Wave.FileName := LastName;
- FADPCMConvert.Enabled := FADPCMConvert.CanConvert;
- end
- else
- FWaveFile.Wave.FreeWave;
- FUpdating := True;
- { make sure the item is first selected, then update }
- KillTimer(FScopeWnd,99);
- SetTimer(FScopeWnd,99,50,nil);
- end;
- end;
- inherited DoSelChanged(FName);
- end;
- {-- TMMWaveOpenDialog ---------------------------------------------------------}
- procedure TMMWaveOpenDialog.DoCommand(Wnd,Parent: Hwnd; cmd: Integer);
- begin
- if (Wnd = FHWnd) then
- begin
- if (cmd = BT_Play) and (FWaveOut.NumDevs > 0) then
- begin
- if not (wosPlay in FWaveOut.State) then
- begin
- if not FWaveFile.Wave.Empty and
- FWaveOut.QueryDevice(FWaveOut.DeviceID,FWaveOut.PWaveFormat) then
- try
- FWaveOut.Start;
- except
- { don't raise a exception here }
- end;
- end
- else FWaveOut.Close;
- end
- else if (cmd = CB_PREVIEW) then
- begin
- FPreview := SendDlgItemMessage(Wnd, CB_PREVIEW, BM_GetCheck, 0, 0)<> 0;
- if FPreview then FWaveOut.Close;
- UpdateWave;
- end
- else if (cmd = CB_AUTOPLAY) then
- begin
- FAutoPlay := SendDlgItemMessage(Wnd, CB_AUTOPLAY, BM_GetCheck, 0, 0)<> 0;
- if FAutoPlay then
- begin
- if not (wosPlay in FWaveOut.State) and
- not FWaveFile.Wave.Empty and
- FWaveOut.QueryDevice(FWaveOut.DeviceID,FWaveOut.PWaveFormat) then
- try
- FWaveOut.Start;
- except
- { don't raise a exception here }
- end;
- end
- else FWaveOut.Close;
- end;
- end;
- inherited DoCommand(Wnd,Parent,cmd);
- end;
- {-- TMMWaveOpenDialog ---------------------------------------------------------}
- procedure TMMWaveOpenDialog.WaveOutStart(Sender: TObject);
- begin
- FOldPos := -1;
- FTimer.Enabled := True;
- SetDlgItemText(Wnd,BT_PLAY,'Stop');
- end;
- {-- TMMWaveOpenDialog ---------------------------------------------------------}
- procedure TMMWaveOpenDialog.WaveOutStop(Sender: TObject);
- begin
- FTimer.Enabled := False;
- DrawLocator(FOldPos,-1);
- SetDlgItemText(Wnd,BT_PLAY,'Play');
- end;
- {-- TMMWaveOpenDialog ---------------------------------------------------------}
- procedure TMMWaveOpenDialog.DrawLocator(var OldPos: Longint; NewPos: Longint);
- Var
- OldPen: HPen;
- OldMode: integer;
- DC: HDC;
- aRect: TRect;
- X: integer;
- begin
- if not FPreview or (FWaveFile.Wave.FormatTag <> 1) then exit;
- {$IFDEF WIN32}
- Windows.GetClientRect(FScopeWnd, aRect);
- {$ELSE}
- WinProcs.GetClientRect(FScopeWnd, aRect);
- {$ENDIF}
- InflateRect(aRect, -2, -2);
- DC := GetDC(FScopeWnd);
- try
- OldPen := SelectObject(DC,CreatePen(PS_SOLID,1,ColorToRGB(FLocatorColor)));
- try
- OldMode := SetROP2(DC, R2_XORPEN);
- try
- if (OldPos <> -1) then
- begin
- { clear old locator }
- X := MulDiv32(aRect.Right-aRect.Left,OldPos,FWaveFile.Wave.DataSize);
- MoveToEx(DC,aRect.Left+X,aRect.Top, nil);
- LineTo(DC,aRect.Left+X,aRect.Bottom-1);
- end;
- { draw new locator }
- if (NewPos <> -1) then
- begin
- X := MulDiv32(aRect.Right-aRect.Left,NewPos,FWaveFile.Wave.DataSize);
- MoveToEx(DC,aRect.Left+X,aRect.Top, nil);
- LineTo(DC,aRect.Left+X,aRect.Bottom-1);
- end;
- OldPos := NewPos;
- finally
- SetROP2(DC, OldMode);
- end;
- finally
- DeleteObject(SelectObject(DC,OldPen));
- end;
- finally
- ReleaseDC(FScopeWnd,DC);
- end;
- end;
- {-- TMMWaveOpenDialog ---------------------------------------------------------}
- procedure TMMWaveOpenDialog.TimerExpired(Sender: TObject);
- begin
- if (wosPlay in FWaveOut.State) then
- DrawLocator(FOldPos,FWaveOut.Position);
- end;
- {-- TMMWaveOpenDialog ---------------------------------------------------------}
- procedure TMMWaveOpenDialog.DrawDISP(DC: HDC; aRect: TRect);
- var
- ParentDC: HDC;
- aBitmap: TBitmap;
- R: TRect;
- lpDisp: PDISP;
- hBM: HBITMAP;
- Clr: Longint;
- begin
- with FWaveFile.Wave, aRect do
- begin
- aBitmap := TBitmap.Create;
- with aBitmap, aBitmap.Canvas do
- try
- aBitmap.Width := aRect.Right-aRect.Left;
- aBitmap.Height := aRect.Bottom-aRect.Top;
- R := Rect(0,0,aBitmap.Width,aBitmap.Height);
- { find the right background color }
- ParentDC := GetDC(Wnd);
- clr := GetPixel(ParentDC,0,0);
- ReleaseDC(Wnd, ParentDC);
- { clear background }
- Brush.Color := clr;{ clBtnFace; }
- FillRect(R);
- if (FileName <> '') then
- begin
- lpDisp := PWaveIOInfo^.lpDisp^.pHead;
- while (lpDisp <> nil) do
- begin
- if (lpDisp^.cfid = CF_DIB) then break;
- lpDisp := lpDisp^.pNext;
- end;
- if (lpDisp <> nil) then
- begin
- InflateRect(R, -2, -2);
- { Frame3D(Canvas,R,clBtnShadow,clBtnHighLight,1);
- Frame3D(Canvas,R,clWindowFrame,cl3DLight,1); }
- DIB_Display(PDIB(lpDisp^.lpChunk),Canvas.Handle, R);
- end
- else
- begin
- InflateRect(R, -2, -2);
- hBM := LoadBitmap(HInstance, 'BMP_WAVE');
- DrawTransparentBitmap(Canvas.Handle, hBM,
- R.Left,R.Top,
- GetTransparentColor(hBM));
- DeleteObject(hBM);
- end;
- end;
- BitBlt(DC,aRect.Left,aRect.Top,aRect.Right-aRect.Left,
- aRect.Bottom-aRect.Top,
- aBitmap.Canvas.Handle, 0,0,SRCCOPY);
- finally
- aBitmap.Free;
- end;
- end;
- end;
- {-- TMMWaveOpenDialog ---------------------------------------------------------}
- procedure TMMWaveOpenDialog.CreatePCMData(DC: HDC; aRect: TRect);
- var
- i,aWidth,aHeight,Y1: integer;
- aResult,Bytes: Longint;
- ReadBuffer: PChar;
- Data: PDisplayData;
- Canvas: TCanvas;
- begin
- InflateRect(aRect, -2, -2);
- aWidth := aRect.Right-aRect.Left;
- aHeight := aRect.Bottom-aRect.Top;
- FillChar(FData^, aWidth*sizeOf(TDisplayRec),0);
- if not FWaveFile.Wave.Empty and FPreview then
- with FWaveFile.Wave do
- begin
- Canvas := TCanvas.Create;
- with Canvas, aRect do
- try
- Handle := DC;
- Brush.Color := FColor;
- FillRect(aRect);
- Bytes := Max(DataSize div aWidth and not 3,4);
- ReadBuffer := GlobalAllocPtr(GHND, Bytes);
- try
- OpenFile;
- Position := 0;
- Data:= FData;
- Screen.Cursor := crHourGlass;
- Pen.Color := FForeColor;
- MoveTo(Left,Top+(aHeight div 2));
- i := 0;
- while (i < aWidth) do
- begin
- aResult := ReadDataBytes(ReadBuffer, Bytes);
- if aResult <= 0 then break;
- pcmFindMinMax(PWaveFormat,ReadBuffer, aResult,
- Data^[i].LeftMin,
- Data^[i].LeftMax,
- Data^[i].RightMin,
- Data^[i].RightMax);
- if (BitLength = 8) then
- begin
- Data^[i].LeftMin := (Word(Data^[i].LeftMin) shl 8) xor $8000;
- Data^[i].LeftMax := (Word(Data^[i].LeftMax) shl 8) xor $8000;
- Data^[i].RightMin:= (Word(Data^[i].RightMin) shl 8) xor $8000;
- Data^[i].RightMax:= (Word(Data^[i].RightMax) shl 8) xor $8000;
- end;
- Brush.Color := FColor;
- FillRect(Rect(Left+i,Top,Left+i+1,Bottom));
- Y1 := MulDiv32(Min(Data^[i].LeftMin,Data^[i].RightMin)+ Long($7FFF),aHeight,$FFFF);
- LineTo(Left+i, Bottom-Y1-1);
- Y1 := MulDiv32(Max(Data^[i].LeftMax,Data^[i].RightMax)+ Long($7FFF),aHeight,$FFFF);
- LineTo(Left+i, Bottom-Y1-1);
- Brush.Color := FLocatorColor;
- if (i < aWidth-1) and (DataSize > 1024*2048) then
- FillRect(Rect(Left+i+1,Top,Left+i+2,Bottom));
- {$IFDEF WIN32}
- GDIFlush;
- {$ENDIF}
- inc(i);
- end;
- if (i < aWidth-1) then
- begin
- if (i > 0) then dec(i);
- MoveTo(Left+i, Top+(aHeight div 2));
- LineTo(Right, Top+(aHeight div 2));
- end;
- finally
- CloseFile;
- GlobalFreePtr(ReadBuffer);
- Screen.Cursor := crDefault;
- end;
- finally
- Canvas.Handle := 0;
- Canvas.Free;
- end;
- end;
- end;
- {-- TMMWaveOpenDialog ---------------------------------------------------------}
- procedure TMMWaveOpenDialog.DrawPCMData(DC: HDC; aRect: TRect);
- var
- i,Y1,aHeight: integer;
- R: TRect;
- Data: PDisplayData;
- aBitmap: TBitmap;
- begin
- with FWaveFile.Wave do
- begin
- aBitmap := TBitmap.Create;
- with aBitmap.Canvas, R do
- try
- aBitmap.Width := aRect.Right-aRect.Left;
- aBitmap.Height := aRect.Bottom-aRect.Top;
- R := Rect(0,0,aBitmap.Width,aBitmap.Height);
- { clear background }
- Brush.Color := FColor;
- FillRect(R);
- Frame3D(aBitmap.Canvas,R,clBtnShadow,clBtnHighLight,1);
- Frame3D(aBitmap.Canvas,R,clWindowFrame,cl3DLight,1);
- FOldPos := -1;
- if (FileName = '') or not FPreview or
- (FormatTag <> 1) or (DataSize <= 0) then
- begin
- { only draw a horizontal line }
- Pen.Color := clGray;
- MoveTo(Left+5, Top+(Bottom-Top) div 2);
- LineTo((Right-Left)-5,Top+(Bottom-Top) div 2);
- end
- else if not FUpdating then
- begin
- Data := FData;
- Pen.Color := FForeColor;
- aHeight := Bottom-Top;
- Y1 := MulDiv32(Min(Data^[0].LeftMin,Data^[0].RightMin) + Long($7FFF),aHeight,$FFFF);
- MoveTo(Left, Top+aHeight-Y1-1);
- Y1 := MulDiv32(Max(Data^[0].LeftMax,Data^[0].RightMax) + Long($7FFF),aHeight,$FFFF);
- LineTo(Left, Top+aHeight-Y1-1);
- i := 0;
- while i < Right-Left do
- begin
- Y1 := MulDiv32(Min(Data^[i].LeftMin,Data^[i].RightMin) + Long($7FFF),aHeight,$FFFF);
- LineTo(Left+i, Bottom-Y1-1);
- Y1 := MulDiv32(Max(Data^[i].LeftMax,Data^[i].RightMax) + Long($7FFF),aHeight,$FFFF);
- LineTo(Left+i, Bottom-Y1-1);
- inc(i);
- end;
- LineTo(Left+i, Bottom-Y1-1);
- end;
- BitBlt(DC,aRect.Left,aRect.Top,aRect.Right-aRect.Left,
- aRect.Bottom-aRect.Top,
- aBitmap.Canvas.Handle,0,0,SRCCOPY);
- finally
- aBitmap.Free;
- end;
- end;
- end;
- {-- TMMWaveOpenDialog ---------------------------------------------------------}
- procedure TMMWaveOpenDialog.UpdatePlayParams;
- begin
- if not FWaveFile.Wave.Empty and (FWaveOut.PWaveFormat <> nil) then
- begin
- { adjust the buffersize for best results }
- case Word(FWaveOut.PWaveFormat^.nSamplesPerSec) of
- 00000..15000: FWaveOut.BufferSize := 512;
- 15001..24000: FWaveOut.BufferSize := 1024;
- 24001..32000: FWaveOut.BufferSize := 2048;
- 32001..48000: FWaveOut.BufferSize := 3072;
- end;
- case FWaveOut.PWaveFormat^.wBitsPerSample of
- 1: FWaveOut.BufferSize := FWaveOut.BufferSize div 16;
- 2..4: FWaveOut.BufferSize := FWaveOut.BufferSize div 8;
- 5..7: FWaveOut.BufferSize := FWaveOut.BufferSize div 4;
- 9..16: FWaveOut.BufferSize := FWaveOut.BufferSize * 2;
- end;
- end;
- end;
- {-- TMMWaveOpenDialog ---------------------------------------------------------}
- procedure TMMWaveOpenDialog.UpdateWave;
- Label CheckDevice;
- var
- aBuf: array[0..256] of Char;
- Format,FormatName,Size: String;
- aRect: TRect;
- DC: HDC;
- begin
- {$IFDEF WIN32}
- Windows.GetClientRect(FDIBWnd, aRect);
- {$ELSE}
- WinProcs.GetClientRect(FDIBWnd, aRect);
- {$ENDIF}
- DC := GetDC(FDIBWnd);
- try
- DrawDISP(DC, aRect);
- finally
- ReleaseDC(FDIBWnd,DC);
- end;
- EnableWindow(GetDlgItem(Wnd,CB_PREVIEW), False);
- with FWaveFile.Wave do
- if (FileName = '') then
- begin
- Format := LoadResStr(IDS_WAVEUNKNOWN);
- SetDlgItemText(Wnd,LT_FORMAT,StrPCopy(aBuf, Format));
- EnableWindow(GetDlgItem(Wnd,BT_Play), False);
- {$IFDEF WIN32}
- Windows.GetClientRect(FScopeWnd, aRect);
- {$ELSE}
- WinProcs.GetClientRect(FScopeWnd, aRect);
- {$ENDIF}
- InvalidateRect(FScopeWnd, @aRect, False);
- end
- else
- begin
- acmGetFormatDescription(PWaveFormat,FormatName,Format);
- Size := '; ' + IntToStr(FileSize div 1024) + ' KB';
- SetDlgItemText(Wnd,LT_FORMAT,StrPCopy(aBuf, FormatName+'; '+Format+Size));
- {$IFDEF WIN32}
- Windows.GetClientRect(FScopeWnd, aRect);
- {$ELSE}
- WinProcs.GetClientRect(FScopeWnd, aRect);
- {$ENDIF}
- if (FormatTag = 1) and (DataSize > 0) then
- begin
- EnableWindow(GetDlgItem(Wnd,CB_PREVIEW), True);
- if FPreview then
- begin
- DC := GetDC(FScopeWnd);
- try
- CreatePCMData(DC,aRect);
- finally
- ReleaseDC(FScopeWnd, DC);
- end;
- goto CheckDevice;
- end;
- end;
- InvalidateRect(FScopeWnd, @aRect, False);
- CheckDevice:
- if (FWaveOut.NumDevs > 0) and not FWaveFile.Wave.Empty and
- FWaveOut.QueryDevice(FWaveOut.DeviceID,FWaveOut.PWaveFormat) and
- not (wosPlay in FWaveOut.State) then
- begin
- UpdatePlayParams;
- EnableWindow(GetDlgItem(Wnd,BT_Play), True);
- if FAutoPlay then
- try
- FWaveOut.Start;
- except
- { don't raise a exception here }
- end;
- end
- else EnableWindow(GetDlgItem(Wnd,BT_Play), False);
- end;
- end;
- {-- TMMWaveOpenDialog ---------------------------------------------------------}
- procedure TMMWaveOpenDialog.ScopeWndHookProc(var Message: TMessage);
- var
- DC: HDC;
- Paint: TPaintStruct;
- aRect: TRect;
- begin
- with Message do
- begin
- if (Msg = WM_Paint) then
- begin
- DC := BeginPaint(FScopeWnd,Paint);
- {$IFDEF WIN32}
- Windows.GetClientRect(FScopeWnd,aRect);
- {$ELSE}
- WinProcs.GetClientRect(FScopeWnd,aRect);
- {$ENDIF}
- DrawPCMData(DC,aRect);
- EndPaint(FScopeWnd, Paint);
- end
- else if (Msg = WM_TIMER) then
- begin
- KillTimer(FScopeWnd,wParam);
- FUpdating := False;
- UpdateWave;
- end
- else Result := CallWindowProc(FScopeDefProc,FScopeWnd,Msg,wParam,lParam);
- end;
- end;
- {-- TMMWaveOpenDialog ---------------------------------------------------------}
- procedure TMMWaveOpenDialog.DIBWndHookProc(var Message: TMessage);
- var
- DC: HDC;
- Paint: TPaintStruct;
- aRect: TRect;
- begin
- with Message do
- begin
- if (Msg = WM_Paint) then
- begin
- DC := BeginPaint(FDIBWnd,Paint);
- {$IFDEF WIN32}
- Windows.GetClientRect(FDIBWnd,aRect);
- {$ELSE}
- WinProcs.GetClientRect(FDIBWnd,aRect);
- {$ENDIF}
- DrawDISP(DC,aRect);
- EndPaint(FDIBWnd, Paint);
- end
- else Result := CallWindowProc(FDIBDefProc,FDIBWnd,Msg,wParam,lParam);
- end;
- end;
- {== TMMWaveSaveDialog =========================================================}
- constructor TMMWaveSaveDialog.Create(aOwner: TComponent);
- begin
- inherited Create(aOwner);
- Title := LoadResStr(IDS_WAVESAVE);
- end;
- {-- TMMWaveSaveDialog ---------------------------------------------------------}
- function TMMWaveSaveDialog.Execute: Boolean;
- begin
- Result := DoExecute(@GetSaveFileName);
- end;
- {== TMMPictureOpenDialog ======================================================}
- constructor TMMPictureOpenDialog.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- Options := Options + [ofHideReadOnly];
- {$IFDEF WIN32}
- Options := Options + [ofNoNetworkButton];
- {$ENDIF}
- FBitmap := TBitmap.Create;
- FPicture := TPicture.Create;
- FPreview := False;
- FColor := clWindow;
- FLastFile := '';
- Title := LoadResStr(IDS_PICTUREOPEN);
- DefaultExt := GraphicExtension(TGraphic);
- Filter := GraphicFilter(TGraphic);
- FilterIndex := 1;
- FHookWnd := 0;
- {$IFNDEF WIN32}
- if _WINNT_ then
- TemplateName := 'CustomPictureOpenDlgNT'
- else
- {$ENDIF}
- TemplateName := 'CustomPictureOpenDlg';
- end;
- {-- TMMPictureOpenDialog ------------------------------------------------------}
- destructor TMMPictureOpenDialog.Destroy;
- begin
- FBitmap.Free;
- FPicture.Free;
- inherited Destroy;
- end;
- {-- TMMPictureOpenDialog ------------------------------------------------------}
- procedure TMMPictureOpenDialog.DoCreate;
- var
- aBuf: array[0..20] of Char;
- begin
- if (FHookWnd = 0) then
- begin
- FHookWnd := GetDlgItem(Wnd,ST_PICTURE);
- FDefProc := Pointer(GetWindowLong(FHookWnd,GWL_WNDPROC));
- FOldProc := SetWindowLong(FHookWnd,GWL_WNDPROC,
- Longint(MakeObjectInstance(WndHookProc)));
- end;
- SetDlgItemText(Wnd,CB_PREVIEW,StrPCopy(aBuf,LoadResStr(IDS_PREVIEW)));
- SendDlgItemMessage(Wnd,CB_PREVIEW, BM_SETCHECK, Ord(FPReview), 0);
- {$IFDEF WIN32}
- if not NewStyleControls then
- {$ENDIF}
- begin
- { TODO: hier Texte im Dialog lokalisieren !!!
- oder gleich englische Resource verwenden }
- end;
- inherited DoCreate;
- end;
- {-- TMMPictureOpenDialog ------------------------------------------------------}
- procedure TMMPictureOpenDialog.DoDestroy;
- begin
- if (FHookWnd <> 0) then
- begin
- FreeObjectInstance(Pointer(SetWindowLong(FHookWnd,GWL_WNDPROC,FOldProc)));
- FHookWnd := 0;
- end;
- inherited DoDestroy;
- end;
- {-- TMMPictureOpenDialog ------------------------------------------------------}
- procedure TMMPictureOpenDialog.DoFileOK(FName: String; var IsOk: Boolean);
- begin
- { TODO: hier Format pr黤en ? }
- inherited DoFileOK(FName, IsOK);
- end;
- {-- TMMPictureOpenDialog ------------------------------------------------------}
- procedure TMMPictureOpenDialog.DoSelChanged(FName: String);
- var
- LastName: string;
- begin
- if assigned(FPicture) then
- begin
- if (FName <> '') then
- begin
- LastName := FindLastFileName(FName);
- if (LastName <> FLastFile) and FileExists(LastName) then
- begin
- try
- FPicture.LoadFromFile(LastName);
- FLastFile := LastName;
- except
- FPicture.Bitmap.Handle := 0;
- FPicture.Icon.Handle := 0;
- FPicture.Metafile.Handle := 0;
- FLastFile := '';
- end;
- UpdatePicture;
- end;
- end
- else if (FLastFile <> '') then
- begin
- FPicture.Bitmap.Handle := 0;
- FPicture.Icon.Handle := 0;
- FPicture.Metafile.Handle := 0;
- FLastFile := '';
- UpdatePicture;
- end;
- end;
- inherited DoSelChanged(FName);
- end;
- {-- TMMPictureOpenDialog ------------------------------------------------------}
- procedure TMMPictureOpenDialog.DoCommand(Wnd,Parent: Hwnd; cmd: Integer);
- begin
- if (Wnd = FHWnd) then
- begin
- if (cmd = CB_PREVIEW) then
- begin
- FPreview := SendDlgItemMessage(Wnd, CB_PREVIEW, BM_GetCheck, 0, 0)<> 0;
- UpdatePicture;
- end;
- end;
- inherited DoCommand(Wnd,Parent,cmd);
- end;
- {-- TMMPictureOpenDialog ------------------------------------------------------}
- procedure TMMPictureOpenDialog.DrawPicture(DC: HDC; aRect: TRect);
- const
- Space = 5;
- var
- aCanvas: TCanvas;
- oldPal: HPalette;
- Factor: Float;
- iWidth,iHeight: integer;
- begin
- with FPicture, aRect do
- begin
- aCanvas := TCanvas.Create;
- with aCanvas do
- try
- Handle := DC;
- { clear background }
- Brush.Color := clWindow;
- FillRect(aRect);
- Frame3D(aCanvas,aRect,clBtnShadow,clBtnHighLight,1);
- Frame3D(aCanvas,aRect,clWindowFrame,cl3DLight,1);
- if (Graphic <> nil) and not Graphic.Empty and FPreview then
- begin
- iWidth := FPicture.Width;
- iHeight := FPicture.Height;
- if (Graphic is TIcon) or (Graphic is TMetaFile) then
- begin
- if (iWidth < (Right-Left)-2*Space) and
- (iHeight < (Bottom-Top)-2*Space) then
- begin
- aRect := Bounds(((Right-Left) - iWidth) div 2,
- ((Bottom-Top) - iHeight) div 2,
- iWidth, iHeight);
- end;
- aCanvas.StretchDraw(aRect,Graphic);
- end
- else if (Graphic is TBitmap) then
- begin
- OldPal := SelectPalette(Handle,Bitmap.Palette,False);
- RealizePalette(Handle);
- if (iWidth < (Right-Left)-2*Space) and
- (iHeight < (Bottom-Top)-2*Space) then
- begin
- aRect := Bounds(((Right-Left) - iWidth) div 2,
- ((Bottom-Top) - iHeight) div 2,
- iWidth, iHeight);
- end
- else if (iWidth > iHeight) then
- begin
- Factor := ((Right-Left)-2*Space)/iWidth;
- iHeight := Trunc(iHeight * Factor);
- aRect.Top := Top+((Bottom-Top)-iHeight) div 2;
- aRect.Bottom := Top + iHeight;
- aRect.Left := Left+Space;
- aRect.Right := Right-Space;
- end
- else
- begin
- Factor := ((Bottom-Top)-2*Space)/iHeight;
- iWidth := Trunc(iWidth * Factor);
- aRect.Left := Left+((Right-Left)-iWidth) div 2;
- aRect.Right := Left + iWidth;
- aRect.Top := aRect.Top + Space;
- aRect.Bottom := Bottom - Space;
- end;
- aCanvas.StretchDraw(aRect,Graphic);
- SelectPalette(Handle, OldPal, False);
- RealizePalette(Handle);
- end;
- end;
- finally
- aCanvas.Handle := 0;
- aCanvas.Free;
- end;
- end;
- end;
- {-- TMMPictureOpenDialog ------------------------------------------------------}
- Procedure TMMPictureOpenDialog.UpdatePicture;
- var
- aRect: TRect;
- begin
- {$IFDEF WIN32}
- Windows.GetClientRect(FHookWnd, aRect);
- {$ELSE}
- WinProcs.GetClientRect(FHookWnd, aRect);
- {$ENDIF}
- InvalidateRect(FHookWnd, @aRect, False);
- end;
- {-- TMMPictureOpenDialog ------------------------------------------------------}
- procedure TMMPictureOpenDialog.WndHookProc(var Message: TMessage);
- var
- DC: HDC;
- Paint: TPaintStruct;
- aRect: TRect;
- begin
- with Message do
- begin
- if (Msg = WM_Paint) then
- begin
- DC := BeginPaint(FHookWnd,Paint);
- {$IFDEF WIN32}
- Windows.GetClientRect(FHookWnd,aRect);
- {$ELSE}
- WinProcs.GetClientRect(FHookWnd,aRect);
- {$ENDIF}
- DrawPicture(DC,aRect);
- EndPaint(FHookWnd, Paint);
- end
- else Result := CallWindowProc(FDefProc,FHookWnd,Msg,wParam,lParam);
- end;
- end;
- {== TMMPictureSaveDialog ======================================================}
- constructor TMMPictureSaveDialog.Create(aOwner: TComponent);
- begin
- inherited Create(aOwner);
- Title := LoadResStr(IDS_PICTURESAVE);
- end;
- {-- TMMPictureSaveDialog ------------------------------------------------------}
- function TMMPictureSaveDialog.Execute: Boolean;
- begin
- Result := DoExecute(@GetSaveFileName);
- end;
- initialization
- {$IFDEF WIN32}
- if not NewStyleControls then
- {$ENDIF}
- InitDialogs;
- end.