Giáo Trình How To Use AutoIt A Professional Manner part 41 potx

6 238 0
Giáo Trình How To Use AutoIt A Professional Manner part 41 potx

Đang tải... (xem toàn văn)

Thông tin tài liệu

; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd GUIDelete() EndFunc ;==>Example1 ; ***************** ; * Second sample * ; ***************** 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 Function Reference GUICtrlCreateDate tạo ra date control cho GUI để nhập ngày tháng và thời gian. GUICtrlCreateDate ( "text", left, top [, width [, height [, style [, exStyle]]]] ) Parameters text ngày tháng hiện thị left tọa độ X top tọa độ Y width chiều rộng height chiều cao style kiểu. xem thêm GUI Control Styles Appendix. default (-1) : $DTS_LONGDATEFORMAT forced style : $WS_TABSTOP exStyle kiểu mở rộng. xem Extended Style Table. Return Value Success: trả lại ControlID Failure: Returns 0. Remarks để lấy giá trị của control ta dùng GUICtrlRead. để đặt các thuộc tính cho control ta dùng GUICtrlSet để sử dụng nhiều kiểu trong style ta dùng BitOr($GUI_SS_DEFAULT_DATE, newstyle, ). ngày tháng hiển thị trên control có thể định dạng lại bởi hàm GuiCtrlSendMsg với tham số là $DTM_SETFORMAT. để có thể dùng đc các biến trên ta cần phải khai báo thư viện #include <DateTimeConstants.au3> in your script. Default resizing is $GUI_DOCKHEIGHT. Related GUICoordMode (Option), GUICtrlSetState, GUIGetMsg, GUICtrlRead Example #include <GUIConstantsEx.au3> #include <DateTimeConstants.au3> Opt('MustDeclareVars', 1) Example1() Example2() Example3() ; example1 Func Example1() Local $date, $msg GUICreate("My GUI get date", 200, 200, 800, 200) $date = GUICtrlCreateDate("1953/04/25", 10, 10, 185, 20) GUISetState() ; Run the GUI until the dialog is closed Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE MsgBox(0, "Date", GUICtrlRead($date)) GUIDelete() EndFunc ;==>Example1 ; example2 Func Example2() Local $n, $msg GUICreate("My GUI get time") $n = GUICtrlCreateDate("", 20, 20, 100, 20, $DTS_TIMEFORMAT) GUISetState() ; Run the GUI until the dialog is closed Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE . GUICtrlSetState, GUIGetMsg, GUICtrlRead Example #include <GUIConstantsEx.au3> #include <DateTimeConstants.au3> Opt('MustDeclareVars', 1) Example1() Example2() Example3(). 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. ;==>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)

Ngày đăng: 08/07/2014, 20:20

Tài liệu cùng người dùng

Tài liệu liên quan