找回密码
 加入
搜索
查看: 1650|回复: 5

打开对话框的问题,高手帮忙[已解决]

[复制链接]
发表于 2009-7-15 08:46:36 | 显示全部楼层 |阅读模式
本帖最后由 superflq 于 2009-7-16 14:31 编辑

我需要打开一个对话框,要集FileOpenDialog和FileSelectFolder 的功能
就是说打开的对话框我选文件夹就返回文件夹的路径,选任意文件就返回文件的路径,
 楼主| 发表于 2009-7-15 08:48:42 | 显示全部楼层
在线等呢,碰到问题卡住了~
发表于 2009-7-15 09:33:04 | 显示全部楼层
本帖最后由 ueiayz 于 2009-7-15 09:35 编辑
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 633, 454, 192, 114)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$Input1 = GUICtrlCreateInput("Input1", 80, 80, 281, 21)
$button = GUICtrlCreateButton("打开", 250, 120, 60)
GUICtrlSetOnEvent($button, "OKButton")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        Sleep(100)
WEnd

Func CLOSEClicked()
        Exit
EndFunc

Func OKButton()
  $message = "按下 Ctrl 或 Shift 键选择多个文件."
  $var = FileOpenDialog($message, @WindowsDir & "", "图像文件 (*.jpg;*.bmp)", 1 + 4 )
  If @error Then 
          MsgBox(4096,"","没有选择文件!")
  Else
          GUICtrlSetData ( $Input1, $var  )
          MsgBox(4096,"","你选择了:" & $var)
  EndIf
EndFunc
发表于 2009-7-15 11:56:47 | 显示全部楼层
选文件夹就返回文件夹的路径,选任意文件就返回文件的路径

没有这样的函数
明知不可为而为之
可以折中一点用msgbox来让用户选择是选择文件夹或文件
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 633, 454, 192, 114)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$Input1 = GUICtrlCreateInput("", 80, 80, 281, 21)
$button = GUICtrlCreateButton("打开", 250, 120, 60)
GUICtrlSetOnEvent($button, "OKButton")
GUISetState(@SW_SHOW)

While 1
        Sleep(100)
WEnd

Func CLOSEClicked()
        Exit
EndFunc

Func OKButton()
  If MsgBox(4,"选择",'是:选择文件    否:选择文件夹') =7 Then
$var =FileSelectFolder("选择一个文件夹.", "")
Else
  $var = FileOpenDialog("按下 Ctrl 或 Shift 键选择多个文件.", @WindowsDir & "", "图像文件 (*.jpg;*.bmp)", 1 + 4 )
  EndIf
GUICtrlSetData ( $Input1, $var  )
MsgBox(4096,"","你选择了:" & $var)
EndFunc
如果真能有如楼主描述的函数或者实现方法
我反而真想学习一下
 楼主| 发表于 2009-7-16 14:30:54 | 显示全部楼层
没有这样的函数
明知不可为而为之
可以折中一点用msgbox来让用户选择是选择文件夹或文件#include
#include
#include
Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 633, 454, 192, 114)
GUISet ...
lynfr8 发表于 2009-7-15 11:56


最后我用了这个方法解决问题了
Func Example2()

Local
$hGui,
$OptionsBtn,
$OptionsDummy,
$OptionsContext,
$OptionsCommon,
$OptionsFile,
$msg

Local
$OptionsExit,
$HelpBtn,
$HelpDummy,
$HelpContext,
$HelpWWW,
$HelpAbout

$hGui
=
GUICreate("My GUI",
170,
40)


$OptionsBtn
=
GUICtrlCreateButton("&Options",
10,
10,
70,
20,
$BS_FLAT)


; At first create a dummy control for the options and a contextmenu for it

$OptionsDummy
=
GUICtrlCreateDummy()

$OptionsContext
=
GUICtrlCreateContextMenu($OptionsDummy)

$OptionsCommon
=
GUICtrlCreateMenuItem("Common",
$OptionsContext)

$OptionsFile
=
GUICtrlCreateMenuItem("File",
$OptionsContext)

GUICtrlCreateMenuItem("",
$OptionsContext)

$OptionsExit
=
GUICtrlCreateMenuItem("Exit",
$OptionsContext)



$HelpBtn
=
GUICtrlCreateButton("&Help",
90,
10,
70,
20,
$BS_FLAT)


; Create a dummy control and a contextmenu for the help too

$HelpDummy
=
GUICtrlCreateDummy()

$HelpContext
=
GUICtrlCreateContextMenu($HelpDummy)

$HelpWWW
=
GUICtrlCreateMenuItem("Website",
$HelpContext)

GUICtrlCreateMenuItem("",
$HelpContext)

$HelpAbout
=
GUICtrlCreateMenuItem("About...",
$HelpContext)



GUISetState()


While
1

$msg
=
GUIGetMsg()



Switch
$msg

Case
$OptionsExit,
$GUI_EVENT_CLOSE

ExitLoop



Case
$OptionsBtn
                ShowMenu($hGui,
$msg,
$OptionsContext)



Case
$HelpBtn
                ShowMenu($hGui,
$msg,
$HelpContext)



Case
$HelpAbout

MsgBox(64,
"About...",
"GUICtrlGetHandle-Sample")

EndSwitch

WEnd

GUIDelete()
EndFunc
;==>Example2


; Show a menu in a given GUI window which belongs to a given GUI ctrl
Func ShowMenu($hWnd,
$CtrlID,
$nContextID)

Local
$arPos,
$x,
$y

Local
$hMenu
=
GUICtrlGetHandle($nContextID)



$arPos
=
ControlGetPos($hWnd,
"",
$CtrlID)



$x
=
$arPos[0]

$y
=
$arPos[1]
+
$arPos[3]


    ClientToScreen($hWnd,
$x,
$y)
    TrackPopupMenu($hWnd,
$hMenu,
$x,
$y)
EndFunc
;==>ShowMenu


; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd,
ByRef
$x,
ByRef
$y)

Local
$stPoint
=
DllStructCreate("int;int")



DllStructSetData($stPoint,
1,
$x)

DllStructSetData($stPoint,
2,
$y)


DllCall("user32.dll",
"int",
"ClientToScreen",
"hwnd",
$hWnd,
"ptr",
DllStructGetPtr($stPoint))



$x
=
DllStructGetData($stPoint,
1)

$y
=
DllStructGetData($stPoint,
2)

; release Struct not really needed as it is a local

$stPoint
=
0
EndFunc
;==>ClientToScreen


; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
Func TrackPopupMenu($hWnd,
$hMenu,
$x,
$y)

DllCall("user32.dll",
"int",
"TrackPopupMenuEx",
"hwnd",
$hMenu,
"int",
0,
"int",
$x,
"int",
$y,
"hwnd",
$hWnd,
"ptr",
0)
EndFunc
;==>TrackPopupMenu
发表于 2009-7-16 17:53:35 | 显示全部楼层
本帖最后由 lynfr8 于 2009-7-16 18:15 编辑

楼上编辑一下你的帖子
代码乱了
 
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
Func Example2()
Local $hGui,$OptionsBtn,$OptionsDummy,$OptionsContext,$OptionsCommon,$OptionsFile,$msg
Local $OptionsExit,$HelpBtn,$HelpDummy,$HelpContext,$HelpWWW,$HelpAbout
$hGui=GUICreate("My GUI",170,40)
$OptionsBtn=GUICtrlCreateButton("&Options",10,10,70,20,$BS_FLAT)
; At first create a dummy control for the options and a contextmenu for it
$OptionsDummy=GUICtrlCreateDummy()
$OptionsContext=GUICtrlCreateContextMenu($OptionsDummy)
$OptionsCommon=GUICtrlCreateMenuItem("Common",$OptionsContext)
$OptionsFile=GUICtrlCreateMenuItem("File",$OptionsContext)
GUICtrlCreateMenuItem("",$OptionsContext)
$OptionsExit=GUICtrlCreateMenuItem("Exit",$OptionsContext)
$HelpBtn=GUICtrlCreateButton("&Help",90,10,70,20,$BS_FLAT)
; Create a dummy control and a contextmenu for the help too
$HelpDummy=GUICtrlCreateDummy()
$HelpContext=GUICtrlCreateContextMenu($HelpDummy)
$HelpWWW=GUICtrlCreateMenuItem("Website",$HelpContext)
GUICtrlCreateMenuItem("",$HelpContext)
$HelpAbout=GUICtrlCreateMenuItem("About...",$HelpContext)
GUISetState()
While 1
$msg=GUIGetMsg()
Switch $msg
 Case $OptionsExit;,$GUI_EVENT_CLOSE
ExitLoop
Case  $OptionsBtn
                ShowMenu($hGui,$msg,$OptionsContext)
Case  $HelpBtn
                ShowMenu($hGui,$msg,$HelpContext)
Case $HelpAbout
MsgBox(64,"About...","GUICtrlGetHandle-Sample")
EndSwitch
WEnd
GUIDelete()
EndFunc
;==>Example2
; Show a menu in a given GUI window which belongs to a given GUI ctrl
Func ShowMenu($hWnd,$CtrlID,$nContextID)
Local $arPos,$x,$y
Local $hMenu=GUICtrlGetHandle($nContextID)
$arPos=ControlGetPos($hWnd,"",$CtrlID)
$x=$arPos[0]
$y=$arPos[1]+$arPos[3]
    ClientToScreen($hWnd,$x,$y)
    TrackPopupMenu($hWnd,$hMenu,$x,$y)
EndFunc
;==>ShowMenu
; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd,ByRef $x,ByRef $y)
Local $stPoint=DllStructCreate("int;int")
DllStructSetData($stPoint,1,$x)
DllStructSetData($stPoint,2,$y)
DllCall("user32.dll","int","ClientToScreen","hwnd",$hWnd,"ptr",DllStructGetPtr($stPoint))
$x=DllStructGetData($stPoint,1)
$y=DllStructGetData($stPoint,2)
; release Struct not really needed as it is a local
$stPoint=0
EndFunc
;==>ClientToScreen
; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
Func TrackPopupMenu($hWnd,$hMenu,$x,$y)
DllCall("user32.dll","int","TrackPopupMenuEx","hwnd",$hMenu,"int",0,"int",$x,"int",$y,"hwnd",$hWnd,"ptr",0)
EndFunc
;==>TrackPopupMenu

评分

参与人数 1金钱 +10 贡献 +5 收起 理由
kn007 + 10 + 5 难过我copy后无效。。。学习了

查看全部评分

您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-3 00:54 , Processed in 0.072761 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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