[UDF] Time Notify

Partagez des fonctions et des UDF AutoIt.
Règles du forum
.
Répondre
Avatar du membre
Numeric
Niveau 5
Niveau 5
Messages : 125
Enregistré le : mer. 23 mars 2016 08:17
Status : Hors ligne

[UDF] Time Notify

#1

Message par Numeric »

Salut,
Je vous propose un model d'interaction de deux programmes afin de préserver le temps réel dans l"exécution de ceux ci...

Guide utilisateur :
1) Lancez d'abord le serveur...il n'y a aucune notification qui vous prévienne que le serveur est lancé...
2) Lancez le client...et attendez au moins une minute dans le cas de mon exemple pour voir la notification...et encore une minute de plus pour pour la revoir. :?
Remarque : (ces fonctions sont toujours en étude..et je vous proposerai un truc complet...)

Serveur
#include <Date.au3>
#include <WinAPI.au3>

HotKeySet("{ESC}", "_Exit")
;========================================================================================================================
;declaration globale
;========================================================================================================================
Global Const $IP_Adress = @IPAddress1, $iPort = 80, $iMax = 2
Global $Recv, $MainSOCKET, $Socket, $tagStruct
Global Const $tStruct = "struct;long heure;long min;long sec;long eache;hwnd win;long start;long toend;long top;endstruct"

If Not TCPStartup() Then
   _WinAPI_ShowError("Enabable to create ressource", True)
EndIf

$MainSOCKET = TCPListen($IP_Adress, $iPort, $iMax)

If $MainSOCKET = -1 Or $MainSOCKET = 0 Then
   TCPShutdown()
   _WinAPI_ShowError("Impossible de se connecter!")
EndIf


Do
   $Socket = TCPAccept($MainSOCKET)
   Sleep(20)
Until $Socket <> -1
;Creation de la structure pour gerer le client
;le serveur recevra les ordres à partir de cette structure.
$tagStruct = DllStructCreate($tStruct)
If @error Then
   _WinAPI_ShowError("Impossible de créer la structure", True)
EndIf


$Recv = TCPRecv($Socket, 9999);Entree des donnes
AdlibRegister("__sDataBase", 250);Requete de demande d'ordre
While 1
   Sleep(30)
WEnd

TCPCloseSocket($MainSOCKET)
TCPShutdown()






; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __sDataBase
; Description ...: Gere les données du client
; Syntax ........: __sDataBase()
; Parameters ....:
; Return values .: None
; Author ........: Numeric
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func __sDataBase()
   $Recv = TCPRecv($Socket, 9999)
   If StringInStr($Recv, "time") Then
      Local $GetALL = StringSplit($Recv, "|")
      DllStructSetData($tagStruct, "heure", $GetALL[2])
      DllStructSetData($tagStruct, "min", $GetALL[3])
      DllStructSetData($tagStruct, "sec", $GetALL[4])
      DllStructSetData($tagStruct, "eache", $GetALL[5])
      DllStructSetData($tagStruct, "win", $GetALL[6])
      DllStructSetData($tagStruct, "start", $GetALL[7])
      DllStructSetData($tagStruct, "toend", $GetALL[8])
      DllStructSetData($tagStruct, "top", $GetALL[9])
   EndIf
   If __TimeCompare($tagStruct) Then
      If IsNumber(DllStructGetData($tagStruct, "eache")) Then
         Local $sNewDate = _DateAdd("n", DllStructGetData($tagStruct, "eache"), _NowCalc())
         Local $GetTime = StringSplit($sNewDate, " ")[2]
         Local $aPart = StringSplit($GetTime, ":")
         DllStructSetData($tagStruct, "heure", $aPart[1])
         DllStructSetData($tagStruct, "min", $aPart[2])
         DllStructSetData($tagStruct, "sec", $aPart[3])
      EndIf
      __MoveWindow($tagStruct)
   EndIf
EndFunc   ;==>__sDataBase



; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __TimeCompare
; Description ...:  Compare les donnees du temps
; Syntax ........: __TimeCompare($tagStruct)
; Parameters ....: $tagStruct           - a structures definition.
; Return values .: True or false
; Author ........: Numeric
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __TimeCompare($tagStruct)
   If DllStructGetData($tagStruct, "heure") = @HOUR Then
      If DllStructGetData($tagStruct, "min") = @MIN Then
         If DllStructGetData($tagStruct, "sec") = @SEC Then
            Return True
         EndIf
      EndIf
   EndIf
   Return False
EndFunc   ;==>__TimeCompare

Func _Exit()
   Exit
EndFunc   ;==>_Exit


; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __MoveWindow
; Description ...:  Déplace la fenetre...
; Syntax ........: __MoveWindow($DLL)
; Parameters ....: $DLL                 - an unknown value.
; Return values .: None
; Author ........: Numeric
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __MoveWindow($DLL)
   Local $toStart = DllStructGetData($tagStruct, "start")
   Local $toEnd = DllStructGetData($tagStruct, "toend")
   Local $WinHwnd = DllStructGetData($tagStruct, "win")
   Local $Top = DllStructGetData($tagStruct, "top")

   For $i = $toStart To $toEnd
      Sleep(10)
      WinMove($WinHwnd, "", $i, $Top)
   Next
   Sleep(300)
   For $j = $toEnd To $toStart Step -1
      Sleep(10)
      WinMove($WinHwnd, "", $j, $Top)
   Next
EndFunc   ;==>__MoveWindow

 
De 0 et 1 vers les étoiles , tout part du Binaire, Numeric
Avatar du membre
Numeric
Niveau 5
Niveau 5
Messages : 125
Enregistré le : mer. 23 mars 2016 08:17
Status : Hors ligne

Re: [UDF] Time Notify

#2

Message par Numeric »

Client
#include-once
#include <Date.au3>
#include <StaticConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>


;========================================================================================================================================
;Declaration globale
;=======================================================================================================================================
Global Const $tagWindowGetState = 'struct;wchar uText[13];int uTextFont;int TimeLabelFont;bool RoundRect;int WinHeight;hwnd WinHandle;endstruct'
Global $__tn_ghWnd, $__tn_idLabel, $tWinSTATE_INFOS, $idLabel, $tnINITIAL_POS
Global $tnDEFAULT_FONT = 36
Global $tnDEFAULT_FONT_NAME = "Modern No. 20"
Global $Socket, $iPort = 80, $IP_Adress = @IPAddress1
;=======================================================================================================================================


#Region Exemple
Local $ToCreate = TimeNotifyCreate("Hello World!", Default, Default, Default)
TimeNotifySetFont(Default, Default)
TimeNotifySetRoundWin($ToCreate)
TimeNotifStart(@HOUR, @MIN + 1, 00, 1)
#EndRegion Exemple


; #FUNCTION# ====================================================================================================================
; Name ..........: TimeNotifyCreate
; Description ...: Cree et initialise la fenetre TimeNotify
; Syntax ........: TimeNotifyCreate([$sText = ""[, $iTransparency = Default[, $sTextColor = Default[, $bkColor = Default]]]])
; Parameters ....: $sText               - [optional] a string value. Default is "".
;                  $iTransparency       - [optional] an integer value. Default is Default.
;                  $sTextColor          - [optional] a string value. Default is Default.
;                  $bkColor             - [optional] a boolean value. Default is Default.
; Return values .: None
; Author ........: Numeric
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func TimeNotifyCreate($sText = "", $iTransparency = Default, $sTextColor = Default, $bkColor = Default)
   Local $LabelStyle = BitOR($SS_CENTER, $SS_CENTERIMAGE)
   $tWinSTATE_INFOS = DllStructCreate($tagWindowGetState)

   $__tn_ghWnd = GUICreate("", 319, 121, 0, 0, BitOR($WS_SYSMENU, $WS_POPUP), $WS_EX_TOPMOST)
   Local $aWinPos = WinGetPos($__tn_ghWnd)
   Local $Left = $aWinPos[0], $Top = $aWinPos[1], $Width = $aWinPos[2], $WinHeight = $aWinPos[3]
   $tnINITIAL_POS = DllStructCreate("struct;long Left;long Top;long Width;long Height;endstruct")
   DllStructSetData($tnINITIAL_POS, "Left", $Left)
   DllStructSetData($tnINITIAL_POS, "Top", $Top)
   DllStructSetData($tnINITIAL_POS, "Width", $Width)
   DllStructSetData($tnINITIAL_POS, "Height", $WinHeight)

   $__tn_idLabel = GUICtrlCreateLabel(_NowTime(), 0, 0, $Width, $WinHeight / 2, $LabelStyle)

   Local $_FirstCTRLHeight = $WinHeight / 2
   Local $_SecLabelHeight = $WinHeight - $_FirstCTRLHeight

   If Not StringLen($sText) Then
      $WinHeight = $_FirstCTRLHeight
   Else
      DllStructSetData($tWinSTATE_INFOS, "uText", $sText)
      Local $showText = getData("uText")
      $idLabel = GUICtrlCreateLabel($showText, $Left, $_FirstCTRLHeight, $Width, $_SecLabelHeight, $LabelStyle)

   EndIf
   DllStructSetData($tWinSTATE_INFOS, "WinHeight", $WinHeight)
   WinMove($__tn_ghWnd, "", $Left, $Top, $Width, $WinHeight)

   WinMove($__tn_ghWnd, "", $Left - $Width, $Top);Hide mode

   If $sTextColor = Default Or $sTextColor = "" Then $sTextColor = 0x0000FF
   GUICtrlSetColor($idLabel, $sTextColor)

   If $bkColor = Default Or $bkColor = "" Then $bkColor = 0xFF0000
   GUICtrlSetColor($__tn_idLabel, $bkColor)
   DllStructSetData($tWinSTATE_INFOS, "WinHandle", WinGetHandle($__tn_ghWnd))
   If $iTransparency = Default Then $iTransparency = 960
   If IsNumber($iTransparency) Then
      WinSetTrans($__tn_ghWnd, "", $iTransparency)
   EndIf
   HotKeySet("{ESC}", "_Exit")
   Return $__tn_ghWnd
EndFunc   ;==>TimeNotifyCreate

; #FUNCTION# ====================================================================================================================
; Name ..........: TimeNotifStart
; Description ...: Commence la notification...
; Syntax ........: TimeNotifStart([$H = @HOUR[, $Min = @MIN[, $Sec = @SEC[, $EachTime = 1]]]])
; Parameters ....: $H                   - [optional] an unknown value. Default is @HOUR.
;                  $Min                 - [optional] an unknown value. Default is @MIN.
;                  $Sec                 - [optional] an unknown value. Default is @SEC.
;                  $EachTime            - [optional] an unknown value. Default is 1.
; Return values .: None
; Author ........: Numeric
; Modified ......:
; Remarks .......: $EachTime defini la duree de temps que la fenetre prend avant de s'afficher
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func TimeNotifStart($H = @HOUR, $Min = @MIN, $Sec = @SEC, $EachTime = 1)
   If Not TCPStartup() Then
      _WinAPI_ShowError("Impossible de générer les ressources necessaires" & @CRLF & "Veuillez reessayer plus tard!", True)
   EndIf
   Local $getHwd = DllStructGetData($tWinSTATE_INFOS, "WinHandle")
   If Not IsHWnd($getHwd) Then
      _WinAPI_ShowError("Time notify must be created", True)
   EndIf
   $Socket = TCPConnect($IP_Adress, $iPort)
   If $Socket = -1 Or $Socket = 0 Then
      TCPShutdown()
      _WinAPI_ShowError("Impossible de se connecter!", True)
   EndIf
   MsgBox(48, "Client", "Connexion établie...", 1)
   Local $Left, $Top, $Width
   $Left = getData("Left", $tnINITIAL_POS)
   $Top = getData("Top", $tnINITIAL_POS)
   $Width = getData("Width", $tnINITIAL_POS)

   Local $Date = "time|" & $H & "|" & $Min & "|" & $Sec & "|" & $EachTime & "|" & $getHwd & "|" & ($Left - $Width) & "|" & $Left & "|" & $Top

   TCPSend($Socket, $Date)
   GUISetState(@SW_SHOW, $getHwd)
   AdlibRegister("NetRectInLabel", 250)

   While 1
      Sleep(5)
   WEnd
EndFunc   ;==>TimeNotifStart


; #FUNCTION# ====================================================================================================================
; Name ..........: TimeNotifySetFont
; Description ...: Definit la police et d'affichage du temps et de la notification
; Syntax ........: TimeNotifySetFont([$iSize = Default[, $sFontName = Default]])
; Parameters ....: $iSize               - [optional] an integer value. Default is Default.
;                  $sFontName           - [optional] a string value. Default is Default.
; Return values .: None
; Author ........: Numeric
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func TimeNotifySetFont($iSize = Default, $sFontName = Default)
   Local $s__Size
   If $iSize = Default Then $iSize = $tnDEFAULT_FONT
   If $sFontName = Default Then $sFontName = $tnDEFAULT_FONT_NAME

   If $iSize >= 30 Then
      $s__Size = $iSize - 10
   Else
      $s__Size = $iSize - 2
   EndIf
   GUICtrlSetFont($__tn_idLabel, $iSize, 400, 0, $sFontName)
   GUICtrlSetFont($idLabel, $s__Size, 400, 0, $sFontName)
   If IsDllStruct($tWinSTATE_INFOS) Then
      DllStructSetData($tWinSTATE_INFOS, "TimeLabelFont", $iSize)
   EndIf
EndFunc   ;==>TimeNotifySetFont


; #FUNCTION# ====================================================================================================================
; Name ..........: TimeNotifySetRoundWin
; Description ...: Permet d'avoir la fenetre ronde...
; Syntax ........: TimeNotifySetRoundWin($hWnd)
; Parameters ....: $hWnd                - a handle value.
; Return values .: None
; Author ........: Numeric
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func TimeNotifySetRoundWin($hWnd)
   If IsHWnd($__tn_ghWnd) Then
      $hWnd = $__tn_ghWnd
   Else
      $hWnd = WinGetHandle($hWnd)
   EndIf
   Local $hRgn = _WinAPI_CreateRoundRectRgn(0, 0, WinGetPos($hWnd)[2], WinGetPos($hWnd)[3], WinGetPos($hWnd)[2] / 3, WinGetPos($hWnd)[3] / 3)
   _WinAPI_SetWindowRgn($hWnd, $hRgn, True)
   _WinAPI_SelectObject($hWnd, $hRgn)
   _WinAPI_ReleaseDC($hWnd, $hRgn)
   If IsDllStruct($tWinSTATE_INFOS) Then
      DllStructSetData($tWinSTATE_INFOS, "RoundRect", True)
   EndIf
EndFunc   ;==>TimeNotifySetRoundWin

;================================================================================================================================
; fonctions internes
;================================================================================================================================
Func _Exit()
   Exit
EndFunc   ;==>_Exit

Func NetRectInLabel()
   GUICtrlSetData($__tn_idLabel, _NowTime())
EndFunc   ;==>NetRectInLabel

Func getData($DataName, $tSTRUCT = $tWinSTATE_INFOS)
   If IsDllStruct($tSTRUCT) Then
      Return DllStructGetData($tSTRUCT, $DataName)
   EndIf
EndFunc   ;==>getData
;================================================================================================================================
De 0 et 1 vers les étoiles , tout part du Binaire, Numeric
Répondre