//公用对话框修改版--时光制作,欢迎大家继续在下面发成品库
//comdlg32 dll//windows公用对话框支持,例如打开文件对话框
import win;
namespace win.comdlg32
import raw;
dll = raw.loadDll("comdlg32.dll");
/*intellisense(::)*/
::OPENFILENAME = class{
INT lStructSize = 0;
INT hwndOwner = 0;
pointer hInstance ;
string lpstrFilter;
string lpstrCustomFilter;
INT nMaxCustFilter = 0;
INT nFilterIndex = 0;
string lpstrFile = ..raw.malloc(::_MAX_PATH);
INT nMaxFile = ::_MAX_PATH-1;
string lpstrFileTitle;
INT nMaxFileTitle = 0;
string lpstrInitialDir;
string lpstrTitle;
INT Flags = 0;
WORD nFileOffset = 0;
WORD nFileExtension = 0;
string lpstrDefExt;
pointer lCustData;
pointer lpfnHook;
string lpTemplateName;
pointer pvReserved;
INT dwReserved = 0;
INT FlagsEx = 0;
}
::GetOpenFileName = dll.api("GetOpenFileName","int(struct&)" )
::GetSaveFileName = dll.api("GetSaveFileName","int(struct&)" )
/*end intellisense*/
/*intellisense(win.comdlg32)*/
OpenFileDlg = function(dir, filter,flag){
var parenthwnd=0
var title="打开文件"
//=== Struct used by the standard file dialog
ofn = OPENFILENAME();
ofn.lStructSize = raw.sizeof(ofn);
//====== Query the current folder ;
var re,curdir = ::GetCurrentDirectory(::_MAX_PATH,::_MAX_PATH);
dir := curdir;
ofn.lpstrInitialDir=dir
//====== Try to set the hook
//ofn.lpfnHook = MyHook(hWnd, ID_FILE_OPEN, 0, 0);
ofn.lpfnHook = null; //MyHook(hWnd, ID_FILE_OPEN, 0, 0);
if( type(filter) == type.table ) begin
..table.push( filter,"");//为了让后面多一个\0
ofn.lpstrFilter = ..string.join( filter,'\0' )
end;
else if(type(filter) == type.string)
ofn.lpstrFilter = ..string.replace( filter,'|','\0');
else{
ofn.lpstrFilter = ..string.replace("所有文件|*.*",'|','\0');
}
//====== The filters string index (begins with 1)
ofn.nFilterIndex = 1;
//====== Dialog caption
ofn.lpstrTitle = title ;
ofn.nMaxFileTitle = #(ofn.lpstrTitle);
//====== Dialog style (only in Win2K)
ofn.Flags = ::_OFN_EXPLORER;
if(flag)ofn.Flags |= flag;
if(parenthwnd)
{
ofn.hwndOwner = parenthwnd;
}
else
{
ofn.hwndOwner =0
}
//====== Create and open the dialog (retuns 0 on failure)
if( GetOpenFileName(ofn) )
{
return ofn.lpstrFile ;
}
else
{
return
}
}
SaveFileDlg = function(dir,filter,flag){
var parenthwnd=0
var title="保存文件"
//=== Struct used by the standard file dialog
ofn = OPENFILENAME();
ofn.lStructSize = raw.sizeof(ofn);
//====== Query the current folder ;
var re,curdir = ::GetCurrentDirectory(::_MAX_PATH,::_MAX_PATH);
dir := curdir;
ofn.lpstrInitialDir=dir
//====== Try to set the hook
//ofn.lpfnHook = MyHook(hWnd, ID_FILE_OPEN, 0, 0);
ofn.lpfnHook = null; //MyHook(hWnd, ID_FILE_OPEN, 0, 0);
if( type(filter) == type.table ) begin
..table.push( filter,"");//为了让后面多一个\0
ofn.lpstrFilter = ..string.join( filter,'\0' )
end;
else if(type(filter) == type.string)
ofn.lpstrFilter = ..string.replace(filter, '|','\0');
else{
ofn.lpstrFilter = ..string.replace("所有文件|*.*",'|','\0');
}
//====== The filters string index (begins with 1)
ofn.nFilterIndex = 1;
//====== Dialog caption
ofn.lpstrTitle = title ;
ofn.nMaxFileTitle = #(ofn.lpstrTitle);
//====== Dialog style (only in Win2K)
ofn.Flags = ::_OFN_EXPLORER;
if(flag)ofn.Flags |= flag;
ofn.hwndOwner = parenthwnd;
//====== Create and open the dialog (retuns 0 on failure)
if( GetSaveFileName(ofn) )
{
return ofn.lpstrFile ;
}
else
{
return
}
}
::win.opendlg=OpenFileDlg
::win.savedlg=SaveFileDlg
/*end intellisense*/