Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/21/2017 in all areas

  1. A possible explanation for this curious association (never knew Tom was originally called Jasper).
    1 point
  2. I posted this the other day, but thought I would post in a separate topic instead. #include <MsgBoxConstants.au3> ; ---- Start of Person Class ; Stored in the 'object' to verify it's our 'object' and not some random array Global Const $PERSON_GUID = '4197B285-6AB1-489B-8585-08C852E33F3D' ; Friendly names for 0, 1, 2 and 3 Global Enum $PERSON_AGE, $PERSON_NAME, $PERSON_ID, $PERSON_MAX ; Constructor Func Person($sName, $iAge) Local $hPerson[$PERSON_MAX] ; Set the GUID, so as the verification will work $hPerson[$PERSON_ID] = $PERSON_GUID Person_SetAge($hPerson, $iAge) Person_SetName($hPerson, $sName) ; Return the Person 'object' Return $hPerson EndFunc ;==>Person ; Getter for the age property Func Person_GetAge(ByRef $hPerson) Return _Person_IsObject($hPerson) ? $hPerson[$PERSON_AGE] : Null EndFunc ;==>Person_GetAge ; Setter for the age property Func Person_SetAge(ByRef $hPerson, $iAge) ; If not a valid 'object' or integer then return If Not _Person_IsObject($hPerson) Or Not IsInt($iAge) Then Return ; Set the age $hPerson[$PERSON_AGE] = $iAge EndFunc ;==>Person_SetAge ; Getter for the name property Func Person_GetName(ByRef $hPerson) Return _Person_IsObject($hPerson) ? $hPerson[$PERSON_NAME] : Null EndFunc ;==>Person_GetName ; Setter for the name property Func Person_SetName(ByRef $hPerson, $sName) ; If not a valid 'object' then return If Not _Person_IsObject($hPerson) Then Return ; Set the name $hPerson[$PERSON_NAME] = $sName EndFunc ;==>Person_SetName ; ToString() for the 'object' Func Person_ToString(ByRef $hPerson) Return _Person_IsObject($hPerson) ? StringFormat('Name: %s, Age: %i', $hPerson[$PERSON_NAME], $hPerson[$PERSON_AGE]) : Null EndFunc ;==>Person_ToString ; Check if it's a valid 'object' and not some random array. "NTERNAL ONLY! Func _Person_IsObject(ByRef $hPerson) Return UBound($hPerson) = $PERSON_MAX And $hPerson[$PERSON_ID] == $PERSON_GUID EndFunc ;==>_Person_IsObject ; ---- End of Person Class Example() Func Example() ; Store the Person 'object', which is just a glorified array Local $hP1 = Person('John', 30) ; Display the 'object' MsgBox($MB_SYSTEMMODAL, 'Person 1', Person_ToString($hP1)) ; Create a new person ; Store the Person 'object', which is just a glorified array Local $hP2 = Person('James', 36) ; Display the 'object' MsgBox($MB_SYSTEMMODAL, 'Person 2', Person_ToString($hP2)) ; Set the age for Person 2 Person_SetAge($hP2, 45) ; Display the 'object' MsgBox($MB_SYSTEMMODAL, 'Person 2 - Revised', Person_ToString($hP2)) EndFunc ;==>Example
    1 point
  3. Makes sense ... really? Try this for starters: HotKeySet("{ENTER}", "_enter") HotKeySet("{ESC}", "_exit") ; HotKeySet("{F11}", "_TogglePause") Global $Paused = False While 1 Sleep(100) ; WEnd Func _enter() HotKeySet("{ENTER}") If Not $Paused Then Send("3") ;Send 3 EndIf Send("{ENTER}") HotKeySet("{ENTER}", "_enter") EndFunc ;==>_enter Func _exit() Exit EndFunc ;==>_exit Func _TogglePause() $Paused = Not $Paused Return EndFunc ;==>_TogglePaus Jos
    1 point
  4. jchd

    AutoIt Snippets

    @Deye, This is very slow. Repeatedly invoking _ArrayAdd and _ArraySearch is horrible CPU waste. You can use a Map to speed the process tremendously. The Map datatype is available in the beta but by the time it has been available the beta hasn't been found problematic at all. Note that I process 100,000 values in the following example: #include <Array.au3> Local $Source[100000] For $i = 0 To UBound($Source) - 1 $Source[$i] = Random(0, 99, 1) Next Local $Histogram[] ; use a Map datatype For $i In $Source If MapExists($Histogram, $i) Then $Histogram[$i] += 1 Else $Histogram[$i] = 1 EndIf Next Local $Keys = MapKeys($Histogram) _ArraySort($Keys) For $i In $Keys ConsoleWrite($i & ' has ' & $Histogram[$i] & " occurences" & @LF) Next ; another possibility since we can expect that all values in the range are present at least once ; this requires that the values are integers in [0. N] Local $Counts[UBound($Keys)] For $i = 0 To UBound($Keys) - 1 $Counts[$i] = $Histogram[$i] Next _ArrayDisplay(_Array1DToHistogram($Counts)) As a bonus I also show how one can use _Array1DToHistogram in some cases. Displaying values sorted by increasing/decreasing occurence is left as an exercise to the reader.
    1 point
  5. TCPNameToIP resolves the host name with a DNS query. A DNS resolution does not require an internet connection : so, no, TCPNameToIP cannot be used to check the Internet connection. Look at InternetGetConnectedState here : https://www.autoitscript.com/wiki/Connected, it's a sure way
    1 point
  6. by using TCPNameToIP() you are actually trying to check host status by querying the DNS service. this is obviously wrong. a DNS service maintains a DNS record even when the host is not alive for a while. and it does not bother to check the host in order to reply to a DNS query. to check if a host is online, you must check if the host is online, not if the DNS service is online. use ping for the simplest test, and if the host is configured to ignore ping (for security reasons), you can alternatively check a vital service that the host provides.
    1 point
  7. Something like this? #include <Array.au3> Local $s_TECHID = GetTechID() MsgBox(0,'', $s_TECHID) Func GetTechID() Local $as_IniRead = IniReadSection(@ScriptDir & '\settings.ini', 'Users') If IsArray($as_IniRead) Then Return _ArrayToString($as_IniRead, '|', 1, -1, '|', 0, 0) EndFunc ;==>GetTechID
    1 point
  8. Found it! $BProgress was the handle to the control ... obtained with $BProgress = GUICtrlGetHandle($AProgress) ... which is required by _SendMessage. But resetting the control simply requires setting the style of the ControlID. Maybe this post will help someone.
    1 point
  9. Oh.. the group control, I thought it was a group of controls. Something like this maybe? #include <Misc.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> #include <Word.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <ColorConstantS.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <ListViewConstants.au3> #include <GuiListView.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <GDIPlus.au3> #include <WinAPI.au3> Global $GUI = GUICreate("Opticiens-Atol", 800, 600) $Font1 = GUICtrlCreateLabel("", 5, 5, 185, 130) $Groupe1 = GUICtrlCreateGroup("Office1", 5, 5, 190, 135) ;Groupe OFFICE $Groupe2 = GUICtrlCreateGroup("Utilisateur2", 200, 5, 200, 195) ;Groupe Utilisateur $Groupe3 = GUICtrlCreateGroup("Accés réseau3", 405, 5, 390, 120) ;Groupe RESEAU $Groupe4 = GUICtrlCreateGroup("Lecture AD4", 405, 125, 390, 75) ;Groupe RESEAU GUICtrlSetGroupBkColor($Groupe1, 0x4486FA) GUISetState(@SW_SHOW, $GUI) While (1) Switch (GUIGetMsg()) Case $GUI_EVENT_CLOSE Exit 0 EndSwitch WEnd Func GUICtrlSetGroupBkColor(Const $iCtrl, Const $iColor) Local Static $iBorder = 4 ; Border of the group control, this is the grey line around the edges Local Static $iYOffset = 14 ; Y offset to account for the text in the group control Local $hWnd = IsHWnd($iCtrl) ? $iCtrl : GUICtrlGetHandle($iCtrl) ; Handle used to get the control position Local $aCtrlArea = ControlGetPos(_WinAPI_GetParent($hWnd), "", $iCtrl) ; Get the control position Local $lblReturn = GUICtrlCreateLabel("", $aCtrlArea[0] + $iBorder, $aCtrlArea[1] + $iYOffset, $aCtrlArea[2] - $iBorder * 2, $aCtrlArea[3] - $iYOffset - $iBorder) ; Create a label that's used for the back color inside the group control GUICtrlSetColor($lblReturn, $iColor) GUICtrlSetBkColor($lblReturn, $iColor) GUICtrlSetState($lblReturn, $GUI_DISABLE) GUICtrlSetBkColor($iCtrl, $iColor) Return $lblReturn ; Return the label, can be stored and used to update the color of this group later EndFunc ;==>GUICtrlSetGroupBkColor#include <Misc.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> #include <Word.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <ColorConstantS.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <ListViewConstants.au3> #include <GuiListView.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <GDIPlus.au3> #include <WinAPI.au3> Global $GUI = GUICreate("Opticiens-Atol", 800, 600) $Font1 = GUICtrlCreateLabel("", 5, 5, 185, 130) $Groupe1 = GUICtrlCreateGroup("Office1", 5, 5, 190, 135) ;Groupe OFFICE $Groupe2 = GUICtrlCreateGroup("Utilisateur2", 200, 5, 200, 195) ;Groupe Utilisateur $Groupe3 = GUICtrlCreateGroup("Accés réseau3", 405, 5, 390, 120) ;Groupe RESEAU $Groupe4 = GUICtrlCreateGroup("Lecture AD4", 405, 125, 390, 75) ;Groupe RESEAU GUICtrlSetGroupBkColor($Groupe1, 0x4486FA) GUISetState(@SW_SHOW, $GUI) While (1) Switch (GUIGetMsg()) Case $GUI_EVENT_CLOSE Exit 0 EndSwitch WEnd Func GUICtrlSetGroupBkColor(Const $iCtrl, Const $iColor) Local Static $iBorder = 4 ; Border of the group control, this is the grey line around the edges Local Static $iYOffset = 14 ; Y offset to account for the text in the group control Local $hWnd = IsHWnd($iCtrl) ? $iCtrl : GUICtrlGetHandle($iCtrl) ; Handle used to get the control position Local $aCtrlArea = ControlGetPos(_WinAPI_GetParent($hWnd), "", $iCtrl) ; Get the control position Local $lblReturn = GUICtrlCreateLabel("", $aCtrlArea[0] + $iBorder, $aCtrlArea[1] + $iYOffset, $aCtrlArea[2] - $iBorder * 2, $tCtrlArea[3] - $iYOffset - $iBorder) ; Create a label that's used for the back color inside the group control GUICtrlSetColor($lblReturn, $iColor) GUICtrlSetBkColor($lblReturn, $iColor) GUICtrlSetState($lblReturn, $GUI_DISABLE) GUICtrlSetBkColor($iCtrl, $iColor) Return $lblReturn ; Return the label, can be stored and used to update the color of this group later EndFunc ;==>GUICtrlSetGroupBkColor You might get a more desirable result if you just created a square using some labels and using them as the border for your "group" and then you can create another label for the actual background of the group.
    1 point
  10. No image file to create, and you can keep your tabs. The job is done by creating and deleting one pic control only Please try this in your script in post #1 #Include <WinAPI.au3> ; add this include ;..... Func _ShowFlag () Local Const $STM_SETIMAGE = 0x0172 Local Static $pic GuiCtrlDelete($pic) GuiSwitch($MainGUI, $Tab0) _GDIPlus_Startup () Local $hBitmap = _GDIPlus_BitmapCreateFromMemory(Binary (_GetInfoFromDataBase ("SELECT flag FROM countries WHERE eng = " & _SQLite_Escape (GUICtrlRead($CountriesCombo)) & ";"))) Local $iPicWidth = _GDIPlus_ImageGetWidth($hBitmap) Local $iPicHeight = _GDIPlus_ImageGetHeight($hBitmap) $pic = GUICtrlCreatePic("", ($iWidth - $iPicWidth) / 2 + Random (0, 300, 1), ($iHeight - $iPicHeight) / 2 + Random (0, 300, 1), $iPicWidth, $iPicHeight) $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _WinAPI_DeleteObject(GUICtrlSendMsg($pic, $STM_SETIMAGE, 0, $hHBmp)) GUICtrlCreateTabItem("") GUISetState() _GDIPlus_BitmapDispose($hBitmap) _WinAPI_DeleteObject($hHBmp) _GDIPlus_Shutdown() EndFunc ; _ShowFlag
    1 point
  11. david1337

    Search box for names

    Danyfirex, you sure did mate! and NO WAY.. you just created the search button..! How bad ass are you? So the GUIRegisterMsg refers to the new func, in which the highlight part, color code etc. is defined. The whole DllStruct part I have clue what does. Anyway, can't thank you enough! Saludos!
    1 point
  12. Melba23, you beat me to it, but I will post what I wrote anyways. Yours looks more efficient, though. #include <GUIConstantsEx.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> #include <GuiTab.au3> HotKeySet("^{TAB}", "_TabRight") HotKeySet("^+{TAB}", "_TabLeft") $Form1 = GUICreate("Form1", 444, 232) $hWnd = GUICtrlCreateTab(16, 16, 409, 193) $TabSheet1 = GUICtrlCreateTabItem("TabSheet1") GUICtrlSetState(-1, $GUI_SHOW) $TabSheet2 = GUICtrlCreateTabItem("TabSheet2") $TabSheet3 = GUICtrlCreateTabItem("TabSheet3") $TabSheet4 = GUICtrlCreateTabItem("TabSheet4") $TabSheet5 = GUICtrlCreateTabItem("TabSheet5") GUICtrlCreateTabItem("") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _TabRight() $CurPos = _GUICtrlTab_GetCurSel($hWnd) _GUICtrlTab_SetCurSel($hWnd, $CurPos + 1) EndFunc Func _TabLeft() $CurPos = _GUICtrlTab_GetCurSel($hWnd) _GUICtrlTab_SetCurSel($hWnd, $CurPos - 1) EndFunc
    1 point
  13. mLipok, If you want this functionality in an AutoIt GUI then I would use accelerator keys like this: #include <GUIConstantsEx.au3> Global $aTab[3] $hGUI = GUICreate("Test", 500, 500) $cTab = GUICtrlCreateTab(10, 10, 480, 200) $aTab[0] = GUICtrlCreateTabItem("Tab 0") $aTab[1] = GUICtrlCreateTabItem("Tab 1") $aTab[2] = GUICtrlCreateTabItem("Tab 2") GUICtrlCreateTabItem("") $cTab_Right = GUICtrlCreateDummy() $cTab_Left = GUICtrlCreateDummy() GUISetState() Global $aAccelKeys[2][2] = [["^{TAB}", $cTab_Right],["^+{TAB}", $cTab_Left]] GUISetAccelerators($aAccelKeys) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cTab_Right $iTab = GUICtrlRead($cTab) + 1 If $iTab > (UBound($aTab) - 1) Then $iTab = 0 GUICtrlSetState($aTab[$iTab], $GUI_SHOW) Case $cTab_Left $iTab = GUICtrlRead($cTab) - 1 If $iTab < 0 Then $iTab = UBound($aTab) - 1 GUICtrlSetState($aTab[$iTab], $GUI_SHOW) EndSwitch WEnd M23
    1 point
×
×
  • Create New...