Probleme avec le TIMER de VB6

Résolu
Seth77 Messages postés 572 Date d'inscription mardi 30 avril 2002 Statut Membre Dernière intervention 4 mai 2020 - 1 sept. 2005 à 17:12
Seth77 Messages postés 572 Date d'inscription mardi 30 avril 2002 Statut Membre Dernière intervention 4 mai 2020 - 1 sept. 2005 à 20:58
Slu



j utilise un timer pour mon App, et egalement un menu Popup que j affiche avec le clic droit sur l icone dans le Systray.

Que le timer soit actif ou pas si la fonction Private Sub Timer_Timer()
est presente dans le code le menu poptray ne s affiche pas lors du
premier clic mais lors de deuxieme !



est ce que qqn sait d ou cela vient et si il y a une soluce ?



thx

Herve

11 réponses

PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
1 sept. 2005 à 20:53
salut,
oui, en effet, mais c'est bien la preuve qu'il n'y a aucun rapport avec le timer ;)

le problème se situe au niveau du focus. la première fois que tu click, le systray prend le focus, donc la form le perd, et c'est tout. et seulement ensuite, le click est efficace.

il faut ajouter un SetForeGround lors de chaque click

module :
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long

form :

'(...)
Case WM_RBUTTONDOWN 'Me.Caption = "Right Click"
Call SetForegroundWindow(Me.hWnd)
PopupMenu MNUazerty
'(...)

PCPT
3
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
1 sept. 2005 à 17:51
salut......
un peu trop peu d'explications pour pouvoir donner suite (non?)
PCPT
0
Seth77 Messages postés 572 Date d'inscription mardi 30 avril 2002 Statut Membre Dernière intervention 4 mai 2020 1
1 sept. 2005 à 17:54
ben je ne crois pas ...

des que la fonction Timer_Timer() est dans le code (sans pour
autant faire qqchose il faut que je clic 2X pour faire apparaitre le
menu

Herve
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
1 sept. 2005 à 17:58
le problème vient donc forcément de ce qu'elle contient, et non juste sa déclaration vierge.....
PCPT
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Seth77 Messages postés 572 Date d'inscription mardi 30 avril 2002 Statut Membre Dernière intervention 4 mai 2020 1
1 sept. 2005 à 18:03
j ai essaye de mettre sans code et cela fait le meme bug, juste la declaration




Herve
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
1 sept. 2005 à 18:09
donc t'a juste un timer enabled=true, sans instruction (puisque pareil), et un évènement systray genre

private sub Systray_Click()
popupmenu PopTray
end sub

c'est bien çà? aucun booléen qui vient géner, ou quoi que ce soit?
pas un "me" ou "systray" show ou hide qui vient interférer?

PCPT
0
Seth77 Messages postés 572 Date d'inscription mardi 30 avril 2002 Statut Membre Dernière intervention 4 mai 2020 1
1 sept. 2005 à 18:33
voici le code :



Private Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As Long



'Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

' If (KeyCode = 27) Then

' If (STATION_LOCK = True) Then

' StationLock False

' Else

' StationLock True

' End If

' End If

'

' If (KeyCode >= vbKeyA And KeyCode <= vbKeyZ) Then

' LB_Password.Caption = LB_Password.Caption & Chr(KeyCode)

' End If

'

' If (KeyCode >= vbKey0 And KeyCode <= vbKey9) Then

' LB_Password.Caption = LB_Password.Caption & Chr(KeyCode)

' End If

'End Sub



Private Sub Form_Load()

MNU.Visible = False



'ToujoursVisible FRM_Main, True



' Tray Icone

Tic.cbSize = Len(Tic)

Tic.hwnd = PB_Ico.hwnd

Tic.uID = H1&

Tic.uFlags = NIF_DOALL

Tic.uCallbackMessage = WM_MOUSEMOVE

Tic.hIcon = PB_Ico.Picture

erg = Shell_NotifyIcon(NIM_ADD, Tic)



' CheckKey

'

' LB_Password.Caption = ""

' StationLock False

End Sub



Private Sub CMD_LOCK_Click()

LB_Password.Caption = ""

End Sub



Private Sub Form_Unload(Cancel As Integer)

If (STATION_LOCK = True) Then

Cancel = 1

Else

erg = Shell_NotifyIcon(NIM_DELETE, Tic)

End If

End Sub



Private Sub MNU_QUITTER_Click()

Unload Me

End Sub



Private Sub PB_Ico_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

X = X / Screen.TwipsPerPixelX



If (STATION_LOCK = True) Then Exit Sub



Select Case X

Case WM_LBUTTONDOWN 'Me.Caption = "Left Click"



Case WM_RBUTTONDOWN 'Me.Caption = "Right Click"

PopupMenu MNU

Case WM_MOUSEMOVE 'Me.Caption = "Move"




Case WM_LBUTTONDBLCLK 'Me.Caption = "Double Click"



End Select

End Sub



Private Sub Timer_Timer()

' If (STATION_LOCK = True) Then

' SetCursorPos 10000, 10000

' FRM_Main.SetFocus

' End If

End Sub



Private Sub StationLock(Val As Boolean)

STATION_LOCK = Val

FRM_Main.Caption = Val



Timer.Enabled = Val

End Sub

Herve
0
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
1 sept. 2005 à 19:48
vouaip, mais comme il manque le code pour le systray.....
PCPT
0
Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
1 sept. 2005 à 19:57
évite d'appeler ta donnée Val c'est un mot réservé



j'ai aussi un Timer avec le systray et aucun problème.

Daniel
0
Seth77 Messages postés 572 Date d'inscription mardi 30 avril 2002 Statut Membre Dernière intervention 4 mai 2020 1
1 sept. 2005 à 20:29
J ai essaye dans un nouveau projet :



dans une FRM :



Private Sub Form_Load()

Dim erg

Tic.cbSize = Len(Tic)

Tic.hwnd = PB_Ico.hwnd

Tic.uID = H1&

Tic.uFlags = NIF_DOALL

Tic.uCallbackMessage = WM_MOUSEMOVE

Tic.hIcon = PB_Ico.Picture

erg = Shell_NotifyIcon(NIM_ADD, Tic)

End Sub

Private Sub PB_Ico_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

X = X / Screen.TwipsPerPixelX



'If (STATION_LOCK = True) Then Exit Sub



Select Case X

Case WM_LBUTTONDOWN 'Me.Caption = "Left Click"

PopupMenu MNUazerty

Case WM_RBUTTONDOWN 'Me.Caption = "Right Click"

PopupMenu MNUazerty

Case WM_MOUSEMOVE 'Me.Caption = "Move"




Case WM_LBUTTONDBLCLK 'Me.Caption = "Double Click"



End Select

End Sub





dans un module :



Public Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias
"Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA)
As Long



Public Const NIM_ADD = &H0

Public Const NIM_MODIFY = &H1

Public Const NIM_DELETE = &H2

Public Const NIF_MESSAGE = &H1

Public Const NIF_ICON = &H2

Public Const NIF_TIP = &H4

Public Const WM_CLOSE = &H10

Public Const NIF_DOALL = NIF_MESSAGE Or NIF_ICON Or NIF_TIP

Public Const WM_MOUSEMOVE = &H200

Public Const WM_LBUTTONDBLCLK = &H203

Public Const WM_LBUTTONDOWN = &H201

Public Const WM_RBUTTONDOWN = &H204



Public Type NOTIFYICONDATA

cbSize As Long

hwnd As Long

uID As Long

uFlags As Long

uCallbackMessage As Long

hIcon As Long

szTip As String * 64

End Type



Public Tic As NOTIFYICONDATA







et exactement le meme prob ....


Herve
0
Seth77 Messages postés 572 Date d'inscription mardi 30 avril 2002 Statut Membre Dernière intervention 4 mai 2020 1
1 sept. 2005 à 20:58
Ahhh merci ca marche !!


Herve
0
Rejoignez-nous