Dialogues entres applications

Description

DIALOGUES ENTRES APPLICATIONS (PAR LA BASE DE REGISTRE)

plusieurs applic... pourront se parler et se repondre
savoir si une autre applic... nommee est executee

elles se reconnaissent par leurs noms d executable ou fichier vbp

l applic.... sais qui l'appelle

je donnerai des infos sur la fonction BLOCK() si besoin

executer les deux projets ils sont identiques
mais projet1 dit bonjour
---- projet2 lui repond merci et le nomme
.....

Source / Exemple :


'projet1------------------------------------------

''form1--------------------------------*
Private Sub Form_Load()
Form1.Caption = App.EXEName ' aff le nom de son application

'If dialog_test("projet2") Then End '  falcutatif : ne demarre que si le projet2 est lance

Call dialog_init(Form1)  ' initialise le dialoge entre applications [ Form1 pour informer ou est Public Sub dialog_recu() ]
Timer1.Interval = 100    ' le timer qui surveil

Call dialog_env("projet2", "bonjour") '  envois bonjours a l apllication projet2

End Sub

'=============pour gerer les dialogues recus=====================
Public Sub dialog_recu(appelant, message)
  List1.AddItem appelant & "   " & message ' falcutatif
  
If message = "bonjour" Then Call dialog_env(appelant, "merci " & appelant) ' si bonjour repond par un message a appelant
' ect.....
' ect.....
DoEvents
End Sub
                                                           
Private Sub Form_Terminate()
Timer1.Interval = 0 ' stop le timer qui surveil
Call dialog_fin     ' stop le dialog : informe de son inactivite
' et efface les traces de messages (si derniere application)
End Sub

Private Sub Timer1_Timer()
Call dialog_surveil
End Sub

''module--------------------------*
Public Cible As Form

Public Sub dialog_surveil()
a = block(App.EXEName, 4)
End Sub

Public Sub dialog_env(app_cible, dial)
SaveSetting "dialog connect", app_cible, App.EXEName, dial
End Sub

Public Sub dialog_fin()
SaveSetting "dialog connect", "inscris", App.EXEName, "inactif"
a = block("inscris", 1)
End Sub

Public Sub dialog_init(cible1 As Form)
SaveSetting "dialog connect", "inscris", App.EXEName, "actif"
Set Cible = cible1
End Sub

Public Function dialog_test(a5)
dialog_test = GetSetting("dialog connect", "inscris", a5) = "inactif"
End Function
''bon courage......
Public Function block(a2 As String, a3 As Integer) As Variant

Dim avnt As Variant
Dim bntX As Integer
Dim app_ins As String
Dim app_dial As String

If a3 = 0 Then Exit Function

     block = "0": avnt = GetAllSettings("dialog connect", a2)
     If VarType(avnt) <> 0 Then
     For bntX = 0 To UBound(avnt, 1)
     app_ins = avnt(bntX, 0)
     app_dial = avnt(bntX, 1)
     
     If a3 = 1 And app_dial = "actif" Then block = "1"
     If a3 = 2 Then a = block(app_ins, 3)
     If a3 = 3 Then DeleteSetting "dialog connect", a2, app_ins
     If a3 = 4 Then Call Cible.dialog_recu(app_ins, app_dial)
     
     Next bntX
     If a3 = 4 Then DeleteSetting "dialog connect", App.EXEName
     End If
     If a3 = 1 And block = "0" Then
     a = block("inscris", 2)
     End If
     DoEvents
End Function

'projet2------------------------------------------

' il vous faut form list timer
''form1--------------------------------*

Private Sub Form_Load()
Form1.Caption = App.EXEName ' aff le nom de son application

'If dialog_test("projet2") Then End '  falcutatif : ne demarre que si le projet2 est lance

Call dialog_init(Form1)  ' initialise le dialoge entre applications [ Form1 pour informer ou est Public Sub dialog_recu() ]
Timer1.Interval = 100    ' le timer qui surveil

''Call dialog_env("projet2", "bonjour") '  envois bonjours a l apllication projet2

End Sub

'=====================pour gerer les dialogues recus=====================
Public Sub dialog_recu(appelant, message)
  List1.AddItem appelant & "   " & message ' falcutatif
  
If message = "bonjour" Then Call dialog_env(appelant, "merci " & appelant) ' si bonjour repond par un message a appelant
' ect.....
' ect.....
DoEvents
End Sub
                                                           
Private Sub Form_Terminate()
Timer1.Interval = 0 ' stop le timer qui surveil
Call dialog_fin     ' stop le dialog : informe de son inactivite
' et efface les traces de messages (si derniere application)
End Sub

Private Sub Timer1_Timer()
Call dialog_surveil
End Sub

''module--------------------------*

'''le meme que projet1

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.