GaryFrost Posted December 9, 2007 Share Posted December 9, 2007 Seem to be doing something wrong on this, could use a fresh pair eyes and maybe get it figured out. expandcollapse popupGlobal Const $tagOFN = "dword StructSize;hwnd hwndOwner;hwnd hInstance;ptr lpstrFilter;ptr lpstrCustomFilter;dword nMaxCustFilter;" & _ "dword nFilterIndex;ptr lpstrFile;dword nMaxFile;ptr lpstrFileTitle;dword nMaxFileTitle;ptr lpstrInitialDir;ptr lpstrTitle;" & _ "dword Flags;long nFileOffset;int nFileExtension;ptr lpstrDefExt;lparam lCustData;ptr lpfnHook;ptr lpTemplateName;ptr pvReserved;" & _ "dword dwReserved;dword FlagsEx" Global Const $OFN_ALLOWMULTISELECT = 0x200 Global Const $OFN_CREATEPROMPT = 0x2000 Global Const $OFN_DONTADDTORECENT = 0x2000000 Global Const $OFN_ENABLEHOOK = 0x20 Global Const $OFN_ENABLEINCLUDENOTIFY = 0x400000 Global Const $OFN_ENABLESIZING = 0x800000 Global Const $OFN_ENABLETEMPLATE = 0x40 Global Const $OFN_ENABLETEMPLATEHANDLE = 0x80 Global Const $OFN_EXPLORER = 0x80000 Global Const $OFN_EXTENSIONDIFFERENT = 0x400 Global Const $OFN_FILEMUSTEXIST = 0x1000 Global Const $OFN_FORCESHOWHIDDEN = 0x10000000 Global Const $OFN_HIDEREADONLY = 0x4 Global Const $OFN_LONGNAMES = 0x200000 Global Const $OFN_NOCHANGEDIR = 0x8 Global Const $OFN_NODEREFERENCELINKS = 0x100000 Global Const $OFN_NOLONGNAMES = 0x40000 Global Const $OFN_NONETWORKBUTTON = 0x20000 Global Const $OFN_NOREADONLYRETURN = 0x8000 Global Const $OFN_NOTESTFILECREATE = 0x10000 Global Const $OFN_NOVALIDATE = 0x100 Global Const $OFN_OVERWRITEPROMPT = 0x2 Global Const $OFN_PATHMUSTEXIST = 0x800 Global Const $OFN_READONLY = 0x1 Global Const $OFN_SHAREAWARE = 0x4000 Global Const $OFN_SHOWHELP = 0x10 Global Const $OFN_EX_NOPLACESBAR = 0x1 Global Const $CDERR_DIALOGFAILURE = 0xFFFF Global Const $CDERR_FINDRESFAILURE = 0x6 Global Const $CDERR_INITIALIZATION = 0x2 Global Const $CDERR_LOADRESFAILURE = 0x7 Global Const $CDERR_LOADSTRFAILURE = 0x5 Global Const $CDERR_LOCKRESFAILURE = 0x8 Global Const $CDERR_MEMALLOCFAILURE = 0x9 Global Const $CDERR_MEMLOCKFAILURE = 0xA Global Const $CDERR_NOHINSTANCE = 0x4 Global Const $CDERR_NOHOOK = 0xB Global Const $CDERR_NOTEMPLATE = 0x3 Global Const $CDERR_REGISTERMSGFAIL = 0xC Global Const $CDERR_STRUCTSIZE = 0x1 Global Const $FNERR_BUFFERTOOSMALL = 0x3003 Global Const $FNERR_INVALIDFILENAME = 0x3002 Global Const $FNERR_SUBCLASSFAILURE = 0x3001 $sFile = _WinAPI_GetOpenFileName("My Open File Dialog", "Text File *.txt") If $sFile = 0 Then $sFile = _WinAPI_CommDlgExtendedError() ConsoleWrite("CommDlgExtendedError (" & @error & "): " & $sFile & @lf) EndIf Func _WinAPI_GetOpenFileName($sTitle, $sFilter, $sInitalDir = ".", $sFile = "", $iFilterIndex = 1, $iFlags = 0, $iFlagsEx = 0, $hwndOwner = 0) Local $tOFN = DllStructCreate($tagOFN) Local $tFilter = DllStructCreate("char Filter[" & StringLen($sFilter) + 1 & "]") Local $tInitialDir = DllStructCreate("char Dir[" & StringLen($sInitalDir) + 1 & "]") Local $tFile = DllStructCreate("char File[260]") Local $tTitle = DllStructCreate("char Title[" & StringLen($sTitle) + 1 & "]") Local $tFileTitle = DllStructCreate("char FileTitle[260]") Local $iResult DllStructSetData($tFilter, "Filter", $sFilter) DllStructSetData($tInitialDir, "Dir", $sInitalDir) DllStructSetData($tFile, "File", $sFile) DllStructSetData($tTitle, "Title", $sTitle) DllStructSetData($tFileTitle, "FileTitle", "") DllStructSetData($tOFN, "StructSize", DllStructGetSize($tOFN)) DllStructSetData($tOFN, "lpstrTitle", DllStructGetPtr($tTitle)) DllStructSetData($tOFN, "lpstrFilter", DllStructGetPtr($tFilter)) DllStructSetData($tOFN, "lpstrInitialDir", DllStructGetPtr($tInitialDir)) DllStructSetData($tOFN, "lpstrFile", DllStructGetPtr($tFile)) DllStructSetData($tOFN, "nMaxFile", 260) DllStructSetData($tOFN, "lpstrFileTitle", DllStructGetPtr($tFileTitle)) DllStructSetData($tOFN, "nMaxFileTitle", 260) DllStructSetData($tOFN, "nFilterIndex", $iFilterIndex) DllStructSetData($tOFN, "hwndOwnder", $hwndOwner) If BitAND($iFlags, $OFN_ALLOWMULTISELECT) = $OFN_ALLOWMULTISELECT Then BitOR($iFlags, $OFN_EXPLORER) DllStructSetData($tOFN, "Flags", $iFlags) DllStructSetData($tOFN, "FlagEx", $iFlagsEx) $iResult = DllCall("comdlg32.dll", "int", "GetOpenFileName", "ptr", DllStructGetPtr($tOFN)) If @error Then Return SetError(@error, @extended, 0) Return DllStructGetData($tOFN, "lpstrFile") EndFunc ;==>_WinAPI_GetOpenFileName Func _WinAPI_CommDlgExtendedError() Local $iResult = DllCall("comdlg32.dll", "dword", "CommDlgExtendedError") If @error Then Return SetError(@error, @extended, "") SetError($iResult[0]) Switch @error Case $CDERR_DIALOGFAILURE Return SetError(@error, 0, "The dialog box could not be created." & @LF & _ "The common dialog box function's call to the DialogBox function failed." & @LF & _ "For example, this error occurs if the common dialog box call specifies an invalid window handle.") Case $CDERR_FINDRESFAILURE Return SetError(@error, 0, "The common dialog box function failed to find a specified resource.") Case $CDERR_INITIALIZATION Return SetError(@error, 0, "The common dialog box function failed during initialization." & @LF & "This error often occurs when sufficient memory is not available.") Case $CDERR_LOADRESFAILURE Return SetError(@error, 0, "The common dialog box function failed to load a specified resource.") Case $CDERR_LOADSTRFAILURE Return SetError(@error, 0, "The common dialog box function failed to load a specified string.") Case $CDERR_LOCKRESFAILURE Return SetError(@error, 0, "The common dialog box function failed to lock a specified resource.") Case $CDERR_MEMALLOCFAILURE Return SetError(@error, 0, "The common dialog box function was unable to allocate memory for internal structures.") Case $CDERR_MEMLOCKFAILURE Return SetError(@error, 0, "The common dialog box function was unable to lock the memory associated with a handle.") Case $CDERR_NOHINSTANCE Return SetError(@error, 0, "The ENABLETEMPLATE flag was set in the Flags member of the initialization structure for the corresponding common dialog box," & @LF & _ "but you failed to provide a corresponding instance handle.") Case $CDERR_NOHOOK Return SetError(@error, 0, "The ENABLEHOOK flag was set in the Flags member of the initialization structure for the corresponding common dialog box," & @LF & _ "but you failed to provide a pointer to a corresponding hook procedure.") Case $CDERR_NOTEMPLATE Return SetError(@error, 0, "The ENABLETEMPLATE flag was set in the Flags member of the initialization structure for the corresponding common dialog box," & @LF & _ "but you failed to provide a corresponding template.") Case $CDERR_REGISTERMSGFAIL Return SetError(@error, 0, "The RegisterWindowMessage function returned an error code when it was called by the common dialog box function.") Case $CDERR_STRUCTSIZE Return SetError(@error, 0, "The lStructSize member of the initialization structure for the corresponding common dialog box is invalid") Case $FNERR_BUFFERTOOSMALL Return SetError(@error, 0, "The buffer pointed to by the lpstrFile member of the OPENFILENAME structure is too small for the file name specified by the user." & @LF & _ "The first two bytes of the lpstrFile buffer contain an integer value specifying the size, in TCHARs, required to receive the full name.") Case $FNERR_INVALIDFILENAME Return SetError(@error, 0, "A file name is invalid.") Case $FNERR_SUBCLASSFAILURE Return SetError(@error, 0, "An attempt to subclass a list box failed because sufficient memory was not available.") EndSwitch EndFunc SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
buzonjl Posted December 24, 2007 Share Posted December 24, 2007 hello, i will want help too, I attempt run DLLCALL winth GetOpenFileName, but by moment nothing of my attempt result. Mi code is: $dll = DllOpen("comdlg32.dll") $str1=" dword lStructSize; hwnd hwndOwner; hwnd hInstance; ptr lpstrFilter;" $str2=" ptr lpstrCustomFilter; int nMaxCustFilter; int nFilterIndex; ptr lpstrFile;" $str3=" int nMaxFile; ptr lpstrFileTitle; int nMaxFileTitle; ptr lpstrInitialDir;" $str4=" ptr lpstrTitle; dword Flags; int nFileOffset; int nFileExtension;" $str5=" ptr lpstrDefExt; ptr lCustData; ptr lpfnHook; ptr lpTemplateName;" $str6=" int pvReserved; int dwReserved; int FlagsEx" $openFN=DllStructCreate($str1 & $str2 & $str3 & $str4 & $str5 & $str6) MsgBox(0,"openFN","Struct Size: " & DllStructGetSize($openFN) & @CRLF & _ "Struct pointer: " & DllStructGetPtr($openFN) & @CRLF & _ "Data:" & @CRLF & _ DllStructGetData($openFN,0) & @CRLF & _ DllStructGetData($openFN,1) & @CRLF & _ DllStructGetData($openFN,2) & @CRLF & _ DllStructGetData($openFN,3) & @CRLF & _ DllStructGetData($openFN,4) & @CRLF & _ DllStructGetData($openFN,5) & @CRLF & _ DllStructGetData($openFN,6) & @CRLF & _ DllStructGetData($openFN,7) & @CRLF & _ DllStructGetData($openFN,8) & @CRLF & _ DllStructGetData($openFN,9) & @CRLF & _ DllStructGetData($openFN,10) & @CRLF & _ DllStructGetData($openFN,11) & @CRLF & _ DllStructGetData($openFN,12) & @CRLF & _ DllStructGetData($openFN,13) & @CRLF & _ DllStructGetData($openFN,14) & @CRLF & _ DllStructGetData($openFN,15) & @CRLF & _ DllStructGetData($openFN,16) & @CRLF & _ DllStructGetData($openFN,17) & @CRLF & _ DllStructGetData($openFN,18) & @CRLF & _ DllStructGetData($openFN,19) & @CRLF & _ DllStructGetData($openFN,20) & @CRLF & _ DllStructGetData($openFN,21) & @CRLF & _ DllStructGetData($openFN,22) & @CRLF & _ DllStructGetData($openFN,23) & @CRLF & _ DllStructGetData($openFN,24)) $sDir=DllStructCreate("char initDir[260]") DllStructSetData($sDir,"initDir","c:\") $sFile=DllStructCreate("char pathFile[260]") DllStructSetData($sFile,"pathFile",0,1) $sFilter=DllStructCreate("char filter[260]") DllStructSetData($sFilter,"filter","algo *.*") $hwnd=WinGetHandle("Untitled.txt - Bloc de notas") DllStructSetData($openFN,"lStructSize",DllStructGetSize($openFN)) ;dword DllStructSetData($openFN,"hwndOwner",0) ;hwnd DllStructSetData($openFN,"hInstance",0) ;hwnd DllStructSetData($openFN,"lpstrFilter",DllStructGetPtr($sFilter)) ;ptr DllStructSetData($openFN,"lpstrCustomFilter",0) ;ptr DllStructSetData($openFN,"nMaxCustFilter",0) ;int DllStructSetData($openFN,"nFilterIndex",1) ;int DllStructSetData($openFN,"lpstrFile",DllStructGetPtr($sFile)) ;ptr DllStructSetData($openFN,"nMaxFile",260) ;int DllStructSetData($openFN,"lpstrFileTitle",0) ;ptr DllStructSetData($openFN,"nMaxFileTitle",0) ;int DllStructSetData($openFN,"lpstrInitialDir",DllStructGetPtr($sDir)) ;ptr DllStructSetData($openFN,"lpstrTitle",0) ;ptr DllStructSetData($openFN,"Flags",0) ;dword DllStructSetData($openFN,"nFileOffset",0) ;int DllStructSetData($openFN,"nFileExtension",0) ;int DllStructSetData($openFN,"lpstrDefExt",0) ;ptr DllStructSetData($openFN,"lCustData",0) ;ptr DllStructSetData($openFN,"lpfnHook",0) ;ptr DllStructSetData($openFN,"lpTemplateName",0) ;ptr DllStructSetData($openFN,"pvReserved",0) ;int DllStructSetData($openFN,"dwReserved",0) ;int DllStructSetData($openFN,"FlagsEx",0) ;int MsgBox(0,"openFN","Struct Size: " & DllStructGetSize($openFN) & @CRLF & _ "Struct pointer: " & DllStructGetPtr($openFN) & @CRLF & _ "Data:" & @CRLF & _ DllStructGetData($openFN,0) & @CRLF & _ DllStructGetData($openFN,1) & @CRLF & _ DllStructGetData($openFN,2) & @CRLF & _ DllStructGetData($openFN,3) & @CRLF & _ DllStructGetData($openFN,4) & @CRLF & _ DllStructGetData($openFN,5) & @CRLF & _ DllStructGetData($openFN,6) & @CRLF & _ DllStructGetData($openFN,7) & @CRLF & _ DllStructGetData($openFN,8) & @CRLF & _ DllStructGetData($openFN,9) & @CRLF & _ DllStructGetData($openFN,10) & @CRLF & _ DllStructGetData($openFN,11) & @CRLF & _ DllStructGetData($openFN,12) & @CRLF & _ DllStructGetData($openFN,13) & @CRLF & _ DllStructGetData($openFN,14) & @CRLF & _ DllStructGetData($openFN,15) & @CRLF & _ DllStructGetData($openFN,16) & @CRLF & _ DllStructGetData($openFN,17) & @CRLF & _ DllStructGetData($openFN,18) & @CRLF & _ DllStructGetData($openFN,19) & @CRLF & _ DllStructGetData($openFN,20) & @CRLF & _ DllStructGetData($openFN,21) & @CRLF & _ DllStructGetData($openFN,22) & @CRLF & _ DllStructGetData($openFN,23) & @CRLF & _ DllStructGetData($openFN,24)) IF DllCall($dll, "wsrt", "GetOpenFileName","ptr",DllStructGetPtr($openFN)) Then MsgBox(0,"parece que vamos","Bien") EndIf $result=DllCall($dll,"int", "GetOpenFileName","ptr",DllStructGetPtr($openFN)) :this param is for call de GetOpenFileName function, but de return value is cero, but the significance is that the one error has ocured how the user close de box or any thing for style. But for other side de CommDlgExtendedError report that the funtion has calling sucefully. $result2=DllCall($dll,"dword", "CommDlgExtendedError","none","") ; this param is for check error en de call of function GetOpenFileName, but at firts glace I get of this function one notice. What the function GetOpenFileName Work Well MsgBox(0,"el valor de la variable $62 es", $result[0] & @CRLF _ & $result[1] ) MsgBox(0,"el valor es", $result2 ) DllClose($dll) I show the var content any times for check that the arguments are correct, but yet not work, the function GetOpenFilename always return cero value, but this we say that the function fail. I dont know if is for one error in the ESTRUCT param or is one error in the DLLCALL. Any can help me plis. Link to comment Share on other sites More sharing options...
GaryFrost Posted January 1, 2008 Author Share Posted January 1, 2008 (edited) Now works, had part of my structure incorrect and thanks to info posted at #419498 fixed my filter problem.expandcollapse popupGlobal Const $tagOFN = "dword StructSize;hwnd hwndOwner;hwnd hInstance;ptr lpstrFilter;ptr lpstrCustomFilter;dword nMaxCustFilter;" & _ "dword nFilterIndex;ptr lpstrFile;dword nMaxFile;ptr lpstrFileTitle;int nMaxFileTitle;ptr lpstrInitialDir;ptr lpstrTitle;" & _ "dword Flags;short nFileOffset;short nFileExtension;ptr lpstrDefExt;ptr lCustData;ptr lpfnHook;ptr lpTemplateName;ptr pvReserved;" & _ "dword dwReserved;dword FlagsEx" Global Const $OFN_ALLOWMULTISELECT = 0x200 Global Const $OFN_CREATEPROMPT = 0x2000 Global Const $OFN_DONTADDTORECENT = 0x2000000 Global Const $OFN_ENABLEHOOK = 0x20 Global Const $OFN_ENABLEINCLUDENOTIFY = 0x400000 Global Const $OFN_ENABLESIZING = 0x800000 Global Const $OFN_ENABLETEMPLATE = 0x40 Global Const $OFN_ENABLETEMPLATEHANDLE = 0x80 Global Const $OFN_EXPLORER = 0x80000 Global Const $OFN_EXTENSIONDIFFERENT = 0x400 Global Const $OFN_FILEMUSTEXIST = 0x1000 Global Const $OFN_FORCESHOWHIDDEN = 0x10000000 Global Const $OFN_HIDEREADONLY = 0x4 Global Const $OFN_LONGNAMES = 0x200000 Global Const $OFN_NOCHANGEDIR = 0x8 Global Const $OFN_NODEREFERENCELINKS = 0x100000 Global Const $OFN_NOLONGNAMES = 0x40000 Global Const $OFN_NONETWORKBUTTON = 0x20000 Global Const $OFN_NOREADONLYRETURN = 0x8000 Global Const $OFN_NOTESTFILECREATE = 0x10000 Global Const $OFN_NOVALIDATE = 0x100 Global Const $OFN_OVERWRITEPROMPT = 0x2 Global Const $OFN_PATHMUSTEXIST = 0x800 Global Const $OFN_READONLY = 0x1 Global Const $OFN_SHAREAWARE = 0x4000 Global Const $OFN_SHOWHELP = 0x10 Global Const $OFN_EX_NOPLACESBAR = 0x1 Global Const $CDERR_DIALOGFAILURE = 0xFFFF Global Const $CDERR_FINDRESFAILURE = 0x6 Global Const $CDERR_INITIALIZATION = 0x2 Global Const $CDERR_LOADRESFAILURE = 0x7 Global Const $CDERR_LOADSTRFAILURE = 0x5 Global Const $CDERR_LOCKRESFAILURE = 0x8 Global Const $CDERR_MEMALLOCFAILURE = 0x9 Global Const $CDERR_MEMLOCKFAILURE = 0xA Global Const $CDERR_NOHINSTANCE = 0x4 Global Const $CDERR_NOHOOK = 0xB Global Const $CDERR_NOTEMPLATE = 0x3 Global Const $CDERR_REGISTERMSGFAIL = 0xC Global Const $CDERR_STRUCTSIZE = 0x1 Global Const $FNERR_BUFFERTOOSMALL = 0x3003 Global Const $FNERR_INVALIDFILENAME = 0x3002 Global Const $FNERR_SUBCLASSFAILURE = 0x3001 $hGui = GUICreate("My GUI") GUISetState() $aFile = _WinAPI_GetOpenFileName("My Open File Dialog", "Text File (*.txt)|AutoIt File (*.au3)", ".", @ScriptName, "", 2, BitOR($OFN_ALLOWMULTISELECT, $OFN_EXPLORER), 0, $hGui) ; explore style ;~ $aFile = _WinAPI_GetOpenFileName("My Open File Dialog", "Text File (*.txt)|AutoIt File (*.au3)", ".", @ScriptName, "", 2, $OFN_ALLOWMULTISELECT, 0, $hGui) ; old style ;~ $aFile = _WinAPI_GetOpenFileName("My Open File Dialog", "Text File (*.txt)|AutoIt File (*.au3)", ".", @ScriptName, "", 2, 0, 0, $hGui) ; explore style single select ;~ $aFile = _WinAPI_GetOpenFileName("My Open File Dialog", "Text File (*.txt)|AutoIt File (*.au3)", ".", @ScriptName, "", 2, 0, $OFN_EX_NOPLACESBAR, $hGui) ; explore style single select If $aFile[0] = 0 Then $sError = _WinAPI_CommDlgExtendedError() ConsoleWrite("CommDlgExtendedError (" & @error & "): " & $sError & @lf) Else For $x = 1 To $aFile[0] ConsoleWrite($aFile[$x] & @LF) Next EndIf Func _WinAPI_GetOpenFileName($sTitle, $sFilter = "All files (*.*)", $sInitalDir = ".", $sDefaultFile = "", $sDefaultExt = "", $iFilterIndex = 1, $iFlags = 0, $iFlagsEx = 0, $hwndOwner = 0) Local $iPathLen = 4096 ; Max chars in returned string Local $iNulls = 0 Local $tOFN = DllStructCreate($tagOFN) Local $aFiles[1] Local $iFlag = $iFlags ; Filter string to array conversion Local $asFLines = StringSplit($sFilter, "|") Local $asFilter[$asFLines[0] * 2 + 1] Local $i, $iStart, $iFinal, $stFilter $asFilter[0] = $asFLines[0] * 2 For $i = 1 To $asFLines[0] $iStart = StringInStr($asFLines[$i], "(", 0, 1) $iFinal = StringInStr($asFLines[$i], ")", 0, -1) $asFilter[$i * 2 - 1] = StringStripWS(StringLeft($asFLines[$i], $iStart - 1), 3) $asFilter[$i * 2] = StringStripWS(StringTrimRight(StringTrimLeft($asFLines[$i], $iStart), StringLen($asFLines[$i]) - $iFinal + 1), 3) $stFilter &= "char[" & StringLen($asFilter[$i * 2 - 1]) + 1 & "];char[" & StringLen($asFilter[$i * 2]) + 1 & "];" Next Local $tTitle = DllStructCreate("char Title[" & StringLen($sTitle) + 1 & "]") Local $tInitialDir = DllStructCreate("char InitDir[" & StringLen($sInitalDir) + 1 & "]") Local $tFilter = DllStructCreate($stFilter & "char") Local $tPath = DllStructCreate("char Path[" & $iPathLen & "]") Local $tExtn = DllStructCreate("char Extension[" & StringLen($sDefaultExt) + 1 & "]") For $i = 1 To $asFilter[0] DllStructSetData($tFilter, $i, $asFilter[$i]) Next Local $iResult ; Set Data of API structures DllStructSetData($tTitle, "Title", $sTitle) DllStructSetData($tInitialDir, "InitDir", $sInitalDir) DllStructSetData($tPath, "Path", $sDefaultFile) DllStructSetData($tExtn, "Extension", $sDefaultExt) DllStructSetData($tOFN, "StructSize", DllStructGetSize($tOFN)) DllStructSetData($tOFN, "hwndOwner", $hwndOwner) DllStructSetData($tOFN, "lpstrFilter", DllStructGetPtr($tFilter)) DllStructSetData($tOFN, "nFilterIndex", $iFilterIndex) DllStructSetData($tOFN, "lpstrFile", DllStructGetPtr($tPath)) DllStructSetData($tOFN, "nMaxFile", $iPathLen) DllStructSetData($tOFN, "lpstrInitialDir", DllStructGetPtr($tInitialDir)) DllStructSetData($tOFN, "lpstrTitle", DllStructGetPtr($tTitle)) DllStructSetData($tOFN, "Flags", $iFlag) DllStructSetData($tOFN, "lpstrDefExt", DllStructGetPtr($tExtn)) DllStructSetData($tOFN, "FlagsEx", $iFlagsEx) $iResult = DllCall("comdlg32.dll", "int", "GetOpenFileName", "ptr", DllStructGetPtr($tOFN)) If @error Or $iResult[0] = 0 Then Return SetError(@error, @extended, $aFiles) If BitAND($iFlags, $OFN_ALLOWMULTISELECT) = $OFN_ALLOWMULTISELECT And BitAND($iFlags, $OFN_EXPLORER) = $OFN_EXPLORER Then For $x = 1 To $iPathLen If DllStructGetData($tPath, "Path", $x) = Chr(0) Then DllStructSetData($tPath, "Path", "|", $x) $iNulls += 1 Else $iNulls = 0 EndIf If $iNulls = 2 Then ExitLoop Next DllStructSetData($tPath, "Path", Chr(0), $x - 1) $aFiles = StringSplit(DllStructGetData($tPath, "Path"), "|") If $aFiles[0] = 1 Then Return _WinAPI_ParseFileDialogPath(DllStructGetData($tPath, "Path")) Return StringSplit(DllStructGetData($tPath, "Path"), "|") ElseIf BitAND($iFlags, $OFN_ALLOWMULTISELECT) = $OFN_ALLOWMULTISELECT Then $aFiles = StringSplit(DllStructGetData($tPath, "Path"), " ") If $aFiles[0] = 1 Then Return _WinAPI_ParseFileDialogPath(DllStructGetData($tPath, "Path")) Return StringSplit(StringReplace(DllStructGetData($tPath, "Path"), " ", "|"), "|") Else Return _WinAPI_ParseFileDialogPath(DllStructGetData($tPath, "Path")) EndIf EndFunc ;==>_WinAPI_GetOpenFileName Func _WinAPI_ParseFileDialogPath($sPath) Local $aFiles[3], $stemp $aFiles[0] = 2 $stemp = StringMid($sPath, 1, StringInStr($sPath, "\", 0, -1) - 1) $aFiles[1] = $stemp $aFiles[2] = StringMid($sPath, StringInStr($sPath, "\", 0, -1) + 1) Return $aFiles EndFunc ;==>_WinAPI_ParseFileDialogPath Func _WinAPI_CommDlgExtendedError() Local $iResult = DllCall("comdlg32.dll", "dword", "CommDlgExtendedError") If @error Then Return SetError(@error, @extended, "") SetError($iResult[0]) Switch @error Case $CDERR_DIALOGFAILURE Return SetError(@error, 0, "The dialog box could not be created." & @LF & _ "The common dialog box function's call to the DialogBox function failed." & @LF & _ "For example, this error occurs if the common dialog box call specifies an invalid window handle.") Case $CDERR_FINDRESFAILURE Return SetError(@error, 0, "The common dialog box function failed to find a specified resource.") Case $CDERR_INITIALIZATION Return SetError(@error, 0, "The common dialog box function failed during initialization." & @LF & "This error often occurs when sufficient memory is not available.") Case $CDERR_LOADRESFAILURE Return SetError(@error, 0, "The common dialog box function failed to load a specified resource.") Case $CDERR_LOADSTRFAILURE Return SetError(@error, 0, "The common dialog box function failed to load a specified string.") Case $CDERR_LOCKRESFAILURE Return SetError(@error, 0, "The common dialog box function failed to lock a specified resource.") Case $CDERR_MEMALLOCFAILURE Return SetError(@error, 0, "The common dialog box function was unable to allocate memory for internal structures.") Case $CDERR_MEMLOCKFAILURE Return SetError(@error, 0, "The common dialog box function was unable to lock the memory associated with a handle.") Case $CDERR_NOHINSTANCE Return SetError(@error, 0, "The ENABLETEMPLATE flag was set in the Flags member of the initialization structure for the corresponding common dialog box," & @LF & _ "but you failed to provide a corresponding instance handle.") Case $CDERR_NOHOOK Return SetError(@error, 0, "The ENABLEHOOK flag was set in the Flags member of the initialization structure for the corresponding common dialog box," & @LF & _ "but you failed to provide a pointer to a corresponding hook procedure.") Case $CDERR_NOTEMPLATE Return SetError(@error, 0, "The ENABLETEMPLATE flag was set in the Flags member of the initialization structure for the corresponding common dialog box," & @LF & _ "but you failed to provide a corresponding template.") Case $CDERR_REGISTERMSGFAIL Return SetError(@error, 0, "The RegisterWindowMessage function returned an error code when it was called by the common dialog box function.") Case $CDERR_STRUCTSIZE Return SetError(@error, 0, "The lStructSize member of the initialization structure for the corresponding common dialog box is invalid") Case $FNERR_BUFFERTOOSMALL Return SetError(@error, 0, "The buffer pointed to by the lpstrFile member of the OPENFILENAME structure is too small for the file name specified by the user." & @LF & _ "The first two bytes of the lpstrFile buffer contain an integer value specifying the size, in TCHARs, required to receive the full name.") Case $FNERR_INVALIDFILENAME Return SetError(@error, 0, "A file name is invalid.") Case $FNERR_SUBCLASSFAILURE Return SetError(@error, 0, "An attempt to subclass a list box failed because sufficient memory was not available.") EndSwitch EndFunc ;==>_WinAPI_CommDlgExtendedError Edited January 2, 2008 by GaryFrost SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
buzonjl Posted January 7, 2008 Share Posted January 7, 2008 Tanks Men. now I can open the dialog box GetOpenFileName. I hope you have a good day. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now