I don't use delphi forms , and i don't want my programm to be bigger than 80
Ko,
so i can't use delphi components ....
thanks
Ludovick LAGREVOL
"Ludovick LAGREVOL - Ingetic" <new...@ingetic.com> schreef in bericht
news:8vjg7r$khc$1...@reader1.imaginet.fr...
Hi Ludovick,
Here is a useable source
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs,
StdCtrls;
const
{$EXTERNALSYM OFN_READONLY}
OFN_READONLY = $00000001;
{$EXTERNALSYM OFN_OVERWRITEPROMPT}
OFN_OVERWRITEPROMPT = $00000002;
{$EXTERNALSYM OFN_HIDEREADONLY}
OFN_HIDEREADONLY = $00000004;
{$EXTERNALSYM OFN_NOCHANGEDIR}
OFN_NOCHANGEDIR = $00000008;
{$EXTERNALSYM OFN_SHOWHELP}
OFN_SHOWHELP = $00000010;
{$EXTERNALSYM OFN_ENABLEHOOK}
OFN_ENABLEHOOK = $00000020;
{$EXTERNALSYM OFN_ENABLETEMPLATE}
OFN_ENABLETEMPLATE = $00000040;
{$EXTERNALSYM OFN_ENABLETEMPLATEHANDLE}
OFN_ENABLETEMPLATEHANDLE = $00000080;
{$EXTERNALSYM OFN_NOVALIDATE}
OFN_NOVALIDATE = $00000100;
{$EXTERNALSYM OFN_ALLOWMULTISELECT}
OFN_ALLOWMULTISELECT = $00000200;
{$EXTERNALSYM OFN_EXTENSIONDIFFERENT}
OFN_EXTENSIONDIFFERENT = $00000400;
{$EXTERNALSYM OFN_PATHMUSTEXIST}
OFN_PATHMUSTEXIST = $00000800;
{$EXTERNALSYM OFN_FILEMUSTEXIST}
OFN_FILEMUSTEXIST = $00001000;
{$EXTERNALSYM OFN_CREATEPROMPT}
OFN_CREATEPROMPT = $00002000;
{$EXTERNALSYM OFN_SHAREAWARE}
OFN_SHAREAWARE = $00004000;
{$EXTERNALSYM OFN_NOREADONLYRETURN}
OFN_NOREADONLYRETURN = $00008000;
{$EXTERNALSYM OFN_NOTESTFILECREATE}
OFN_NOTESTFILECREATE = $00010000;
{$EXTERNALSYM OFN_NONETWORKBUTTON}
OFN_NONETWORKBUTTON = $00020000;
{$EXTERNALSYM OFN_NOLONGNAMES}
OFN_NOLONGNAMES = $00040000;
{$EXTERNALSYM OFN_EXPLORER}
OFN_EXPLORER = $00080000;
{$EXTERNALSYM OFN_NODEREFERENCELINKS}
OFN_NODEREFERENCELINKS = $00100000;
{$EXTERNALSYM OFN_LONGNAMES}
OFN_LONGNAMES = $00200000;
{$EXTERNALSYM OFN_ENABLEINCLUDENOTIFY}
OFN_ENABLEINCLUDENOTIFY = $00400000;
{$EXTERNALSYM OFN_ENABLESIZING}
OFN_ENABLESIZING = $00800000;
{ Return values for the registered message sent to the hook function
when a sharing violation occurs. OFN_SHAREFALLTHROUGH allows the
filename to be accepted, OFN_SHARENOWARN rejects the name but puts
up no warning (returned when the app has already put up a warning
message), and OFN_SHAREWARN puts up the default warning message
for sharing violations.
Note: Undefined return values map to OFN_SHAREWARN, but are
reserved for future use. }
{$EXTERNALSYM OFN_SHAREFALLTHROUGH}
OFN_SHAREFALLTHROUGH = 2;
{$EXTERNALSYM OFN_SHARENOWARN}
OFN_SHARENOWARN = 1;
{$EXTERNALSYM OFN_SHAREWARN}
OFN_SHAREWARN = 0;
type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
tagOFNA = packed record
lStructSize: DWORD;
hWndOwner: HWND;
hInstance: HINST;
lpstrFilter: PAnsiChar;
lpstrCustomFilter: PAnsiChar;
nMaxCustFilter: DWORD;
nFilterIndex: DWORD;
lpstrFile: PAnsiChar;
nMaxFile: DWORD;
lpstrFileTitle: PAnsiChar;
nMaxFileTitle: DWORD;
lpstrInitialDir: PAnsiChar;
lpstrTitle: PAnsiChar;
Flags: DWORD;
nFileOffset: Word;
nFileExtension: Word;
lpstrDefExt: PAnsiChar;
lCustData: LPARAM;
lpfnHook: function(Wnd: HWND; Msg: UINT; wParam: WPARAM; lParam:
LPARAM): UINT stdcall;
lpTemplateName: PAnsiChar;
{ if (_WIN32_WINNT >= 0x0500)
void * pvReserved;
DWORD dwReserved;
DWORD FlagsEx;
#endif // (_WIN32_WINNT >= 0x0500)}
end;
var
Form1: TForm1;
function GetSaveFileName(var OpenFile: TagOFNA): Bool; stdcall;
implementation
function GetSaveFileName; external 'comdlg32.dll' name
'GetSaveFileNameA';
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
t : TagOFNA;
FileName : PChar;
begin
GetMem(FileName,MAX_PATH+1);
FillMemory(FileName,MAX_PATH+1,0);
t.lStructSize := SizeOf(TagOFNA);
t.hWndOwner := Self.Handle; //The owner of the dialog.
t.lpstrFilter := PChar('All files'+#0+'*.*'+#0+'Text
files'+#0+'*.txt'+#0#0); //The filter
t.lpstrCustomFilter := #0; // Don't know exactly what this is
t.nMaxCustFilter := 0;
t.nFilterIndex := 0; // 0 select the custom filter, 1 select the first
filter
// that stands in lpstrFilter, 2 select the second
filter...
t.lpstrFile := PChar('Test'+#0); //This text will come in the File name
edit box
//before the user can do anything.
//Afterwards the filename is stored
here.
t.nMaxFile := MAX_PATH;
t.nMaxFileTitle := MAX_PATH;
t.lpstrInitialDir := #0; //Standard dir
t.lpstrTitle := PChar('Save this file as...'); //The title of the
dialog
t.Flags := 0; //For this one you shoult look in the helpfile
t.lpstrDefExt := PChar('sav'); //If the user enters a filename without
a extension
//then this extension will be used. For
this the
//nFilterIndex must be 0 or else you get
the extension
//that, that extensions select. This
will also happen
//if the user enters a extension. So if
you select the
//extension *.txt and the user enters
test.aaa the
//filename will be test.aaa.txt
if GetSaveFileName(t) then begin
ShowMessage(String(t.lpstrFile));
end else
ShowMessage('No File selected');
FreeMem(FileName);
end;
end.