快手库我来做 (时光837253021)

[ 2362 查看 / 12 回复 ]

//公用对话框修改版--时光制作,欢迎大家继续在下面发成品库
//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*/

本主题由 管理员 admin 于 2010-4-17 2:12:56 执行 主题置顶/取消 操作
分享 转发
TOP

大力支持,楼下继续!
TOP

//例子代码
import win
import win.comdlg32
io.open()
print=io.print
x=win.opendlg()
if(x){
print(x)
}

x=win.opendlg("d:\")
if(x){
print(x)
}

x=win.opendlg("c:\","自己定义|*.txt")
if(x){
print(x)
}
x=win.savedlg()
if(x){
print(x)
}

x=win.savedlg("d:\")
if(x){
print(x)
}

x=win.savedlg("c:\","文本文件|*.txt")
if(x){
print(x)
}
io.close()
TOP

支持,学习。
TOP

支持先
TOP

我复制了你的代码,怎么运行报错。需要做些什么设置吗?
TOP

最顶上的代码应该保存到
comdlg32.aau
新版本修改掉了
不过这个版本还是很不错的
TOP

顶一个
TOP

顶顶多
TOP

顶一下
主攻办公全自动,兼习游戏辅助,无其他语言基础。路漫漫,要一步一步坚持走下去。
TOP

虽然看不太懂,但支持时光~!
TOP

还是要学习下啊
Good mood,good eyeglasses
TOP

用 fsys.dlg库里的函数就可以,提供各种文件、目录对话框
  1. import fsys.dlg;

  2. io.open()
  3. io.print( "您选择了目录:",fsys.dlg.opendir() );
复制代码
Quicker and quicker! Quicker and better!
TOP