carloselectro Posted February 15, 2019 Share Posted February 15, 2019 Hi, I need some help with the _Singleton function. I want my application to be restored from the systray if a user tries to reopen the application a second time. I have the following that shows the window of my application that has been minimized to the systray, but for some reason, the button does not work anymore, unless I minimized the window and single click in the systray. If _Singleton("My program.Exe", 1) = 0 Then ;Show form from tray application WinSetState ( "My program", "", @SW_RESTORE) WinActivate ( "My program" , "" ) Exit EndIf Link to comment Share on other sites More sharing options...
Developers Jos Posted February 15, 2019 Developers Share Posted February 15, 2019 Please show a script that reproduces the issue as this code merely shows the GUI again when the script is ran for the second time. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
carloselectro Posted February 15, 2019 Author Share Posted February 15, 2019 Here you go: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Mic.ico #AutoIt3Wrapper_Outfile=Controle soins simulation.Exe #AutoIt3Wrapper_Outfile_x64=Controle soins simulation.Exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; Programme qui commnunique avec un raspberry pi pour modifier les paramètres audio ; du système de simulation de soins infirmer ; version 1.0 ; Auteur : Carl Fortin #include <GUIConstantsEx.au3> #include <constants.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <TrayConstants.au3> #include <Misc.au3> #include <Debug.au3> #include <GDIPlus.au3> #include <File.au3> #include <Array.au3> #include <Date.au3> #include <GDIPlus.au3> #include <GuiConstantsEx.au3> #include <WinAPI.au3> Opt("TrayAutoPause", 0) Opt("MustDeclareVars", 1) Opt("TrayMenuMode", 3) Opt("TrayOnEventMode", 1) ;##################################################### MAIN #################################################################################### Global $System_state Global $hTimer Global $salle Global $Form1 Global $LED_ROUGE Global $LED_VERTE Global $Logo Global $idAbout Global $idExit Global $Button_ouverture Global $Button_fermeture Global $Button_evier Global $Button_bureau Global $Button_tel Global $MIC_EVIER_STATE Global $MIC_BUREAU_STATE Global $TEL_STATE Global $g_hGUI_Evier_On Global $g_hGUI_Bureau_On Global $g_hGUI_Evier_Off Global $g_hGUI_Bureau_Off Global $g_hGUI_Tel_On Global $g_hGUI_Tel_Off Global Const $TITLE_GUI = 'Contrôle soins' ;Enable debugging _DebugSetup("Control soins", True, 4, @ScriptDir & "\LOG control soins.log", True) ;Une seule instance du script est permise If Not _Singleton($TITLE_GUI, 1) Then MsgBox(BitOR($MB_ICONINFORMATION, $MB_TOPMOST), "Attention", "Le programme à déjà été ouvert une fois!") _DebugOut("Le programme à déjà été ouvert une fois!") ;Réactive une fenêtre existante du programme déjà ouvert WinSetState ( $TITLE_GUI, "", @SW_RESTORE) WinActivate ( $TITLE_GUI) Exit EndIf $MIC_EVIER_STATE = 0 $MIC_BUREAU_STATE = 0 $TEL_STATE = 0 $System_state = 0 Local $sImage_Icon_Evier_On = @ScriptDir & "\MIC_EVIER_ON.png" Local $sImage_Icon_Bureau_On = @ScriptDir & "\MIC_BUREAU_ON.png" Local $sImage_Icon_Evier_Off = @ScriptDir & "\MIC_EVIER_OFF.png" Local $sImage_Icon_Bureau_Off = @ScriptDir & "\MIC_BUREAU_OFF.png" Local $sImage_Icon_Tel_Off = @ScriptDir & "\TEL_OFF.png" Local $sImage_Icon_Tel_On = @ScriptDir & "\TEL_ON.png" ;Create transparent Icon Evier ON $g_hGUI_Evier_On = Create_trans_image(305, 140, $sImage_Icon_Evier_On, "FORM_MIC_EVIER_ON") ;Create transparent Icon Bureau ON $g_hGUI_Bureau_On = Create_trans_image(205, 140, $sImage_Icon_Bureau_On, "FORM_MIC_BUREAU_ON") ;Create transparent Icon Evier OFF $g_hGUI_Evier_Off = Create_trans_image(305, 140, $sImage_Icon_Evier_Off, "FORM_MIC_EVIER_OFF") ;Create transparent Icon Bureau OFF $g_hGUI_Bureau_Off = Create_trans_image(205, 140, $sImage_Icon_Bureau_Off, "FORM_MIC_BUREAU_OFF") ;Create transparent Icon TEL ON $g_hGUI_Tel_On = Create_trans_image(105, 140, $sImage_Icon_Tel_On, "FORM_TEL_ON") ;Create transparent Icon TEL ON $g_hGUI_Tel_Off = Create_trans_image(105, 140, $sImage_Icon_Tel_Off, "FORM_TEL_OFF") _DebugOut("Démarrage du programme...") ; Lire le fichier ini qui détermine quel bureau controle les micros Local $ini_file = @ScriptDir & "\Parametre.ini" Local $sRead = IniRead($ini_file, "salle_professeur", "bureau", "Default Value") If ($sRead = "M-1217-01") Or ($sRead = "M-1217-02") Then $salle = $sRead ConsoleWrite("Controle salle " & $salle & @CRLF) Else _DebugOut("Fichier Parametre.ini introuvable ou numéro de bureau incorecte") MsgBox(4112, "Erreur", "Fichier Parametre.ini introuvable ou numéro de bureau incorecte") Exit EndIf ;Démarre Voicemeeter en mode caché avec le xml préconfigurer Start_voicemeeter() ;Changement des paramètres audio Set_default_sound() ;Create GUI Create_GUI() ;Création de la conexion TCp/IP TCP_INIT() ; Vérifie si le système est ouvert If Check_System_state() = True Then Set_Mic_Default_State() EndIf ;Définition des raccourcis claviers Local $set_hotkey_F7 = HotKeySet("{F7}", "MIC_EVIER") Local $set_hotkey_F8 = HotKeySet("{F8}", "MIC_BUREAU") Local $set_hotkey_F9 = HotKeySet("{F9}", "TEL") If $set_hotkey_F7 = 0 Then _DebugOut("Incapable d'assigner F7 comme raccourci clavier") MsgBox(4112, "Erreur", "Incapable d'assigner F7 comme raccourci clavier") EndIf If $set_hotkey_F8 = 0 Then _DebugOut("Incapable d'assigner F8 comme raccourci clavier") MsgBox(4112, "Erreur", "Incapable d'assigner F8 comme raccourci clavier") EndIf If $set_hotkey_F9 = 0 Then _DebugOut("Incapable d'assigner F9 comme raccourci clavier") MsgBox(4112, "Erreur", "Incapable d'assigner F9 comme raccourci clavier") EndIf Show_Mic_Status($MIC_EVIER_STATE, $MIC_BUREAU_STATE, $TEL_STATE) Set_MicroSIP() While 1 Switch GUIGetMsg($Form1) Case $GUI_EVENT_MINIMIZE GUISetState(@SW_HIDE, $Form1) TraySetState(1) Case $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $Form1) TraySetState(1) Case $Button_ouverture Button_ouvertureClick() Case $Button_fermeture Button_eteindreClick() Case $Button_evier MIC_EVIER() Case $Button_bureau MIC_BUREAU() Case $Button_tel TEL() EndSwitch WEnd ;##################################################### FONCTIONS #################################################################################### Func Create_GUI() Local $Formwidth = 478 Local $Formheight = 274 $Form1 = GUICreate("Contrôle soins", 478, 274, @DesktopWidth/2 - $Formwidth/2, @DesktopHeight/2 - $Formheight/2, -1, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE)) ;Texte des boutons en blanc GUICtrlSetDefColor(0xFFFFFF) ;Couleur du Background du GUI GUISetBkColor(0xFFFFFF) $Button_ouverture = GUICtrlCreateButton("Ouverture", 64, 40, 121, 65) GUICtrlSetFont(-1, 12, 400, 0, "Arial") GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetOnEvent(-1, "Button_ouvertureClick") $Button_fermeture = GUICtrlCreateButton("Fermeture", 300, 39, 121, 65) GUICtrlSetFont(-1, 12, 400, 0, "Arial") GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetOnEvent(-1, "Button_eteindreClick") Local $Group1 = GUICtrlCreateGroup("Alimentation du système audio", 40, 12, 409, 105) GUICtrlSetColor($Group1, 0x000000) Local $Group_raccourci = GUICtrlCreateGroup(" Raccourci clavier activation des micros ", 40, 120, 409, 100) $Button_evier = GUICtrlCreateButton("F7 = Évier", 190, 144, 97, 17) GUICtrlSetBkColor(-1, 0x000000) $Button_bureau = GUICtrlCreateButton("F8 = Bureau", 190, 167, 97, 17) GUICtrlSetBkColor(-1, 0x000000) $Button_tel = GUICtrlCreateButton("F9 = Tel", 190, 190, 97, 17) GUICtrlSetBkColor(-1, 0x000000) Local $Label1 = GUICtrlCreateLabel("C.F", 8, 250, 20, 17) GUICtrlSetColor($Label1, 0x000000) Local $Logo = GUICtrlCreatePic("cegep_logo_dti.jpg", 350, 220, 120, 60) ;Tray menu item $idAbout = TrayCreateItem("Information") $idExit = TrayCreateItem("Quiter") TrayItemSetOnEvent($idExit, "Quitter") TrayItemSetOnEvent($idAbout, "Information") TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "TrayEvent") ; Show the menu if the icon is right clicked TraySetClick(8) GUISetState() $LED_ROUGE = GUICtrlCreatePic(@ScriptDir & "\RED_LED.bmp", 215, 50, 57, 49) GUICtrlSetState($LED_ROUGE, $GUI_ENABLE) $LED_VERTE = GUICtrlCreatePic(@ScriptDir & "\GREEN_LED.bmp", 215, 50, 57, 49) GUICtrlSetState($LED_VERTE, $GUI_ENABLE) GUICtrlSetState($LED_VERTE, $GUI_HIDE) GUISetState(@SW_SHOW) EndFunc ;==>Create_GUI Func Start_voicemeeter() Local $param = " -h -l " & """" & @ScriptDir & "\voice_meter.xml" & """" Local $command = "C:\Program Files (x86)\VB\Voicemeeter\voicemeeterpro.exe" & $param LOcal $command_result = Run($command, "", @SW_HIDE) If $command_result = 0 Then _DebugOut("Incapable de démarrer Voicemeeter!") MsgBox(4112, "Erreur", "Incapable de démarrer Voicemeeter!") ;Exit Else _DebugOut("Voicemeeter démmaré corectement") EndIf EndFunc ;==>Start_voicemeeter Func Quitter() TCPShutdown() _DebugOut("Fermeture de l'application via le system tray") Exit EndFunc ;==>Quitter Func Information() ;Au sujet de l'application MsgBox(BitOR($MB_TOPMOST, $MB_ICONQUESTION), "Aide", @ScriptName & @CRLF & "Fait par Carl Fortin" & @CRLF & "Version: 1.0") EndFunc ;==>Information ;Répond avec Microsip automatiquement après un délais Func Answer_call($sleep_before_answer) Local $hWnd ;Répond seulement si aucun appel est actif If Check_Active_call() = False Then $hWnd = WinWait("Appel entrant", "", 1) ;Si la fenetre n'a pas été trouvé au bout de x temps If $hWnd = 0 Then _DebugOut("Appel entrant introuvable") ; MsgBox($MB_SYSTEMMODAL, "", "Appel entrant introuvable") Else WinActivate($hWnd, "") Sleep($sleep_before_answer) ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:1]") EndIf EndIf EndFunc ;==>Answer_call ;Place la fenêtre de MicroSIP à la bonne position et la bonne taille Func Set_MicroSIP() Local $hWnd = WinWait("[CLASS:MicroSIP]", "", 1) WinSetState ( $hWnd, "", @SW_RESTORE) WinMove($hWnd, "",0,460,259,518) EndFunc Func Check_Active_call() If WinExists("[CLASS:MicroSIP]", "Connecté") Then ;MsgBox($MB_SYSTEMMODAL, "", "Appel en cours...") Return True Else ;MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Erreur", "Aucun appel en cour") Return False EndIf EndFunc ;==>Check_Active_call Func MUTE_UNMUTE_VOICEMEETER() ;Toggle Mute Send("^{F10}") ConsoleWrite("Toggle input mute voicemeeter") EndFunc ;==>MUTE_UNMUTE_VOICEMEETER Func SET_MIC($type, $state) Local $Result If $salle = "M-1217-01" Then If $type = "bureau" Then $Result = Send_Data_To_TCP("MIC_BUREAU_01_" & $state) EndIf If $type = "evier" Then $Result = Send_Data_To_TCP("MIC_EVIER_01_" & $state) EndIf EndIf If $salle = "M-1217-02" Then If $type = "bureau" Then $Result = Send_Data_To_TCP("MIC_BUREAU_02_" & $state) EndIf If $type = "evier" Then $Result = Send_Data_To_TCP("MIC_EVIER_02_" & $state) EndIf EndIf If $Result = "ERREUR" Then MsgBox(4112, "ERREUR", "Incapable de controler le micro de la matrice") _DebugOut("Incapable de controler le micro de la matrice") Return "ERREUR" ; La réponse est OK on passe à l'action Else ; Si le téléphone était activé on démute voice If $TEL_STATE = 1 Then $TEL_STATE = 0 ;Unmute tel MUTE_UNMUTE_VOICEMEETER() EndIf If $type = "bureau" Then If $state = "ON" Then $MIC_BUREAU_STATE = 1 MUTE_MIC_MANEQUIN(1, "MUTE") MUTE_MIC_MANEQUIN(2, "MUTE") Else $MIC_BUREAU_STATE = 0 ; Unmute seulement si on n'a pas activé le micro de l'évier If $MIC_EVIER_STATE = 0 Then MUTE_MIC_MANEQUIN(1, "UNMUTE") MUTE_MIC_MANEQUIN(2, "UNMUTE") EndIf EndIf EndIf If $type = "evier" Then If $state = "ON" Then $MIC_EVIER_STATE = 1 MUTE_MIC_MANEQUIN(1, "MUTE") MUTE_MIC_MANEQUIN(2, "MUTE") Else $MIC_EVIER_STATE = 0 ; Unmute seulement si on n'a pas activé le micro du bureau If $MIC_BUREAU_STATE = 0 Then MUTE_MIC_MANEQUIN(1, "UNMUTE") MUTE_MIC_MANEQUIN(2, "UNMUTE") EndIf EndIf EndIf Return "OK" EndIf EndFunc ;==>SET_MIC ;Mute et unmute l'input 1 de Voicemeeter en envoyant le raccourci clavier (CTRL+F10) afin de ne plus entendre les micros des salles lorsqu'on est au téléphone Func TEL() Local $Result_1 Local $Result_2 Local $Result_3 If $TEL_STATE = 0 Then If $salle = "M-1217-01" Then $Result_1 = Send_Data_To_TCP("TEL_01_ON") EndIf If $salle = "M-1217-02" Then $Result_1 = Send_Data_To_TCP("TEL_02_ON") EndIf If $MIC_BUREAU_STATE = 1 Then ;La sortie 2 de la matrice est changé pour l'entrée du téléphone par la commande TEL_01_ON $MIC_BUREAU_STATE = 0 EndIf If $MIC_EVIER_STATE = 1 Then If $salle = "M-1217-01" Then $Result_3 = Send_Data_To_TCP("MIC_EVIER_01_OFF") EndIf If $salle = "M-1217-02" Then $Result_3 = Send_Data_To_TCP("MIC_EVIER_02_OFF") EndIf EndIf ;Mute les micros des mannequins MUTE_MIC_MANEQUIN(1, "MUTE") MUTE_MIC_MANEQUIN(2, "MUTE") Else If $salle = "M-1217-01" Then $Result_1 = Send_Data_To_TCP("TEL_01_OFF") EndIf If $salle = "M-1217-02" Then $Result_1 = Send_Data_To_TCP("TEL_02_OFF") EndIf ;UNMute les micros des mannequins MUTE_MIC_MANEQUIN(1, "UNMUTE") MUTE_MIC_MANEQUIN(2, "UNMUTE") EndIf If ($Result_1 = "ERREUR") Or ($Result_2 = "ERREUR") Or ($Result_3 = "ERREUR") Then MsgBox(4112, "ERREUR", "ERREUR: Fonction TEL non exécuté: " & $Result_1 & " " & $Result_2 & " " & $Result_3) _DebugOut("ERREUR: Fonction TEL non exécuté: " & $Result_1 & " " & $Result_2) Else MUTE_UNMUTE_VOICEMEETER() If $TEL_STATE = 0 Then $MIC_EVIER_STATE = 0 Answer_call(0) $TEL_STATE = 1 Else $TEL_STATE = 0 EndIf _DebugOut("Fonction TEL éxécuté avec succès.") ConsoleWrite("Fonction TEL éxécuté avec succès." & @CRLF) EndIf ; Raffraichit le status des pastilles de l'état des micros Show_Mic_Status($MIC_EVIER_STATE, $MIC_BUREAU_STATE, $TEL_STATE) EndFunc ;==>TEL Func MIC_BUREAU() Local $Result_1 Local $Result_2 ; On allume le micro si il est fermé sinon on le ferme If $MIC_BUREAU_STATE = 0 Then $Result_1 = SET_MIC("bureau", "ON") If $MIC_EVIER_STATE = 1 Then ;Ferme MIC EVIER $Result_2 = SET_MIC("evier", "OFF") EndIf Else $Result_1 = SET_MIC("bureau", "OFF") If $MIC_EVIER_STATE = 1 Then ;Ferme MIC EVIER $Result_2 = SET_MIC("evier", "OFF") EndIf EndIf If ($Result_1 = "ERREUR") Or ($Result_2 = "ERREUR") Then MsgBox(4112, "ERREUR", "ERREUR: Fonction MIC_BUREAU non exécuté: " & $Result_1 & " " & $Result_2) _DebugOut("ERREUR: Fonction MIC_BUREAU non exécuté: " & $Result_1 & " " & $Result_2) Else _DebugOut("Fonction MIC_BUREAU éxécuté avec succès.") ConsoleWrite("Fonction MIC_BUREAU éxécuté avec succès." & @CRLF) EndIf ; Raffraichit le status des pastilles de l'état des micros Show_Mic_Status($MIC_EVIER_STATE, $MIC_BUREAU_STATE, $TEL_STATE) EndFunc ;==>MIC_BUREAU Func MUTE_MIC_MANEQUIN($MIC_NUMBER, $MUTE) Local $Result If $salle = "M-1217-01" Then If $MUTE = "MUTE" Then ConsoleWrite("Muting salle 1 MIC: " & $MIC_NUMBER & @CRLF) $Result = Send_Data_To_TCP("MIC_01_0" & $MIC_NUMBER & "_OFF") EndIf If $MUTE = "UNMUTE" Then ConsoleWrite("Unmuting salle 1 MIC: " & $MIC_NUMBER & @CRLF) $Result = Send_Data_To_TCP("MIC_01_0" & $MIC_NUMBER & "_ON") EndIf EndIf If $salle = "M-1217-02" Then If $MUTE = "MUTE" Then ConsoleWrite("Muting salle 2 MIC: " & $MIC_NUMBER & @CRLF) $Result = Send_Data_To_TCP("MIC_02_0" & $MIC_NUMBER & "_OFF") EndIf If $MUTE = "UNMUTE" Then ConsoleWrite("Unmuting salle 2 MIC: " & $MIC_NUMBER & @CRLF) $Result = Send_Data_To_TCP("MIC_02_0" & $MIC_NUMBER & "_ON") EndIf EndIf If $Result = "ERREUR" Then MsgBox(4112, "ERREUR", "Commandes mute mic mannequin non traité!") _DebugOut("Commandes mute mic mannequin non traité!") EndIf EndFunc ;==>MUTE_MIC_MANEQUIN Func MIC_EVIER() Local $Result_1 Local $Result_2 ; On allume le micro si il est fermé sinon on le ferme If $MIC_EVIER_STATE = 0 Then $Result_1 = SET_MIC("evier", "ON") If $MIC_BUREAU_STATE = 1 Then ;Ferme MIC BUREAU $Result_2 = SET_MIC("bureau", "OFF") EndIf Else $Result_1 = SET_MIC("evier", "OFF") If $MIC_BUREAU_STATE = 1 Then ;Ferme MIC BUREAU $Result_2 = SET_MIC("bureau", "OFF") EndIf EndIf If ($Result_1 = "ERREUR") Or ($Result_2 = "ERREUR") Then MsgBox(4112, "ERREUR", "ERREUR: Fonction MIC_EVIER non exécuté: " & $Result_1 & " " & $Result_2) _DebugOut("ERREUR: Fonction MIC_EVIER non exécuté: " & $Result_1 & " " & $Result_2) Else _DebugOut("Fonction MIC_EVIER éxécuté avec succès.") ConsoleWrite("Fonction MIC_EVIER éxécuté avec succès." & @CRLF) EndIf ; Raffraichit le status des pastilles de l'état des micros Show_Mic_Status($MIC_EVIER_STATE, $MIC_BUREAU_STATE, $TEL_STATE) EndFunc ;==>MIC_EVIER ;Fonction qui change les paramètres de lecture et enregistrement de Windows Func Set_default_sound() Local $param Local $nirsoft_command Local $peripherique_lecture = IniRead($ini_file, "salle_professeur", "peripherique_lecture", "Default Value") Local $peripherique_enregistrement = IniRead($ini_file, "salle_professeur", "peripherique_enregistrement", "Default Value") Local $peripherique_lecture_niveau = IniRead($ini_file, "salle_professeur", "peripherique_lecture_niveau", "Default Value") Local $peripherique_micro_niveau = IniRead($ini_file, "salle_professeur", "peripherique_micro_niveau", "Default Value") ;Enregistrement par défaut sur le Voicemeeter qui passe par ASIO pour le mixer Behringer $param = '/SetDefault /RunAsAdmin ' & """" & $peripherique_enregistrement & """ " & '1' $nirsoft_command = @ScriptDir & "\SoundVolumeView.exe " & $param Run($nirsoft_command, "", @SW_HIDE) ;Niveau du micro $param = '/SetVolume ' & """" & $peripherique_enregistrement & """ " & $peripherique_micro_niveau $nirsoft_command = @ScriptDir & "\SoundVolumeView.exe " & $param Run($nirsoft_command, "", @SW_HIDE) ;Lecture par défaut $param = '/SetDefault /RunAsAdmin ' & """" & $peripherique_lecture & """ " & '1' $nirsoft_command = @ScriptDir & "\SoundVolumeView.exe " & $param Run($nirsoft_command, "", @SW_HIDE) ;Volume de Windows $param = '/SetVolume ' & """" & $peripherique_lecture & """ " & $peripherique_lecture_niveau $nirsoft_command = @ScriptDir & "\SoundVolumeView.exe " & $param Run($nirsoft_command, "", @SW_HIDE) ;Écouter ce périphérique microphone NON UTILISÉ ;$param = '/SetListenToThisDevice /RunAsAdmin "USB Audio CODEC\Device\Microphone" 1' ;$nirsoft_command = @ScriptDir & "\SoundVolumeView.exe " & $param ;RunAs("Administrateur", @ComputerName, "pass", $RUN_LOGON_NOPROFILE, $nirsoft_command, "", @SW_HIDE) ;Unmute le haut-parleur par défaut $param = '/Unmute ' & """" & $peripherique_lecture & """" $nirsoft_command = @ScriptDir & "\SoundVolumeView.exe " & $param Run($nirsoft_command, "", @SW_HIDE) ;Désactive les autres périphériques audio non utilisés $param = '/Disable "Conexant HD Audio\Device\Entrée ligne"' $nirsoft_command = @ScriptDir & "\SoundVolumeView.exe " & $param Run($nirsoft_command, "", @SW_HIDE) _DebugOut("Paramètres audio Windows appliqués") EndFunc ;==>Set_default_sound Func Set_led() If $System_state = 1 Then GUICtrlSetState($LED_ROUGE, $GUI_HIDE) GUICtrlSetState($LED_VERTE, $GUI_SHOW) EndIf If $System_state = 0 Then GUICtrlSetState($LED_ROUGE, $GUI_SHOW) GUICtrlSetState($LED_VERTE, $GUI_HIDE) EndIf EndFunc ;==>Set_led ;Bouton ouverture Func Button_ouvertureClick() If $System_state = 1 Then MsgBox(BitOR($MB_SYSTEMMODAL, $MB_TOPMOST), "Info", "Le système est déjà ouvert!") _DebugOut("Le système est déjà ouvert") ElseIf $System_state = 0 Then MsgBox(BitOR($MB_ICONINFORMATION, $MB_TOPMOST), "Info", "Le système prendra quelques secondes à s'ouvrir.") Send_Data_To_TCP("Turn_On") _DebugOut("Ouverture du système par " & @UserName) Sleep(7000) If Check_System_state() = True Then _DebugOut("Système allumé correctement par " & @UserName) Set_Mic_Default_State() Else _DebugOut("Système n'a pas réussi à s'alummer correctement par " & @UserName) EndIf EndIf EndFunc ;==>Button_ouvertureClick Func Button_eteindreClick() ;Si le système à été ouvert on procède If $System_state = 1 Then _DebugOut("Fermeture du système") Send_Data_To_TCP("Turn_Off") Sleep(3000) If Check_System_state() = False Then _DebugOut("Système fermé correctement par " & @UserName) Else _DebugOut("Système n'a pas réussi à se fermé correctement par " & @UserName) EndIf Else MsgBox(BitOR($MB_ICONINFORMATION, $MB_TOPMOST), "Info", "Le système n'a pas été allumé, cliquez sur ouverture.") EndIf EndFunc ;==>Button_eteindreClick Func TrayEvent() ; Show the GUI GUISetState(@SW_SHOW, $Form1) GUISetState(@SW_RESTORE, $Form1) ; Show the tray icon TraySetState(1) EndFunc ;==>TrayEvent ;Fonction qui check si tout est ouvert corectement Func Check_System_state() Local $Result $Result = Send_Data_To_TCP("CHECK_ON") If $Result = "SYSTEM_ON" Then _DebugOut("Le système est ouvert corectement.") $System_state = 1 Set_led() Return True Else _DebugOut("Le système n'est pas ouvert.") $System_state = 0 Set_led() Return False EndIf EndFunc ;==>Check_System_state ;Fonction qui remet les micros à OFF sur la matrice Func Set_Mic_Default_State() Local $Result If $salle = "M-1217-01" Then $Result = Send_Data_To_TCP("MIC_DEFAULT_01_OFF") EndIf If $salle = "M-1217-02" Then $Result = Send_Data_To_TCP("MIC_DEFAULT_02_OFF") EndIf If $Result = "MIC_OFF" Then _DebugOut("Micro fermé par défaut sur la matrice corectement.") Return True Else _DebugOut("Problème pour mettre les micros par défaut sur la matrice") Return False EndIf EndFunc ;==>Set_Mic_Default_State Func TCP_INIT() ; Start TCP Services ;============================================== Opt("TCPTimeout", 1000) ;1000 milliseconds TCPStartup() Global $ConnectedSocket Local $szIPADDRESS = "10.182.32.7" ;Local $szIPADDRESS = "127.0.0.1" Local $nPORT = "58965" ; Variable qui represente une connecxion ;============================================== $ConnectedSocket = -1 ;Connecte au serveur par IP et PORT ;======================================================= $ConnectedSocket = TCPConnect($szIPADDRESS, $nPORT) ; Si il y a une erreur on le montre If @error Then MsgBox(4112, "Erreur", "Erreur de connexion au Raspberri Pi: " & @error) _DebugOut("Erreur de connexion au Raspberri Pi: " & @error) TCPShutdown() ; Close the TCP service. Else EndIf EndFunc ;==>TCP_INIT Func Send_Data_To_TCP($szData) ;Loop Timeout au bout de 2 secondes si le raspberry ne répond pas Dim $begin = TimerInit() Local $maxtimeout = 2000 ;Si on n'est pas connecté à Asterisk indique le et n'envoie rien If $ConnectedSocket = "-1" Then MsgBox(4112, "Erreur", "Pas connecté au Raspberry Pi!") Else Local $dif Local $sReceived Local $iError = 0 ;Envoie des commandes par TCP et carriage return Local $cnt = TCPSend($ConnectedSocket, $szData) Do $dif = TimerDiff($begin) ;Loop Timeout si la matrice ne répond pas If $dif < $maxtimeout Then $sReceived = TCPRecv($ConnectedSocket, 16, 0) Else _DebugOut("Timeout pendant la réponse du rapsberry pi") ConsoleWrite("Timeout pendant la réponse du rapsberry pi") ExitLoop EndIf Until StringRegExp($sReceived, @CRLF, 0) ;On attend un retour de ligne comme réponse ; If an error occurred display the error code and return False. If @error Then $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Envoie impossible sur TCP : " & $iError) Return False Exit Else Return StringReplace($sReceived, @CRLF, "") EndIf EndIf EndFunc ;==>Send_Data_To_TCP ;Create Transparent image Func Create_trans_image($horizontal_pos, $vertical_pos, $sImage_Icon, $form_name) Local $hAttribute_Alpha Local $tColorMatrix Local $g_aDim Local $g_hGfx Local $hImagetemp Local $y Local $x Local $g_hGUI Local $g_hImage2 ;Image is 100 pixel and taskbar 40 $y = (@DesktopHeight - $vertical_pos) ;Image is 100 pixel $x = (@DesktopWidth - $horizontal_pos) $g_hGUI = GUICreate($form_name, 250, 250, $x, $y, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) _GDIPlus_Startup() $hImagetemp = _GDIPlus_ImageLoadFromFile($sImage_Icon) $hAttribute_Alpha = _GDIPlus_ImageAttributesCreate() $tColorMatrix = _GDIPlus_ColorMatrixCreateTranslate(0, 0, 0, -0.20) ;0 = opaque, -1 = transparent _GDIPlus_ImageAttributesSetColorMatrix($hAttribute_Alpha, 0, True, DllStructGetPtr($tColorMatrix)) $g_aDim = _GDIPlus_ImageGetDimension($hImagetemp) $g_hImage2 = _GDIPlus_BitmapCreateFromScan0($g_aDim[0], $g_aDim[1]) $g_hGfx = _GDIPlus_ImageGetGraphicsContext($g_hImage2) _GDIPlus_GraphicsDrawImageRectRect($g_hGfx, $hImagetemp, 0, 0, $g_aDim[0], $g_aDim[1], 0, 0, $g_aDim[0], $g_aDim[1], $hAttribute_Alpha) SetBitmap($g_hGUI, $g_hImage2, 255) Return $g_hGUI EndFunc ;==>Create_trans_image Func Show_Mic_Status($MIC_EVIER_STATE, $MIC_BUREAU_STATE, $TEL_STATE) If $MIC_EVIER_STATE = 0 And $MIC_BUREAU_STATE = 0 And $TEL_STATE = 0 Then GUISetState(@SW_SHOW, $g_hGUI_Evier_Off) GUISetState(@SW_SHOW, $g_hGUI_Bureau_Off) GUISetState(@SW_SHOW, $g_hGUI_Tel_Off) GUISetState(@SW_HIDE, $g_hGUI_Evier_On) GUISetState(@SW_HIDE, $g_hGUI_Bureau_On) GUISetState(@SW_HIDE, $g_hGUI_Tel_On) EndIf If $MIC_EVIER_STATE = 0 And $MIC_BUREAU_STATE = 0 And $TEL_STATE = 1 Then GUISetState(@SW_SHOW, $g_hGUI_Evier_Off) GUISetState(@SW_SHOW, $g_hGUI_Bureau_Off) GUISetState(@SW_SHOW, $g_hGUI_Tel_On) GUISetState(@SW_HIDE, $g_hGUI_Evier_On) GUISetState(@SW_HIDE, $g_hGUI_Bureau_On) GUISetState(@SW_HIDE, $g_hGUI_Tel_Off) EndIf If $MIC_EVIER_STATE = 0 And $MIC_BUREAU_STATE = 1 And $TEL_STATE = 1 Then GUISetState(@SW_SHOW, $g_hGUI_Evier_Off) GUISetState(@SW_SHOW, $g_hGUI_Bureau_On) GUISetState(@SW_SHOW, $g_hGUI_Tel_On) GUISetState(@SW_HIDE, $g_hGUI_Evier_On) GUISetState(@SW_HIDE, $g_hGUI_Bureau_Off) GUISetState(@SW_HIDE, $g_hGUI_Tel_Off) EndIf If $MIC_EVIER_STATE = 1 And $MIC_BUREAU_STATE = 0 And $TEL_STATE = 1 Then GUISetState(@SW_SHOW, $g_hGUI_Evier_On) GUISetState(@SW_SHOW, $g_hGUI_Bureau_Off) GUISetState(@SW_SHOW, $g_hGUI_Tel_On) GUISetState(@SW_HIDE, $g_hGUI_Evier_Off) GUISetState(@SW_HIDE, $g_hGUI_Bureau_On) GUISetState(@SW_HIDE, $g_hGUI_Tel_Off) EndIf If $MIC_EVIER_STATE = 1 And $MIC_BUREAU_STATE = 0 And $TEL_STATE = 0 Then GUISetState(@SW_SHOW, $g_hGUI_Evier_On) GUISetState(@SW_SHOW, $g_hGUI_Bureau_Off) GUISetState(@SW_SHOW, $g_hGUI_Tel_Off) GUISetState(@SW_HIDE, $g_hGUI_Evier_Off) GUISetState(@SW_HIDE, $g_hGUI_Bureau_On) GUISetState(@SW_HIDE, $g_hGUI_Tel_On) EndIf If $MIC_EVIER_STATE = 0 And $MIC_BUREAU_STATE = 1 And $TEL_STATE = 0 Then GUISetState(@SW_SHOW, $g_hGUI_Evier_Off) GUISetState(@SW_SHOW, $g_hGUI_Bureau_On) GUISetState(@SW_SHOW, $g_hGUI_Tel_Off) GUISetState(@SW_HIDE, $g_hGUI_Evier_On) GUISetState(@SW_HIDE, $g_hGUI_Bureau_Off) GUISetState(@SW_HIDE, $g_hGUI_Tel_On) EndIf If $MIC_EVIER_STATE = 1 And $MIC_BUREAU_STATE = 1 And $TEL_STATE = 1 Then GUISetState(@SW_SHOW, $g_hGUI_Evier_On) GUISetState(@SW_SHOW, $g_hGUI_Bureau_On) GUISetState(@SW_SHOW, $g_hGUI_Tel_On) GUISetState(@SW_HIDE, $g_hGUI_Evier_Off) GUISetState(@SW_HIDE, $g_hGUI_Bureau_Off) GUISetState(@SW_HIDE, $g_hGUI_Tel_Off) EndIf If $MIC_EVIER_STATE = 1 And $MIC_BUREAU_STATE = 1 And $TEL_STATE = 0 Then GUISetState(@SW_SHOW, $g_hGUI_Evier_On) GUISetState(@SW_SHOW, $g_hGUI_Bureau_On) GUISetState(@SW_SHOW, $g_hGUI_Tel_Off) GUISetState(@SW_HIDE, $g_hGUI_Evier_Off) GUISetState(@SW_HIDE, $g_hGUI_Bureau_Off) GUISetState(@SW_HIDE, $g_hGUI_Tel_On) EndIf EndFunc ;==>Show_Mic_Status Func SetBitmap($hGUI, $hImage, $iOpacity) Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend $hScrDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap) $tSize = DllStructCreate($tagSIZE) $pSize = DllStructGetPtr($tSize) DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage)) DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage)) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) $tBlend = DllStructCreate($tagBLENDFUNCTION) $pBlend = DllStructGetPtr($tBlend) DllStructSetData($tBlend, "Alpha", $iOpacity) DllStructSetData($tBlend, "Format", 1) _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA) _WinAPI_ReleaseDC(0, $hScrDC) _WinAPI_SelectObject($hMemDC, $hOld) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteDC($hMemDC) EndFunc ;==>SetBitmap Link to comment Share on other sites More sharing options...
Developers Jos Posted February 15, 2019 Developers Share Posted February 15, 2019 mmm not really as this doesn't run since you are using many extra files. The easiest thing to do in cases like this is strip the script down to the bare minimum to demonstrate the behavior you see. Could you do that? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
carloselectro Posted February 15, 2019 Author Share Posted February 15, 2019 Nevermind I got it working with this thread: https://www.autoitscript.com/forum/topic/128794-wm_command-_singleton/ Basically, it is sending a message to the other application and it is working great: I'll Here you go: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=Mic.ico #AutoIt3Wrapper_Outfile=Controle soins simulation.Exe #AutoIt3Wrapper_Outfile_x64=Controle soins simulation.Exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; Programme qui commnunique avec un raspberry pi pour modifier les paramètres audio ; du système de simulation de soins infirmer ; version 1.0 ; Auteur : Carl Fortin #include <GUIConstantsEx.au3> #include <constants.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <TrayConstants.au3> #include <Misc.au3> #include <Debug.au3> #include <GDIPlus.au3> #include <File.au3> #include <Array.au3> #include <Date.au3> #include <GDIPlus.au3> #include <GuiConstantsEx.au3> #include <WinAPI.au3> Opt("TrayAutoPause", 0) Opt("MustDeclareVars", 1) Opt("TrayMenuMode", 3) Opt("TrayOnEventMode", 1) ;##################################################### MAIN #################################################################################### Global $System_state Global $hTimer Global $salle Global $Form1 Global $LED_ROUGE Global $LED_VERTE Global $Logo Global $idAbout Global $idExit Global $Button_ouverture Global $Button_fermeture Global $Button_evier Global $Button_bureau Global $Button_tel Global $MIC_EVIER_STATE Global $MIC_BUREAU_STATE Global $TEL_STATE Global $g_hGUI_Evier_On Global $g_hGUI_Bureau_On Global $g_hGUI_Evier_Off Global $g_hGUI_Bureau_Off Global $g_hGUI_Tel_On Global $g_hGUI_Tel_Off Global Const $TITLE_GUI = 'Contrôle soins' ;Enable debugging _DebugSetup("Control soins", True, 4, @ScriptDir & "\LOG control soins.log", True) ;Une seule instance du script est permise If Not _Singleton($TITLE_GUI, 1) Then MsgBox(BitOR($MB_ICONINFORMATION, $MB_TOPMOST), "Attention", "Le programme à déjà été ouvert une fois!") _DebugOut("Le programme à déjà été ouvert une fois!") ;Réactive une fenêtre existante du programme déjà ouvert WinSetState ( $TITLE_GUI, "", @SW_RESTORE) WinActivate ( $TITLE_GUI) Exit EndIf $MIC_EVIER_STATE = 0 $MIC_BUREAU_STATE = 0 $TEL_STATE = 0 $System_state = 0 Local $sImage_Icon_Evier_On = @ScriptDir & "\MIC_EVIER_ON.png" Local $sImage_Icon_Bureau_On = @ScriptDir & "\MIC_BUREAU_ON.png" Local $sImage_Icon_Evier_Off = @ScriptDir & "\MIC_EVIER_OFF.png" Local $sImage_Icon_Bureau_Off = @ScriptDir & "\MIC_BUREAU_OFF.png" Local $sImage_Icon_Tel_Off = @ScriptDir & "\TEL_OFF.png" Local $sImage_Icon_Tel_On = @ScriptDir & "\TEL_ON.png" ;Create transparent Icon Evier ON $g_hGUI_Evier_On = Create_trans_image(305, 140, $sImage_Icon_Evier_On, "FORM_MIC_EVIER_ON") ;Create transparent Icon Bureau ON $g_hGUI_Bureau_On = Create_trans_image(205, 140, $sImage_Icon_Bureau_On, "FORM_MIC_BUREAU_ON") ;Create transparent Icon Evier OFF $g_hGUI_Evier_Off = Create_trans_image(305, 140, $sImage_Icon_Evier_Off, "FORM_MIC_EVIER_OFF") ;Create transparent Icon Bureau OFF $g_hGUI_Bureau_Off = Create_trans_image(205, 140, $sImage_Icon_Bureau_Off, "FORM_MIC_BUREAU_OFF") ;Create transparent Icon TEL ON $g_hGUI_Tel_On = Create_trans_image(105, 140, $sImage_Icon_Tel_On, "FORM_TEL_ON") ;Create transparent Icon TEL ON $g_hGUI_Tel_Off = Create_trans_image(105, 140, $sImage_Icon_Tel_Off, "FORM_TEL_OFF") _DebugOut("Démarrage du programme...") ; Lire le fichier ini qui détermine quel bureau controle les micros Local $ini_file = @ScriptDir & "\Parametre.ini" Local $sRead = IniRead($ini_file, "salle_professeur", "bureau", "Default Value") If ($sRead = "M-1217-01") Or ($sRead = "M-1217-02") Then $salle = $sRead ConsoleWrite("Controle salle " & $salle & @CRLF) Else _DebugOut("Fichier Parametre.ini introuvable ou numéro de bureau incorecte") MsgBox(4112, "Erreur", "Fichier Parametre.ini introuvable ou numéro de bureau incorecte") Exit EndIf ;Démarre Voicemeeter en mode caché avec le xml préconfigurer Start_voicemeeter() ;Changement des paramètres audio Set_default_sound() ;Create GUI Create_GUI() ;Création de la conexion TCp/IP TCP_INIT() ; Vérifie si le système est ouvert If Check_System_state() = True Then Set_Mic_Default_State() EndIf ;Définition des raccourcis claviers Local $set_hotkey_F7 = HotKeySet("{F7}", "MIC_EVIER") Local $set_hotkey_F8 = HotKeySet("{F8}", "MIC_BUREAU") Local $set_hotkey_F9 = HotKeySet("{F9}", "TEL") If $set_hotkey_F7 = 0 Then _DebugOut("Incapable d'assigner F7 comme raccourci clavier") MsgBox(4112, "Erreur", "Incapable d'assigner F7 comme raccourci clavier") EndIf If $set_hotkey_F8 = 0 Then _DebugOut("Incapable d'assigner F8 comme raccourci clavier") MsgBox(4112, "Erreur", "Incapable d'assigner F8 comme raccourci clavier") EndIf If $set_hotkey_F9 = 0 Then _DebugOut("Incapable d'assigner F9 comme raccourci clavier") MsgBox(4112, "Erreur", "Incapable d'assigner F9 comme raccourci clavier") EndIf Show_Mic_Status($MIC_EVIER_STATE, $MIC_BUREAU_STATE, $TEL_STATE) Set_MicroSIP() While 1 Switch GUIGetMsg($Form1) Case $GUI_EVENT_MINIMIZE GUISetState(@SW_HIDE, $Form1) TraySetState(1) Case $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $Form1) TraySetState(1) Case $Button_ouverture Button_ouvertureClick() Case $Button_fermeture Button_eteindreClick() Case $Button_evier MIC_EVIER() Case $Button_bureau MIC_BUREAU() Case $Button_tel TEL() EndSwitch WEnd ;##################################################### FONCTIONS #################################################################################### Func Create_GUI() Local $Formwidth = 478 Local $Formheight = 274 $Form1 = GUICreate("Contrôle soins", 478, 274, @DesktopWidth/2 - $Formwidth/2, @DesktopHeight/2 - $Formheight/2, -1, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE)) ;Texte des boutons en blanc GUICtrlSetDefColor(0xFFFFFF) ;Couleur du Background du GUI GUISetBkColor(0xFFFFFF) $Button_ouverture = GUICtrlCreateButton("Ouverture", 64, 40, 121, 65) GUICtrlSetFont(-1, 12, 400, 0, "Arial") GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetOnEvent(-1, "Button_ouvertureClick") $Button_fermeture = GUICtrlCreateButton("Fermeture", 300, 39, 121, 65) GUICtrlSetFont(-1, 12, 400, 0, "Arial") GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetOnEvent(-1, "Button_eteindreClick") Local $Group1 = GUICtrlCreateGroup("Alimentation du système audio", 40, 12, 409, 105) GUICtrlSetColor($Group1, 0x000000) Local $Group_raccourci = GUICtrlCreateGroup(" Raccourci clavier activation des micros ", 40, 120, 409, 100) $Button_evier = GUICtrlCreateButton("F7 = Évier", 190, 144, 97, 17) GUICtrlSetBkColor(-1, 0x000000) $Button_bureau = GUICtrlCreateButton("F8 = Bureau", 190, 167, 97, 17) GUICtrlSetBkColor(-1, 0x000000) $Button_tel = GUICtrlCreateButton("F9 = Tel", 190, 190, 97, 17) GUICtrlSetBkColor(-1, 0x000000) Local $Label1 = GUICtrlCreateLabel("C.F", 8, 250, 20, 17) GUICtrlSetColor($Label1, 0x000000) Local $Logo = GUICtrlCreatePic("cegep_logo_dti.jpg", 350, 220, 120, 60) ;Tray menu item $idAbout = TrayCreateItem("Information") $idExit = TrayCreateItem("Quiter") TrayItemSetOnEvent($idExit, "Quitter") TrayItemSetOnEvent($idAbout, "Information") TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "TrayEvent") ; Show the menu if the icon is right clicked TraySetClick(8) GUISetState() $LED_ROUGE = GUICtrlCreatePic(@ScriptDir & "\RED_LED.bmp", 215, 50, 57, 49) GUICtrlSetState($LED_ROUGE, $GUI_ENABLE) $LED_VERTE = GUICtrlCreatePic(@ScriptDir & "\GREEN_LED.bmp", 215, 50, 57, 49) GUICtrlSetState($LED_VERTE, $GUI_ENABLE) GUICtrlSetState($LED_VERTE, $GUI_HIDE) GUISetState(@SW_SHOW) EndFunc ;==>Create_GUI Func Start_voicemeeter() Local $param = " -h -l " & """" & @ScriptDir & "\voice_meter.xml" & """" Local $command = "C:\Program Files (x86)\VB\Voicemeeter\voicemeeterpro.exe" & $param LOcal $command_result = Run($command, "", @SW_HIDE) If $command_result = 0 Then _DebugOut("Incapable de démarrer Voicemeeter!") MsgBox(4112, "Erreur", "Incapable de démarrer Voicemeeter!") ;Exit Else _DebugOut("Voicemeeter démmaré corectement") EndIf EndFunc ;==>Start_voicemeeter Func Quitter() TCPShutdown() _DebugOut("Fermeture de l'application via le system tray") Exit EndFunc ;==>Quitter Func Information() ;Au sujet de l'application MsgBox(BitOR($MB_TOPMOST, $MB_ICONQUESTION), "Aide", @ScriptName & @CRLF & "Fait par Carl Fortin" & @CRLF & "Version: 1.0") EndFunc ;==>Information ;Répond avec Microsip automatiquement après un délais Func Answer_call($sleep_before_answer) Local $hWnd ;Répond seulement si aucun appel est actif If Check_Active_call() = False Then $hWnd = WinWait("Appel entrant", "", 1) ;Si la fenetre n'a pas été trouvé au bout de x temps If $hWnd = 0 Then _DebugOut("Appel entrant introuvable") ; MsgBox($MB_SYSTEMMODAL, "", "Appel entrant introuvable") Else WinActivate($hWnd, "") Sleep($sleep_before_answer) ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:1]") EndIf EndIf EndFunc ;==>Answer_call ;Place la fenêtre de MicroSIP à la bonne position et la bonne taille Func Set_MicroSIP() Local $hWnd = WinWait("[CLASS:MicroSIP]", "", 1) WinSetState ( $hWnd, "", @SW_RESTORE) WinMove($hWnd, "",0,460,259,518) EndFunc Func Check_Active_call() If WinExists("[CLASS:MicroSIP]", "Connecté") Then ;MsgBox($MB_SYSTEMMODAL, "", "Appel en cours...") Return True Else ;MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Erreur", "Aucun appel en cour") Return False EndIf EndFunc ;==>Check_Active_call Func MUTE_UNMUTE_VOICEMEETER() ;Toggle Mute Send("^{F10}") ConsoleWrite("Toggle input mute voicemeeter") EndFunc ;==>MUTE_UNMUTE_VOICEMEETER Func SET_MIC($type, $state) Local $Result If $salle = "M-1217-01" Then If $type = "bureau" Then $Result = Send_Data_To_TCP("MIC_BUREAU_01_" & $state) EndIf If $type = "evier" Then $Result = Send_Data_To_TCP("MIC_EVIER_01_" & $state) EndIf EndIf If $salle = "M-1217-02" Then If $type = "bureau" Then $Result = Send_Data_To_TCP("MIC_BUREAU_02_" & $state) EndIf If $type = "evier" Then $Result = Send_Data_To_TCP("MIC_EVIER_02_" & $state) EndIf EndIf If $Result = "ERREUR" Then MsgBox(4112, "ERREUR", "Incapable de controler le micro de la matrice") _DebugOut("Incapable de controler le micro de la matrice") Return "ERREUR" ; La réponse est OK on passe à l'action Else ; Si le téléphone était activé on démute voice If $TEL_STATE = 1 Then $TEL_STATE = 0 ;Unmute tel MUTE_UNMUTE_VOICEMEETER() EndIf If $type = "bureau" Then If $state = "ON" Then $MIC_BUREAU_STATE = 1 MUTE_MIC_MANEQUIN(1, "MUTE") MUTE_MIC_MANEQUIN(2, "MUTE") Else $MIC_BUREAU_STATE = 0 ; Unmute seulement si on n'a pas activé le micro de l'évier If $MIC_EVIER_STATE = 0 Then MUTE_MIC_MANEQUIN(1, "UNMUTE") MUTE_MIC_MANEQUIN(2, "UNMUTE") EndIf EndIf EndIf If $type = "evier" Then If $state = "ON" Then $MIC_EVIER_STATE = 1 MUTE_MIC_MANEQUIN(1, "MUTE") MUTE_MIC_MANEQUIN(2, "MUTE") Else $MIC_EVIER_STATE = 0 ; Unmute seulement si on n'a pas activé le micro du bureau If $MIC_BUREAU_STATE = 0 Then MUTE_MIC_MANEQUIN(1, "UNMUTE") MUTE_MIC_MANEQUIN(2, "UNMUTE") EndIf EndIf EndIf Return "OK" EndIf EndFunc ;==>SET_MIC ;Mute et unmute l'input 1 de Voicemeeter en envoyant le raccourci clavier (CTRL+F10) afin de ne plus entendre les micros des salles lorsqu'on est au téléphone Func TEL() Local $Result_1 Local $Result_2 Local $Result_3 If $TEL_STATE = 0 Then If $salle = "M-1217-01" Then $Result_1 = Send_Data_To_TCP("TEL_01_ON") EndIf If $salle = "M-1217-02" Then $Result_1 = Send_Data_To_TCP("TEL_02_ON") EndIf If $MIC_BUREAU_STATE = 1 Then ;La sortie 2 de la matrice est changé pour l'entrée du téléphone par la commande TEL_01_ON $MIC_BUREAU_STATE = 0 EndIf If $MIC_EVIER_STATE = 1 Then If $salle = "M-1217-01" Then $Result_3 = Send_Data_To_TCP("MIC_EVIER_01_OFF") EndIf If $salle = "M-1217-02" Then $Result_3 = Send_Data_To_TCP("MIC_EVIER_02_OFF") EndIf EndIf ;Mute les micros des mannequins MUTE_MIC_MANEQUIN(1, "MUTE") MUTE_MIC_MANEQUIN(2, "MUTE") Else If $salle = "M-1217-01" Then $Result_1 = Send_Data_To_TCP("TEL_01_OFF") EndIf If $salle = "M-1217-02" Then $Result_1 = Send_Data_To_TCP("TEL_02_OFF") EndIf ;UNMute les micros des mannequins MUTE_MIC_MANEQUIN(1, "UNMUTE") MUTE_MIC_MANEQUIN(2, "UNMUTE") EndIf If ($Result_1 = "ERREUR") Or ($Result_2 = "ERREUR") Or ($Result_3 = "ERREUR") Then MsgBox(4112, "ERREUR", "ERREUR: Fonction TEL non exécuté: " & $Result_1 & " " & $Result_2 & " " & $Result_3) _DebugOut("ERREUR: Fonction TEL non exécuté: " & $Result_1 & " " & $Result_2) Else MUTE_UNMUTE_VOICEMEETER() If $TEL_STATE = 0 Then $MIC_EVIER_STATE = 0 Answer_call(0) $TEL_STATE = 1 Else $TEL_STATE = 0 EndIf _DebugOut("Fonction TEL éxécuté avec succès.") ConsoleWrite("Fonction TEL éxécuté avec succès." & @CRLF) EndIf ; Raffraichit le status des pastilles de l'état des micros Show_Mic_Status($MIC_EVIER_STATE, $MIC_BUREAU_STATE, $TEL_STATE) EndFunc ;==>TEL Func MIC_BUREAU() Local $Result_1 Local $Result_2 ; On allume le micro si il est fermé sinon on le ferme If $MIC_BUREAU_STATE = 0 Then $Result_1 = SET_MIC("bureau", "ON") If $MIC_EVIER_STATE = 1 Then ;Ferme MIC EVIER $Result_2 = SET_MIC("evier", "OFF") EndIf Else $Result_1 = SET_MIC("bureau", "OFF") If $MIC_EVIER_STATE = 1 Then ;Ferme MIC EVIER $Result_2 = SET_MIC("evier", "OFF") EndIf EndIf If ($Result_1 = "ERREUR") Or ($Result_2 = "ERREUR") Then MsgBox(4112, "ERREUR", "ERREUR: Fonction MIC_BUREAU non exécuté: " & $Result_1 & " " & $Result_2) _DebugOut("ERREUR: Fonction MIC_BUREAU non exécuté: " & $Result_1 & " " & $Result_2) Else _DebugOut("Fonction MIC_BUREAU éxécuté avec succès.") ConsoleWrite("Fonction MIC_BUREAU éxécuté avec succès." & @CRLF) EndIf ; Raffraichit le status des pastilles de l'état des micros Show_Mic_Status($MIC_EVIER_STATE, $MIC_BUREAU_STATE, $TEL_STATE) EndFunc ;==>MIC_BUREAU Func MUTE_MIC_MANEQUIN($MIC_NUMBER, $MUTE) Local $Result If $salle = "M-1217-01" Then If $MUTE = "MUTE" Then ConsoleWrite("Muting salle 1 MIC: " & $MIC_NUMBER & @CRLF) $Result = Send_Data_To_TCP("MIC_01_0" & $MIC_NUMBER & "_OFF") EndIf If $MUTE = "UNMUTE" Then ConsoleWrite("Unmuting salle 1 MIC: " & $MIC_NUMBER & @CRLF) $Result = Send_Data_To_TCP("MIC_01_0" & $MIC_NUMBER & "_ON") EndIf EndIf If $salle = "M-1217-02" Then If $MUTE = "MUTE" Then ConsoleWrite("Muting salle 2 MIC: " & $MIC_NUMBER & @CRLF) $Result = Send_Data_To_TCP("MIC_02_0" & $MIC_NUMBER & "_OFF") EndIf If $MUTE = "UNMUTE" Then ConsoleWrite("Unmuting salle 2 MIC: " & $MIC_NUMBER & @CRLF) $Result = Send_Data_To_TCP("MIC_02_0" & $MIC_NUMBER & "_ON") EndIf EndIf If $Result = "ERREUR" Then MsgBox(4112, "ERREUR", "Commandes mute mic mannequin non traité!") _DebugOut("Commandes mute mic mannequin non traité!") EndIf EndFunc ;==>MUTE_MIC_MANEQUIN Func MIC_EVIER() Local $Result_1 Local $Result_2 ; On allume le micro si il est fermé sinon on le ferme If $MIC_EVIER_STATE = 0 Then $Result_1 = SET_MIC("evier", "ON") If $MIC_BUREAU_STATE = 1 Then ;Ferme MIC BUREAU $Result_2 = SET_MIC("bureau", "OFF") EndIf Else $Result_1 = SET_MIC("evier", "OFF") If $MIC_BUREAU_STATE = 1 Then ;Ferme MIC BUREAU $Result_2 = SET_MIC("bureau", "OFF") EndIf EndIf If ($Result_1 = "ERREUR") Or ($Result_2 = "ERREUR") Then MsgBox(4112, "ERREUR", "ERREUR: Fonction MIC_EVIER non exécuté: " & $Result_1 & " " & $Result_2) _DebugOut("ERREUR: Fonction MIC_EVIER non exécuté: " & $Result_1 & " " & $Result_2) Else _DebugOut("Fonction MIC_EVIER éxécuté avec succès.") ConsoleWrite("Fonction MIC_EVIER éxécuté avec succès." & @CRLF) EndIf ; Raffraichit le status des pastilles de l'état des micros Show_Mic_Status($MIC_EVIER_STATE, $MIC_BUREAU_STATE, $TEL_STATE) EndFunc ;==>MIC_EVIER ;Fonction qui change les paramètres de lecture et enregistrement de Windows Func Set_default_sound() Local $param Local $nirsoft_command Local $peripherique_lecture = IniRead($ini_file, "salle_professeur", "peripherique_lecture", "Default Value") Local $peripherique_enregistrement = IniRead($ini_file, "salle_professeur", "peripherique_enregistrement", "Default Value") Local $peripherique_lecture_niveau = IniRead($ini_file, "salle_professeur", "peripherique_lecture_niveau", "Default Value") Local $peripherique_micro_niveau = IniRead($ini_file, "salle_professeur", "peripherique_micro_niveau", "Default Value") ;Enregistrement par défaut sur le Voicemeeter qui passe par ASIO pour le mixer Behringer $param = '/SetDefault /RunAsAdmin ' & """" & $peripherique_enregistrement & """ " & '1' $nirsoft_command = @ScriptDir & "\SoundVolumeView.exe " & $param Run($nirsoft_command, "", @SW_HIDE) ;Niveau du micro $param = '/SetVolume ' & """" & $peripherique_enregistrement & """ " & $peripherique_micro_niveau $nirsoft_command = @ScriptDir & "\SoundVolumeView.exe " & $param Run($nirsoft_command, "", @SW_HIDE) ;Lecture par défaut $param = '/SetDefault /RunAsAdmin ' & """" & $peripherique_lecture & """ " & '1' $nirsoft_command = @ScriptDir & "\SoundVolumeView.exe " & $param Run($nirsoft_command, "", @SW_HIDE) ;Volume de Windows $param = '/SetVolume ' & """" & $peripherique_lecture & """ " & $peripherique_lecture_niveau $nirsoft_command = @ScriptDir & "\SoundVolumeView.exe " & $param Run($nirsoft_command, "", @SW_HIDE) ;Écouter ce périphérique microphone NON UTILISÉ ;$param = '/SetListenToThisDevice /RunAsAdmin "USB Audio CODEC\Device\Microphone" 1' ;$nirsoft_command = @ScriptDir & "\SoundVolumeView.exe " & $param ;RunAs("Administrateur", @ComputerName, "pass", $RUN_LOGON_NOPROFILE, $nirsoft_command, "", @SW_HIDE) ;Unmute le haut-parleur par défaut $param = '/Unmute ' & """" & $peripherique_lecture & """" $nirsoft_command = @ScriptDir & "\SoundVolumeView.exe " & $param Run($nirsoft_command, "", @SW_HIDE) ;Désactive les autres périphériques audio non utilisés $param = '/Disable "Conexant HD Audio\Device\Entrée ligne"' $nirsoft_command = @ScriptDir & "\SoundVolumeView.exe " & $param Run($nirsoft_command, "", @SW_HIDE) _DebugOut("Paramètres audio Windows appliqués") EndFunc ;==>Set_default_sound Func Set_led() If $System_state = 1 Then GUICtrlSetState($LED_ROUGE, $GUI_HIDE) GUICtrlSetState($LED_VERTE, $GUI_SHOW) EndIf If $System_state = 0 Then GUICtrlSetState($LED_ROUGE, $GUI_SHOW) GUICtrlSetState($LED_VERTE, $GUI_HIDE) EndIf EndFunc ;==>Set_led ;Bouton ouverture Func Button_ouvertureClick() If $System_state = 1 Then MsgBox(BitOR($MB_SYSTEMMODAL, $MB_TOPMOST), "Info", "Le système est déjà ouvert!") _DebugOut("Le système est déjà ouvert") ElseIf $System_state = 0 Then MsgBox(BitOR($MB_ICONINFORMATION, $MB_TOPMOST), "Info", "Le système prendra quelques secondes à s'ouvrir.") Send_Data_To_TCP("Turn_On") _DebugOut("Ouverture du système par " & @UserName) Sleep(7000) If Check_System_state() = True Then _DebugOut("Système allumé correctement par " & @UserName) Set_Mic_Default_State() Else _DebugOut("Système n'a pas réussi à s'alummer correctement par " & @UserName) EndIf EndIf EndFunc ;==>Button_ouvertureClick Func Button_eteindreClick() ;Si le système à été ouvert on procède If $System_state = 1 Then _DebugOut("Fermeture du système") Send_Data_To_TCP("Turn_Off") Sleep(3000) If Check_System_state() = False Then _DebugOut("Système fermé correctement par " & @UserName) Else _DebugOut("Système n'a pas réussi à se fermé correctement par " & @UserName) EndIf Else MsgBox(BitOR($MB_ICONINFORMATION, $MB_TOPMOST), "Info", "Le système n'a pas été allumé, cliquez sur ouverture.") EndIf EndFunc ;==>Button_eteindreClick Func TrayEvent() ; Show the GUI GUISetState(@SW_SHOW, $Form1) GUISetState(@SW_RESTORE, $Form1) ; Show the tray icon TraySetState(1) EndFunc ;==>TrayEvent ;Fonction qui check si tout est ouvert corectement Func Check_System_state() Local $Result $Result = Send_Data_To_TCP("CHECK_ON") If $Result = "SYSTEM_ON" Then _DebugOut("Le système est ouvert corectement.") $System_state = 1 Set_led() Return True Else _DebugOut("Le système n'est pas ouvert.") $System_state = 0 Set_led() Return False EndIf EndFunc ;==>Check_System_state ;Fonction qui remet les micros à OFF sur la matrice Func Set_Mic_Default_State() Local $Result If $salle = "M-1217-01" Then $Result = Send_Data_To_TCP("MIC_DEFAULT_01_OFF") EndIf If $salle = "M-1217-02" Then $Result = Send_Data_To_TCP("MIC_DEFAULT_02_OFF") EndIf If $Result = "MIC_OFF" Then _DebugOut("Micro fermé par défaut sur la matrice corectement.") Return True Else _DebugOut("Problème pour mettre les micros par défaut sur la matrice") Return False EndIf EndFunc ;==>Set_Mic_Default_State Func TCP_INIT() ; Start TCP Services ;============================================== Opt("TCPTimeout", 1000) ;1000 milliseconds TCPStartup() Global $ConnectedSocket Local $szIPADDRESS = "10.182.32.7" ;Local $szIPADDRESS = "127.0.0.1" Local $nPORT = "58965" ; Variable qui represente une connecxion ;============================================== $ConnectedSocket = -1 ;Connecte au serveur par IP et PORT ;======================================================= $ConnectedSocket = TCPConnect($szIPADDRESS, $nPORT) ; Si il y a une erreur on le montre If @error Then MsgBox(4112, "Erreur", "Erreur de connexion au Raspberri Pi: " & @error) _DebugOut("Erreur de connexion au Raspberri Pi: " & @error) TCPShutdown() ; Close the TCP service. Else EndIf EndFunc ;==>TCP_INIT Func Send_Data_To_TCP($szData) ;Loop Timeout au bout de 2 secondes si le raspberry ne répond pas Dim $begin = TimerInit() Local $maxtimeout = 2000 ;Si on n'est pas connecté à Asterisk indique le et n'envoie rien If $ConnectedSocket = "-1" Then MsgBox(4112, "Erreur", "Pas connecté au Raspberry Pi!") Else Local $dif Local $sReceived Local $iError = 0 ;Envoie des commandes par TCP et carriage return Local $cnt = TCPSend($ConnectedSocket, $szData) Do $dif = TimerDiff($begin) ;Loop Timeout si la matrice ne répond pas If $dif < $maxtimeout Then $sReceived = TCPRecv($ConnectedSocket, 16, 0) Else _DebugOut("Timeout pendant la réponse du rapsberry pi") ConsoleWrite("Timeout pendant la réponse du rapsberry pi") ExitLoop EndIf Until StringRegExp($sReceived, @CRLF, 0) ;On attend un retour de ligne comme réponse ; If an error occurred display the error code and return False. If @error Then $iError = @error MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Client:" & @CRLF & "Envoie impossible sur TCP : " & $iError) Return False Exit Else Return StringReplace($sReceived, @CRLF, "") EndIf EndIf EndFunc ;==>Send_Data_To_TCP ;Create Transparent image Func Create_trans_image($horizontal_pos, $vertical_pos, $sImage_Icon, $form_name) Local $hAttribute_Alpha Local $tColorMatrix Local $g_aDim Local $g_hGfx Local $hImagetemp Local $y Local $x Local $g_hGUI Local $g_hImage2 ;Image is 100 pixel and taskbar 40 $y = (@DesktopHeight - $vertical_pos) ;Image is 100 pixel $x = (@DesktopWidth - $horizontal_pos) $g_hGUI = GUICreate($form_name, 250, 250, $x, $y, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) _GDIPlus_Startup() $hImagetemp = _GDIPlus_ImageLoadFromFile($sImage_Icon) $hAttribute_Alpha = _GDIPlus_ImageAttributesCreate() $tColorMatrix = _GDIPlus_ColorMatrixCreateTranslate(0, 0, 0, -0.20) ;0 = opaque, -1 = transparent _GDIPlus_ImageAttributesSetColorMatrix($hAttribute_Alpha, 0, True, DllStructGetPtr($tColorMatrix)) $g_aDim = _GDIPlus_ImageGetDimension($hImagetemp) $g_hImage2 = _GDIPlus_BitmapCreateFromScan0($g_aDim[0], $g_aDim[1]) $g_hGfx = _GDIPlus_ImageGetGraphicsContext($g_hImage2) _GDIPlus_GraphicsDrawImageRectRect($g_hGfx, $hImagetemp, 0, 0, $g_aDim[0], $g_aDim[1], 0, 0, $g_aDim[0], $g_aDim[1], $hAttribute_Alpha) SetBitmap($g_hGUI, $g_hImage2, 255) Return $g_hGUI EndFunc ;==>Create_trans_image Func Show_Mic_Status($MIC_EVIER_STATE, $MIC_BUREAU_STATE, $TEL_STATE) If $MIC_EVIER_STATE = 0 And $MIC_BUREAU_STATE = 0 And $TEL_STATE = 0 Then GUISetState(@SW_SHOW, $g_hGUI_Evier_Off) GUISetState(@SW_SHOW, $g_hGUI_Bureau_Off) GUISetState(@SW_SHOW, $g_hGUI_Tel_Off) GUISetState(@SW_HIDE, $g_hGUI_Evier_On) GUISetState(@SW_HIDE, $g_hGUI_Bureau_On) GUISetState(@SW_HIDE, $g_hGUI_Tel_On) EndIf If $MIC_EVIER_STATE = 0 And $MIC_BUREAU_STATE = 0 And $TEL_STATE = 1 Then GUISetState(@SW_SHOW, $g_hGUI_Evier_Off) GUISetState(@SW_SHOW, $g_hGUI_Bureau_Off) GUISetState(@SW_SHOW, $g_hGUI_Tel_On) GUISetState(@SW_HIDE, $g_hGUI_Evier_On) GUISetState(@SW_HIDE, $g_hGUI_Bureau_On) GUISetState(@SW_HIDE, $g_hGUI_Tel_Off) EndIf If $MIC_EVIER_STATE = 0 And $MIC_BUREAU_STATE = 1 And $TEL_STATE = 1 Then GUISetState(@SW_SHOW, $g_hGUI_Evier_Off) GUISetState(@SW_SHOW, $g_hGUI_Bureau_On) GUISetState(@SW_SHOW, $g_hGUI_Tel_On) GUISetState(@SW_HIDE, $g_hGUI_Evier_On) GUISetState(@SW_HIDE, $g_hGUI_Bureau_Off) GUISetState(@SW_HIDE, $g_hGUI_Tel_Off) EndIf If $MIC_EVIER_STATE = 1 And $MIC_BUREAU_STATE = 0 And $TEL_STATE = 1 Then GUISetState(@SW_SHOW, $g_hGUI_Evier_On) GUISetState(@SW_SHOW, $g_hGUI_Bureau_Off) GUISetState(@SW_SHOW, $g_hGUI_Tel_On) GUISetState(@SW_HIDE, $g_hGUI_Evier_Off) GUISetState(@SW_HIDE, $g_hGUI_Bureau_On) GUISetState(@SW_HIDE, $g_hGUI_Tel_Off) EndIf If $MIC_EVIER_STATE = 1 And $MIC_BUREAU_STATE = 0 And $TEL_STATE = 0 Then GUISetState(@SW_SHOW, $g_hGUI_Evier_On) GUISetState(@SW_SHOW, $g_hGUI_Bureau_Off) GUISetState(@SW_SHOW, $g_hGUI_Tel_Off) GUISetState(@SW_HIDE, $g_hGUI_Evier_Off) GUISetState(@SW_HIDE, $g_hGUI_Bureau_On) GUISetState(@SW_HIDE, $g_hGUI_Tel_On) EndIf If $MIC_EVIER_STATE = 0 And $MIC_BUREAU_STATE = 1 And $TEL_STATE = 0 Then GUISetState(@SW_SHOW, $g_hGUI_Evier_Off) GUISetState(@SW_SHOW, $g_hGUI_Bureau_On) GUISetState(@SW_SHOW, $g_hGUI_Tel_Off) GUISetState(@SW_HIDE, $g_hGUI_Evier_On) GUISetState(@SW_HIDE, $g_hGUI_Bureau_Off) GUISetState(@SW_HIDE, $g_hGUI_Tel_On) EndIf If $MIC_EVIER_STATE = 1 And $MIC_BUREAU_STATE = 1 And $TEL_STATE = 1 Then GUISetState(@SW_SHOW, $g_hGUI_Evier_On) GUISetState(@SW_SHOW, $g_hGUI_Bureau_On) GUISetState(@SW_SHOW, $g_hGUI_Tel_On) GUISetState(@SW_HIDE, $g_hGUI_Evier_Off) GUISetState(@SW_HIDE, $g_hGUI_Bureau_Off) GUISetState(@SW_HIDE, $g_hGUI_Tel_Off) EndIf If $MIC_EVIER_STATE = 1 And $MIC_BUREAU_STATE = 1 And $TEL_STATE = 0 Then GUISetState(@SW_SHOW, $g_hGUI_Evier_On) GUISetState(@SW_SHOW, $g_hGUI_Bureau_On) GUISetState(@SW_SHOW, $g_hGUI_Tel_Off) GUISetState(@SW_HIDE, $g_hGUI_Evier_Off) GUISetState(@SW_HIDE, $g_hGUI_Bureau_Off) GUISetState(@SW_HIDE, $g_hGUI_Tel_On) EndIf EndFunc ;==>Show_Mic_Status Func SetBitmap($hGUI, $hImage, $iOpacity) Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend $hScrDC = _WinAPI_GetDC(0) $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap) $tSize = DllStructCreate($tagSIZE) $pSize = DllStructGetPtr($tSize) DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage)) DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage)) $tSource = DllStructCreate($tagPOINT) $pSource = DllStructGetPtr($tSource) $tBlend = DllStructCreate($tagBLENDFUNCTION) $pBlend = DllStructGetPtr($tBlend) DllStructSetData($tBlend, "Alpha", $iOpacity) DllStructSetData($tBlend, "Format", 1) _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA) _WinAPI_ReleaseDC(0, $hScrDC) _WinAPI_SelectObject($hMemDC, $hOld) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteDC($hMemDC) EndFunc ;==>SetBitmap Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now