2016-10-11 41 views
1

我不知道是否有可能因爲我找不到任何地方。 我用一些按鈕創建了一個GUI來啓動事物。自動 - 限制執行次數

我只是想知道,如果它是可能的:

  1. 限制GUI
  2. 限制的開口被處決的人數與按鈕
  3. 限制時間範圍內的號碼,以便後某一點,你無法使用它

全球$解釋= 「幫助~~」

#include <IE.au3> 
#include <ButtonConstants.au3> 
#include <EditConstants.au3> 
#include <GUIConstantsEx.au3> 
#include <StaticConstants.au3> 
#include <WindowsConstants.au3> 

Global $explain = "hmmm" 
Global $Form1 = GUICreate("Yay", 328, 157) 
Global $Label1 = GUICtrlCreateLabel("ID", 12, 14, 67, 20) 
Global $Label2 = GUICtrlCreateLabel("Password", 12, 44, 67, 20) 
Global $Label3 = GUICtrlCreateLabel("hello world", 225, 14, 90, 20) 
Global $Input1 = GUICtrlCreateInput("", 76, 10, 105, 24) 
Global $Input2 = GUICtrlCreateInput("", 76, 40, 105, 24, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL)) 
Global $Input3 = GUICtrlCreateInput("", 228, 40, 70, 24) 
Global $Button1 = GUICtrlCreateButton("Log In", 76, 69, 105, 30) 
Global $Button2 = GUICtrlCreateButton("Connect", 212, 69, 100, 30) 
Global $Checkbox1 = GUICtrlCreateCheckbox("hmm", 240, 113, 97, 17) 
Global $Checkbox2 = GUICtrlCreateCheckbox("hmm2", 240, 134, 97, 17) 

Global $Group1 = GUICtrlCreateGroup("", 5, -5, 190, 110) 
Global $Edit1 = GUICtrlCreateEdit("", 5, 110, 228, 100) 
GUICtrlSetData(-1, $explain) 

GUISetState(@SW_SHOW) 

While 1 
$nMsg = GUIGetMsg() 
Switch $nMsg 
    Case $GUI_EVENT_CLOSE 
     Exit 
    Case $Checkbox1 
     If (GUICtrlRead($Checkbox1) = $GUI_CHECKED) Then 
      Global $hmm = 1 
     EndIf 
    Case $Checkbox2 
     If (GUICtrlRead($Checkbox2) = $GUI_CHECKED) Then 
      Global $hmm2 = 0 
     EndIf 
    Case $Button1 
     Global $id = GUICtrlRead($Input1) 
     Global $pass = GUICtrlRead($Input2) 
     WinSetState("Yay", "", @SW_MINIMIZE) 
     MsgBox(0,"","possible to limit #of Execution?") 
    Case $Button2 
     Global $exnum = GUICtrlRead($Input3) 
     WinSetState("Yay", "", @SW_MINIMIZE) 
     MsgBox(0,"","time limit would be nice too! thnx!") 
EndSwitch 
WEnd 

有沒有人試過嗎? 它需要強烈的編碼嗎? 你能提供一個樣本,如果它是不是太糟糕

+1

你能否詳細說明一下這個腳本應該怎麼辦? 「GUI的開放」是什麼意思?該腳本的啓動次數或腳本的多次實例可以同時啓動? – mrt

回答

0

下午好皮塔,

是啊!這一切都是可以做到的!有多種方式可以這樣做,我會嘗試僅舉幾個例子。

管理這些請求的好方法是創建屬性文件來管理所有內容。看看下面的例子!

Global $explain = "help~~" 

#include <IE.au3> 
#include <ButtonConstants.au3> 
#include <EditConstants.au3> 
#include <GUIConstantsEx.au3> 
#include <StaticConstants.au3> 
#include <WindowsConstants.au3> 

; ================================================================================================================================================= 
#include <File.au3> 
#Include <Date.au3> 

; This is the directory that the temporary file will be stored. 
$fileHandle = @AppDataDir & "\TestProgram\properties.txt" 

; Checks to see if the properties file exists 
if FileExists($fileHandle) Then 
    ; START Check Run Limit 
    ; Reads the first value in the properties file. In this example, it's the limit to how many times the program can be launched. 
    $runLimit = FileReadLine($fileHandle, 1) 
    ; MsgBox(0,"Run Limit", $runLimit) 
    ; If the run limit reaches zero (or less than by some glitch), do not launch the program. 
    if $runLimit <= 0 Then 
     MsgBox(16,"Run Limit Reached", "You have reached the maximum number of launches for this program!") 
     Exit 
    EndIf 
    ; Subtract one from the launch limit. 
    $newLimit = $runLimit - 1 
    MsgBox(0,"New Run Limit", "You may launch this program " & $newLimit & " more times!", 3) 
    ; Update the properties file. 
    _FileWriteToLine($fileHandle, 1, $newLimit, True) 
    ; END Check Run Limit 

    ; Start CHECK Expiration Date 
    $expDate = FileReadLine($fileHandle, 2) 
    ; MsgBox(0,"Expiration Date", "This program expires on " & $expDate) 
    ; Check to see if the expiration date has already passed 
    if $expDate < _NowDate() Then 
     MsgBox(16,"Program Expired","Your trial period has expired!") 
     Exit 
    EndIf 

    ; END Check expiration date 
Else 
    ; If the file does not exists, create it and set it up 
    $propFile = FileOpen($fileHandle, 10) 
    ; Sets the launch limit to 10. Change this value to set the launch limit 
    FileWrite($fileHandle, "10" & @CRLF) 
    ; Sets the expiration date to a week (7 days) from the initial launch date. 
    FileWrite($fileHandle, @MON & "/" & (@MDAY + 7) & "/" & @YEAR & @CRLF) 
    ; Sets the button limit for the login button to 3. 
    FileWrite($fileHandle, "3" & @CRLF) 
    FileClose($fileHandle) 

    #CS 
     NOTE: THIS IS JUST FOR DEMONSTRATION PURPOSES! THE USER CAN SIMPLY DELETE THE PROPERTIES FILE 
      IN ORDER TO RESET THE VALUES AND CONTINUE USING THE PROGRAM. THIS WAS DESIGNED SIMPLY TO 
      GET YOU ON THE RIGHT TRACK. 
    #CE 
EndIf 



; ================================================================================================================================================= 

Global $explain = "hmmm" 
Global $Form1 = GUICreate("Yay", 328, 157) 
Global $Label1 = GUICtrlCreateLabel("ID", 12, 14, 67, 20) 
Global $Label2 = GUICtrlCreateLabel("Password", 12, 44, 67, 20) 
Global $Label3 = GUICtrlCreateLabel("hello world", 225, 14, 90, 20) 
Global $Input1 = GUICtrlCreateInput("", 76, 10, 105, 24) 
Global $Input2 = GUICtrlCreateInput("", 76, 40, 105, 24, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL)) 
Global $Input3 = GUICtrlCreateInput("", 228, 40, 70, 24) 
Global $Button1 = GUICtrlCreateButton("Log In", 76, 69, 105, 30) 
Global $Button2 = GUICtrlCreateButton("Connect", 212, 69, 100, 30) 
Global $Checkbox1 = GUICtrlCreateCheckbox("hmm", 240, 113, 97, 17) 
Global $Checkbox2 = GUICtrlCreateCheckbox("hmm2", 240, 134, 97, 17) 

Global $Group1 = GUICtrlCreateGroup("", 5, -5, 190, 110) 
Global $Edit1 = GUICtrlCreateEdit("", 5, 110, 228, 100) 
GUICtrlSetData(-1, $explain) 

GUISetState(@SW_SHOW) 

While 1 
$nMsg = GUIGetMsg() 
Switch $nMsg 
    Case $GUI_EVENT_CLOSE 
     Exit 
    Case $Checkbox1 
     If (GUICtrlRead($Checkbox1) = $GUI_CHECKED) Then 
      Global $hmm = 1 
     EndIf 
    Case $Checkbox2 
     If (GUICtrlRead($Checkbox2) = $GUI_CHECKED) Then 
      Global $hmm2 = 0 
     EndIf 
    Case $Button1 
     ; START Button Limit ================================================================================================================ 
     if FileExists($fileHandle) Then 
      $buttonLimit = FileReadLine($fileHandle, 3) 
      if $buttonLimit <= 0 Then 
       MsgBox(16,"Button Limit Reached", "You have reached the maximum number of times you can hit this button!") 
      ELSE 
       $newButtonLimit = $buttonLimit - 1 
       MsgBox(0,"New Run Limit", "You may press this button " & $newButtonLimit & " more times!", 3) 
       _FileWriteToLine($fileHandle, 3, $newButtonLimit, True) 

       ; START OLD CODE 
       Global $id = GUICtrlRead($Input1) 
       Global $pass = GUICtrlRead($Input2) 
       ; WinSetState("Yay", "", @SW_MINIMIZE) 
       MsgBox(0,"","possible to limit #of Execution?") 
       ; END OLD CODE ================================================================================================================ 

      EndIf 
     EndIf 
     ; END Button Limit 
    Case $Button2 
     Global $exnum = GUICtrlRead($Input3) 
     WinSetState("Yay", "", @SW_MINIMIZE) 
     MsgBox(0,"","time limit would be nice too! thnx!") 
EndSwitch 
WEnd 

啓動該程序後,會生成一個屬性文件並存儲在用戶計算機上的應用數據中。

在窗口上:按Win + R鍵入%appdata%。如果您將示例保持不變,則會出現一個名爲「TestProgram」的文件夾,如果您更改了名稱,它將是您調用它的任何內容。在這個文件夾裏面,會有一些properties.txt文件(除非你改變了名字)。

我在示例代碼做了一些意見,以幫助解釋我做什麼,但我不解釋的事情,所以請讓我知道如果你需要一些更多的幫助太棒了。

P.S.如果你確實使用這種方法,我強烈建議使用屬性文件進行加密(使用Crypt也許?),使其不太可編輯,並設計一些方法來判斷用戶是否刪除了該文件。

我希望這有助於!