找回密码
 加入
搜索
查看: 4189|回复: 8

[GUI管理] api 的GetOpenFileName

  [复制链接]
发表于 2012-10-12 00:36:58 | 显示全部楼层 |阅读模式
api 的GetOpenFileName函数如何调用请高手指导。
 楼主| 发表于 2012-10-12 00:40:18 | 显示全部楼层
这样写对吗,,
#include <GUIConstants.au3>
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#Region ### START Koda GUI section ### Form=c:\documents and settings\administrator\我的文档\form1.kxf
$Form1_1 = GUICreate("Form1", 623, 449, 192, 114)
$Label1 = GUICtrlCreateLabel("系统路径:", 32, 233, 101, 17)
$Input1 = GUICtrlCreateInput("", 152, 232, 337, 21)
$secn = GUICtrlCreateButton("选择", 520, 232, 65, 25)




GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

                Case $secn
                        $Result1 = DllCall("comdlg32.dll","BOOL","GetOpenFileName","Text Files (*.txt), *.txt")
                Case $Input1
        EndSwitch
WEnd
发表于 2012-10-12 08:50:38 | 显示全部楼层
手机党…



对不对你运行一下不就知道了??
发表于 2012-10-12 10:24:40 | 显示全部楼层
本帖最后由 xiehuahere 于 2012-10-12 10:41 编辑

显然没这么简单。
参数为指向 OPENFILENAME 结构体的指针。关键是填充这个结构体就很麻烦。

typedef struct tagOFN {
  DWORD         lStructSize;
  HWND          hwndOwner;
  HINSTANCE     hInstance;
  LPCTSTR       lpstrFilter;
  LPTSTR        lpstrCustomFilter;
  DWORD         nMaxCustFilter;
  DWORD         nFilterIndex;
  LPTSTR        lpstrFile;
  DWORD         nMaxFile;
  LPTSTR        lpstrFileTitle;
  DWORD         nMaxFileTitle;
  LPCTSTR       lpstrInitialDir;
  LPCTSTR       lpstrTitle;
  DWORD         Flags;
  WORD          nFileOffset;
  WORD          nFileExtension;
  LPCTSTR       lpstrDefExt;
  LPARAM        lCustData;
  LPOFNHOOKPROC lpfnHook;
  LPCTSTR       lpTemplateName;
#if (_WIN32_WINNT >= 0x0500)
  void          *pvReserved;
  DWORD         dwReserved;
  DWORD         FlagsEx;
#endif
} OPENFILENAME, *LPOPENFILENAME;

参考:http://hi.baidu.com/onukeyewybejprf/item/9ed3568d5dac95c698255f0d
发表于 2012-10-12 10:30:17 | 显示全部楼层
不懂是什么前来学习。
 楼主| 发表于 2012-10-12 10:37:48 | 显示全部楼层
请xiehuahere 给个代码,先谢谢了。
发表于 2012-10-12 10:42:46 | 显示全部楼层
回复 6# dbdbdd

我也不是太理解结构体中各个参数的意义。
上面的帖子给出参考链接了,你网上搜搜相关帖子吧。
 楼主| 发表于 2012-10-12 14:27:17 | 显示全部楼层
找到了一个方法。如下。OK了。

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Opt('MustDeclareVars', 1)

Global $iMemo

_Example_Defaults()
_Example_ExplorerStyleMultiSelect()
_Example_OldStyle()
_Example_ExplorerStyleSinglSelect()
_Example_ExplorerStyle_NoPlaceBar()

Func _Example_Defaults()
    Local $hGui, $btn_dialog, $aFile, $sError

    ; Erstellt eine GUI
    $hGui = GUICreate("GetOpenFileName (mit Standardeinstellungen)", 450, 296)
    $iMemo = GUICtrlCreateEdit("", 2, 32, 446, 226, $WS_HSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    $btn_dialog = GUICtrlCreateButton("&Ouml;ffnen-Dialog", 180, 270, 90, 20)
    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $btn_dialog
                $aFile = _WinAPI_GetOpenFileName() ; Verwendet Standards
                If $aFile[0] = 0 Then
                    $sError = _WinAPI_CommDlgExtendedError()
                    MemoWrite("CommDlgExtendedError (" & @error & "): " & $sError)
                Else
                    For $x = 1 To $aFile[0]
                        MemoWrite($aFile[$x])
                    Next
                EndIf
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete($hGui)
EndFunc   ;==>_Example_Defaults
; Gibt eine Zeile im Memo-Fenster aus
Func MemoWrite($sMessage)
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-17 15:58 , Processed in 0.082628 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表