Jump to content

Recommended Posts

Posted

Hello,

I need your help with my code. First it works. Cool.

Global $titre_logiciel="Logiciel Maxou version 1.01"
TrayTip($titre_logiciel,"Lancement de l'application",1000)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <ButtonConstants.au3>
#include <GUIConstants.au3>

$aLabel = _GetNames(_GetObj())
Dim $aCheckBox[$aLabel[0] + 1][2]
Dim $aAdapter[2]

$hSelection = GUICreate("Selection", 300, $aLabel[0] * 30 + 30, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))
If $aLabel[0] = 0 Then
    MsgBox(0, "Error", "No Adapters Found", 0, $hSelection)
    Exit
EndIf

For $i = 1 To $aLabel[0]
    $aCheckBox[$i][0] = GUICtrlCreateCheckbox($aLabel[$i], 8, $i * 20, 290)
    $aCheckBox[$i][1] = $aLabel[$i]
Next
$aCheckBox[0][0] = $aLabel[0]

$Button1 = GUICtrlCreateButton("Valider", 100, $aLabel[0] * 30, 75)
GUISetState(@SW_SHOW)

While 1
    Sleep(50)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $i1 = 1
            $bExit = 0
            For $i = 1 To $aCheckBox[0][0]
                If GUICtrlRead($aCheckBox[$i][0]) = 1 Then
                    $aAdapter[0] = $i1
                    ReDim $aAdapter[$i1 + 1]
                    $aAdapter[$i1] = $aCheckBox[$i][1]
                    $i1 += 1
                    $bExit = 1
                EndIf
            Next
            If $bExit = 1 Then
                GUIDelete($hSelection)
                ExitLoop
            Else
                MsgBox(0, "Error", "No Adapter Selected", 0, $hSelection)
            EndIf
    EndSwitch
WEnd

Func _GetNames($colItems)
    Local $aName[2], $i = 1
    If IsObj($colItems) Then
        For $objItem In $colItems
            $aName[0] = $i
            ReDim $aName[$i + 1]
            $aName[$i] = $objItem.Name
            $i += 1
        Next
    EndIf
    Return $aName
EndFunc   ;==>_GetNames

Func _GetData($colItems, $aAdapter)
    Local $aData[2]
    If IsObj($colItems) Then
        For $objItem In $colItems
            For $i = 1 To $aAdapter[0]
                If $objItem.Name = $aAdapter[$i] Then
                    $aData[0] += $objItem.BytesReceivedPersec
                    $aData[1] += $objItem.BytesSentPersec
                EndIf
            Next
        Next
    EndIf
    Return $aData
EndFunc   ;==>_GetData

Func _GetObj()
    Local $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20, $colItems = "", $strComputer = "localhost"
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")

    $colItems = $objWMIService.ExecQuery("SELECT BytesReceivedPersec,BytesSentPersec,Name FROM Win32_PerfRawData_Tcpip_NetworkInterface", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    Return $colItems
EndFunc   ;==>_GetObj

Func _Exit()
    Exit
EndFunc

; crĂ©ation de la petite fenĂȘtre
Global Const $SC_DRAGMOVE = 0xF012
Global $iX_Min = 0, $iX_Max = @DesktopWidth - 200, $iY_Min = 0, $iY_Max = @DesktopHeight - 26
Global $iWidth = 200 ,$iHeight = 26
Local $hGUI = GUICreate('', $iWidth, $iHeight, Default, Default, BitOR($WS_POPUP, $WS_BORDER), $WS_EX_TOPMOST)

$Label1 = GUICtrlCreateLabel("", 5, 5, 68, 16, $SS_RIGHT)
$Label2 = GUICtrlCreateLabel("", 81, 5, 68, 16, $SS_RIGHT)
GUICtrlSetBkColor($Label1, 0xCEECF5)
GUICtrlSetBkColor($Label2, 0xCEECF5)

Global Const $g_MAXGr = 6
Global $g_aidGraphics[$g_MAXGr + 1]
$g_aidGraphics[1] = GUICtrlCreateGraphic(2, 2, 74, 22)
GUICtrlSetBkColor(-1, 0xCEECF5)
GUICtrlSetColor(-1, 0)
$g_aidGraphics[2] = GUICtrlCreateGraphic(78, 2, 74, 22)
GUICtrlSetBkColor(-1, 0xCEECF5)
GUICtrlSetColor(-1, 0)

Local $iInfos = GUICtrlCreateButton('I', 158, 2, 20, 22)
Local $iClose = GUICtrlCreateButton('X', 178, 2, 20, 22)

GUISetBkColor (0xA9D0F5)
GUISetState(@SW_SHOW, $hGUI)
GUIRegisterMsg($WM_WINDOWPOSCHANGING, "WM_WINDOWPOSCHANGING")

$download1=0
$download2=0
$upload1=0
$upload2=0
$maxi=0
$Data_now = _GetData(_GetObj(), $aAdapter)

; HERE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $iClose
            TrayTip($titre_logiciel,"Fermeture de l'application",1000)
            ExitLoop
        Case $GUI_EVENT_PRIMARYDOWN
            _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
    EndSwitch
WEnd


Func WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)

    Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam)

    Local $iLeft = DllStructGetData($stWinPos, 3)
    Local $iTop = DllStructGetData($stWinPos, 4)
    Local $iWidth = DllStructGetData($stWinPos, 5)
    Local $iHeight = DllStructGetData($stWinPos, 6)

    If $iLeft < $iX_Min Then DllStructSetData($stWinPos, 3, $iX_Min)
    If $iTop < $iY_Min Then DllStructSetData($stWinPos, 4, $iY_Min)
    If $iLeft > $iX_Max Then DllStructSetData($stWinPos, 3, $iX_Max)
    If $iTop > $iY_Max Then DllStructSetData($stWinPos, 4, $iY_Max)

EndFunc

but i want to write a result in "$label1" and "$label2" every second.

$btmp= _GetData(_GetObj(), $aAdapter)
    Sleep(1000)

    $aData = _GetData(_GetObj(), $aAdapter)

    $bData = $aData[0] - $Data_now[0]
    $bData2 = $aData[1] - $Data_now[1]

    $difftmp= ($aData[0]-$btmp[0])

    $download_kbps =($bData / 1024)-$download1
    $download1=($bData / 1024)
    $download_mbps =($bData / 1048576)-$download2
    $download2=($bData / 1048576)

    $upload_kbps =($bData2 / 1024)-$upload1
    $upload1=($bData2 / 1024)
    $upload_mbps =($bData2 / 1048576)-$upload2
    $upload2=($bData2 / 1048576)

   If $download_mbps>$maxi Then
       $maxi=$download_mbps
   EndIf

    If $download_kbps<1000 then
        GUICtrlSetData($Label1, StringFormat("%.2f", Round($download_kbps *8, 2)) & " kbps")
    Else
        GUICtrlSetData($Label1, StringFormat("%.2f", Round($download_mbps *8, 2)) & " mbps")
    EndIf

    If $upload_kbps<1000 then
        GUICtrlSetData($Label2, StringFormat("%.2f", Round($upload_kbps *8, 2)) & " kbps")
    Else
        GUICtrlSetData($Label2, StringFormat("%.2f", Round($upload_mbps *8, 2)) & " mbps")
    EndIf

I try switch, but i loose move option and close button. for select same.

If someone can help me. (sorry for my english)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...