Je voulais vous dire merci beaucoup un tutoriel vraiment pratique ... ca fonctionne nickel
et merci dudul008 ta soluce fonctionne aussi
Je voulais vous dire merci beaucoup un tutoriel vraiment pratique ... ca fonctionne nickel
et merci dudul008 ta soluce fonctionne aussi
Bonjour j'ai un petit problème avec votre code ... quand on ferme la base l'icone de la barre de tache demeure jusqu'à ce que je passe dessus avec la souris ... là seulement elle disparaît ... ça semble à une question de refresh de la barre de tâche après fermeture ...
aussi sur Windows xp il n'y a aucun icone de présente mais un espace vide qui réagit au clic avec le bon menu !! bizarre
merci de jeter un coup d'oeil
Bonjour Arkham46 j'ai trouvé une partie du problème ...
lorsque je fermai mon appli le formulaire Frm_systray avait l'ordre de se fermer mais ne le fesait pas ... je l'ai changé de position dans le code et maintenant ca fonctionne. Ce qui arrivait donc étais que la base se fermait sans qu'il y ai le codage pour effacer l'icone du systray ...
ensuite pour ce qui est du problème de l'icone absente dans XP ... il semblerai que le codage :
ne soit pas compatible ! j'ai changé ce bout pour :
Code : Sélectionner tout - Visualiser dans une fenêtre à part Form_FrmSysTray.PutIconFromPackage Form_FrmSysTray.CadreOLEIndépendant
et maintenant tous est ok ...
Code : Sélectionner tout - Visualiser dans une fenêtre à part Form_FrmSysTray.PutIconFromFile "c:\le chemin\lefichier.ico"
si tu a une explication laisse moi savoir merci
Bonjour Thierry,
J'exploite avec bonheur ton code d'occultation de la fenêtre Access en 32 et 64 bits.
Je rencontre cependant un soucis concernant le SysTray en W10-64bits et Access 365 (2016)-64 bits: rien ne s'y passe! Pourtant dans mon système W10-32 et Access 32bits tout est OK.
Voici mon code:
As-tu une idée de ma boulette ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 ' Place l'icone du menu dans le systray Form_FrmSysTray.PutIconFromFile CurrentProject.Path & "\BT.ico" Form_FrmSysTray.ShowFormInTaskBar Forms("F_Menu") Form_FrmSysTray.SysTrayTipText = "Afficher le menu BT SYSTEM" Form_FrmSysTray.DisplayBallon "Afficher le menu BT SYSTEM", "BT SYSTEM", 10, SystrayError Or SystrayNoSound RestaurerFenetre (Me.hwnd)
Merci d'avance pour tes réponses
Bonsoir,
Je ne me rappelle pas avoir fait une version 64 bits.
As-tu fait les adaptations ?
Bonjour,
J'ai effectivement tenté un portage avec les déclarations 64 bits, mais visiblement une déclaration en LongPtr m'a échappé ou, peut-être une énumération dans les déclarations du module est-elle manquante ou erronée???
La fenêtre access est bien occultée (çà c'est nickel) mais, alors que ce code en 32 bits fait bien son boulot côté systray, en 64 bit: pas d'erreur, mais systray désespérément vide.
Ci-joint le résultat de ma gamberge, si tu trouves le hic, çà me sort une belle épine du pied.
Là çà dépasse mes compétences
Form_FrmSysTray.rar
Merci de ta réponse, Thierry
J'ai fait un peu vite.
Le code ci-dessous fonctionne chez moi sur Windows 10 64bits et Windows 8.1 32bits
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678 '*************************************************************************************** '* CLASSE POUR SYSTRAY * '*************************************************************************************** '*************************************************************************************** ' Auteur : Thierry GASPERMENT (Arkham46) ' v0.4 (19/12/2019) ' Adapté de : http://support.microsoft.com/kb/176085 '*************************************************************************************** '*************************************************************************************** '* EN-TETE * '*************************************************************************************** #If VBA7 Then DefLngPtr A-Z Const PtrNull As LongPtr = 0 #Else DefLng A-Z Const PtrNull As Long = 0 #End If Option Explicit Option Base 1 Option Compare Database '*************************************************************************************** '* API * '*************************************************************************************** #If VBA7 Then Private Declare PtrSafe Function GetFileVersionInfo Lib "version.dll" Alias "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwHandle As Long, ByVal dwLen As Long, lpData As Any) As Long Private Declare PtrSafe Function GetFileVersionInfoSize Lib "version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long Private Declare PtrSafe Function VerQueryValue Lib "version.dll" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, puLen As Long) As Long Private Declare PtrSafe Sub RtlMoveMemory Lib "kernel32" (Destination As Any, Source As Any, ByVal length As LongPtr) Private Declare PtrSafe Function CreateIconFromResourceEx Lib "user32" _ (presbits As Byte, ByVal dwResSize As Long, ByVal fIcon As Long, _ ByVal dwVer As Long, ByVal cxDesired As Long, ByVal cyDesired As Long, ByVal uFlags As Long) As LongPtr Private Declare PtrSafe Function ShowWindow Lib "user32" (ByVal hwnd As LongPtr, ByVal nCmdShow As Long) As Long Private Declare PtrSafe Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" _ (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Long Private Declare PtrSafe Function ExtractIcon Lib "shell32" Alias "ExtractIconA" _ (ByVal hInst As LongPtr, ByVal lpszexename As String, _ ByVal nIconIndex As Long) As LongPtr Private Declare PtrSafe Function ExtractAssociatedIcon Lib "SHELL32.DLL" Alias "ExtractAssociatedIconA" (ByVal hInst As LongPtr, ByVal lpIconPath As String, lpiIcon As Long) As LongPtr Private Declare PtrSafe Function DestroyIcon Lib "user32.dll" (ByVal hIcon As LongPtr) As Long Private Declare PtrSafe Function CreatePopupMenu Lib "user32" () As LongPtr Private Declare PtrSafe Function TrackPopupMenuEx Lib "user32" _ (ByVal hMenu As LongPtr, ByVal wFlags As Long, ByVal X As Long, _ ByVal Y As Long, ByVal hwnd As LongPtr, ByVal lptpm As Any) As Long Private Declare PtrSafe Function AppendMenu Lib "user32" Alias "AppendMenuA" _ (ByVal hMenu As LongPtr, ByVal wFlags As Long, _ ByVal wIDNewItem As LongPtr, ByVal lpNewItem As Any) As Long Private Declare PtrSafe Function DestroyMenu Lib "user32" (ByVal hMenu As LongPtr) As Long Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long #If Win64 Then Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongPtrA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongPtrA" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr #Else Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr #End If Private Declare PtrSafe Function GetParent Lib "user32" (ByVal hwnd As LongPtr) As LongPtr Private Declare PtrSafe Function GetDC Lib "user32" (ByVal hwnd As LongPtr) As LongPtr Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hwnd As LongPtr, ByVal hDC As LongPtr) As Long Private Declare PtrSafe Function GetDeviceCaps Lib "Gdi32" (ByVal hDC As LongPtr, ByVal nIndex As Long) As Long #Else Private Declare Function GetFileVersionInfo Lib "Version.dll" Alias "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwhandle As Long, ByVal dwlen As Long, lpData As Any) As Long Private Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long Private Declare Function VerQueryValue Lib "Version.dll" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, puLen As Long) As Long Private Declare Sub RtlMoveMemory Lib "kernel32" (Destination As Any, Source As Any, ByVal length As Long) Private Declare Function CreateIconFromResourceEx Lib "user32" _ (presbits As Byte, ByVal dwResSize As Long, ByVal fIcon As Long, _ ByVal dwVer As Long, ByVal cxDesired As Long, ByVal cyDesired As Long, ByVal uFlags As Long) As Long Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" _ (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Long Private Declare Function ExtractIcon Lib "shell32" Alias "ExtractIconA" _ (ByVal hInst As Long, ByVal lpszexename As String, _ ByVal nIconIndex As Long) As Long Private Declare Function ExtractAssociatedIcon Lib "SHELL32.DLL" Alias "ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As String, lpiIcon As Long) As Long Private Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Long) As Long Private Declare Function CreatePopupMenu Lib "user32" () As Long Private Declare Function TrackPopupMenuEx Lib "user32" _ (ByVal hMenu As Long, ByVal wFlags As Long, ByVal X As Long, _ ByVal Y As Long, ByVal hwnd As Long, ByVal lptpm As Any) As Long Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" _ (ByVal hMenu As Long, ByVal wFlags As Long, _ ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long Private Declare Function DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hDC As Long) As Long Private Declare Function GetDeviceCaps Lib "Gdi32" (ByVal hDC As Long, ByVal nIndex As Long) As Long #End If '*************************************************************************************** '* Constantes * '*************************************************************************************** Private Const MF_STRING = &H0& Private Const MF_SEPARATOR = &H800& Private Const TPM_LEFTALIGN = &H0& Private Const TPM_RETURNCMD = &H100& Private Const TPM_RIGHTBUTTON = &H2& Private Const SW_HIDE = 0 Private Const SW_SHOWNORMAL = 1 Private Const SW_SHOWMINIMIZED = 2 Private Const SW_SHOWMAXIMIZED = 3 Private Const SW_SHOWNA = 8 Private Const SW_SHOWMINNOACTIVE = 7 Private Const NIM_ADD As Long = &H0 Private Const NIM_MODIFY As Long = &H1 Private Const NIM_DELETE As Long = &H2 Private Const NIF_TIP As Long = &H4 Private Const NIF_MESSAGE As Long = &H1 Private Const NIF_ICON As Long = &H2 Private Const NIF_INFO = &H10 Private Const NIIF_NONE = &H0 Private Const NIIF_INFO = &H1 Private Const NIIF_WARNING = &H2 Private Const NIIF_ERROR = &H3 Private Const NIIF_GUID = &H5 Private Const NIIF_ICON_MASK = &HF Private Const NIIF_NOSOUND = &H10 Private Const NOTIFYICON_VERSION = &H3 Private Const WM_MOUSEMOVE = &H200 Private Const WM_LBUTTONDBLCLK = &H203 Private Const WM_LBUTTONDOWN = &H201 Private Const WM_LBUTTONUP = &H202 Private Const WM_RBUTTONDBLCLK = &H206 Private Const WM_RBUTTONDOWN = &H204 Private Const WM_RBUTTONUP = &H205 Private Const WM_MBUTTONDOWN = &H207 Private Const WM_MBUTTONUP = &H208 Private Const WM_MBUTTONDBLCLK = &H209 Private Const LOGPIXELSX As Long = 88 ' Constantes pour nombre de pixels par pouces Private Const WS_EX_APPWINDOW = &H40000 Private Const GWL_EXSTYLE = -20 Private Const NOTIFYICONDATA_V1_SIZE As Long = 88 ' Taille structure avant v5 Private Const NOTIFYICONDATA_V2_SIZE As Long = 488 ' Taille structure à partir de v5 Private Const NOTIFYICONDATA_V3_SIZE As Long = 504 ' Taille structure à partir de v6 Private Const NIN_BALLOONSHOW = &H402 Private Const NIN_BALLOONHIDE = &H403 Private Const NIN_BALLOONTIMEOUT = &H404 Private Const NIN_BALLOONUSERCLICK = &H405 '*************************************************************************************** '* Enumérations * '*************************************************************************************** Public Enum ESysTrayIcon SystrayNoIcon = NIIF_NONE SystrayInformation = NIIF_INFO SystrayWarning = NIIF_WARNING SystrayError = NIIF_ERROR SystrayNoSound = NIIF_NOSOUND End Enum '*************************************************************************************** '* Types * '*************************************************************************************** Private Type VS_FIXEDFILEINFO dwSignature As Long dwStrucVersionl As Integer dwStrucVersionh As Integer dwFileVersionMSl As Integer dwFileVersionMSh As Integer dwFileVersionLSl As Integer dwFileVersionLSh As Integer dwProductVersionMSl As Integer dwProductVersionMSh As Integer dwProductVersionLSl As Integer dwProductVersionLSh As Integer dwFileFlagsMask As Long dwFileFlags As Long dwFileOS As Long dwFileType As Long dwFileSubtype As Long dwFileDateMS As Long dwFileDateLS As Long End Type Private Type POINTAPI X As Long Y As Long End Type Private Type GUID Data1 As Long Data2 As Integer Data3 As Integer Data4(7) As Byte End Type #If VBA7 Then Private Type NOTIFYICONDATA cbSize As Long hwnd As LongPtr uID As Long uFlags As Long uCallbackMessage As Long hIcon As LongPtr szTip As String * 128 dwState As Long dwStateMask As Long szInfo As String * 256 uTimeoutAnduVersion As Long szInfoTitle As String * 64 dwInfoFlags As Long guidItem As GUID End Type #Else Private Type NOTIFYICONDATA cbSize As Long hwnd As Long uID As Long uFlags As Long uCallbackMessage As Long hIcon As Long szTip As String * 128 dwState As Long dwStateMask As Long szInfo As String * 256 uTimeoutAnduVersion As Long szInfoTitle As String * 64 dwInfoFlags As Long guidItem As GUID End Type #End If ' PT : Window sizing information for object ' used in OBJECTHEADER type. Private Type PT Width As Integer Height As Integer End Type Private Type OBJECTHEADER Signature As Integer ' Type signature (0x1c15). HeaderSize As Integer ' Size of header (sizeof(struct ' OBJECTHEADER) + cchName + ' cchClass). ObjectType As Long ' OLE Object type code (OT_STATIC, ' OT_LINKED, OT_EMBEDDED). NameLen As Integer ' Count of characters in object ' name (CchSz(szName) + 1). ClassLen As Integer ' Count of characters in class ' name (CchSz(szClass) + 1). NameOffset As Integer ' Offset of object name in ' structure (sizeof(OBJECTHEADER)). ClassOffset As Integer ' Offset of class name in ' structure (ibName + cchName). ObjectSize As PT ' Original size of object (see ' code below for value). OleInfo As String * 256 End Type Private Type OLEHEADER OleVersion As Long Format As Long TypeLen As Long End Type ' En-tete d'un fichier icone Private Type ICONDIR idReserved As Integer idType As Integer idCount As Integer End Type ' Données de chaque icone du fichier Private Type ICONDIRENTRY bWidth As Byte bHeight As Byte bColorCount As Byte bReserved As Byte wPlanes As Integer wBitCount As Integer dwBytesInRes As Long dwImageOffset As Long End Type '*************************************************************************************** '* Variables * '*************************************************************************************** Private gNID As NOTIFYICONDATA ' Données du systray Private gStructSize As Long ' Taille de la structure en fonction de la version '*************************************************************************************** '* Propriétés * '*************************************************************************************** Public Property Let SysTrayTipText(pText As String) On Error GoTo Gestion_Erreurs ' Rempli la structure pour l'API With gNID ' NIF_TIP pour changement du texte .uFlags = NIF_TIP .szTip = pText & vbNullChar End With ' Ajout l'icone Call Shell_NotifyIcon(NIM_MODIFY, gNID) On Error GoTo 0 Exit Property Gestion_Erreurs: MsgBox "Error " & Err.Number & " (" & Err.Description & ") dans la propriété SysTrayTipText du module Form_FrmSysTray" End Property Public Property Get SysTrayTipText() As String SysTrayTipText = Left(gNID.szTip, InStr(gNID.szTip, vbNullChar) - 1) End Property '*************************************************************************************** '* Procédures/fonctions * '*************************************************************************************** '--------------------------------------------------------------------------------------- ' Version de la dll '--------------------------------------------------------------------------------------- Private Function GetDllVersion(ByVal pPath As String) As Integer Dim lReturn As Long Dim lBuffer() As Byte Dim lSize As Long Dim lPointer Dim lFileInfo As VS_FIXEDFILEINFO On Error GoTo Gestion_Erreurs ' Taille des infos lSize = GetFileVersionInfoSize(pPath, 0&) If lSize < 1 Then GoTo Gestion_Erreurs ' Redimensionne le buffer ReDim lBuffer(1 To lSize) ' Récupère les infos dans le buffer lReturn = GetFileVersionInfo(pPath, 0&, lSize, lBuffer(1)) If lReturn = 0 Then GoTo Gestion_Erreurs ' Formate les infos à l'emplacement mémoire lPointer lReturn = VerQueryValue(lBuffer(1), "\", lPointer, 0&) If lReturn = 0 Then GoTo Gestion_Erreurs ' Déplace les données dans la structure RtlMoveMemory lFileInfo, ByVal lPointer, Len(lFileInfo) ' Récupère le numéro de version principale GetDllVersion = lFileInfo.dwFileVersionMSh On Error GoTo 0 Exit Function Gestion_Erreurs: GetDllVersion = 0 End Function '--------------------------------------------------------------------------------------- ' Modification de l'icone = icone de l'application ou d'access si inexistante '--------------------------------------------------------------------------------------- Public Function PutIconDefault() As Boolean Dim lhIcon ' Icone de l'application On Error Resume Next lhIcon = ExtractIcon(0, CurrentDb.Properties("AppIcon"), 0) On Error GoTo Gestion_Erreurs If lhIcon = 0 Then ' Extraction de l'icone associée au fichier lhIcon = ExtractAssociatedIcon(0, CurrentDb.Name, 0) End If ' Si icone extraite avec succès If lhIcon <> 0 Then ' Supprime l'ancienne icone If gNID.hIcon <> 0 Then DestroyIcon gNID.hIcon ' Rempli la structure pour l'API With gNID ' NIF_ICON pour affichage icone .uFlags = NIF_ICON .hIcon = lhIcon End With ' Ajout l'icone PutIconDefault = (Shell_NotifyIcon(NIM_MODIFY, gNID) <> 0) End If On Error GoTo 0 Exit Function Gestion_Erreurs: MsgBox "Error " & Err.Number & " (" & Err.Description & ") dans la fonction PutIconDefault du module Form_FrmSysTray" PutIconDefault = False End Function '--------------------------------------------------------------------------------------- ' Modification de l'icone à partir d'un fichier '--------------------------------------------------------------------------------------- Public Function PutIconFromFile(pFile As String) As Boolean Dim lhIcon On Error GoTo Gestion_Erreurs ' Extraction de l'icone associée au fichier lhIcon = ExtractIcon(0, pFile, 0) ' Si icone extraite avec succès If lhIcon <> 0 Then ' Supprime l'ancienne icone If gNID.hIcon <> 0 Then DestroyIcon gNID.hIcon ' Rempli la structure pour l'API With gNID ' NIF_ICON pour affichage icone .uFlags = NIF_ICON .hIcon = lhIcon End With ' Ajout l'icone PutIconFromFile = (Shell_NotifyIcon(NIM_MODIFY, gNID) <> 0) End If On Error GoTo 0 Exit Function Gestion_Erreurs: MsgBox "Error " & Err.Number & " (" & Err.Description & ") dans la fonction PutIconFromFile du module Form_FrmSysTray" PutIconFromFile = False End Function '--------------------------------------------------------------------------------------- ' Modification de l'icone à partir d'une icone dans un package ' pPackage = cadre OLE indépendant ' pIconNumber = numéro de l'icone (un fichier pouvant contenir plusieurs icones) '--------------------------------------------------------------------------------------- Public Function PutIconFromPackage(pPackage As Access.ObjectFrame, Optional ByVal pIconNumber As Long = 1) As Boolean ' Adapté de http://support.microsoft.com/kb/147727/fr Dim lhIcon Dim lData() As Byte Dim lHeader As OBJECTHEADER Dim lOleHeader As OLEHEADER Dim lBuffer() As Byte Dim lpos As Long Dim lLong As Long Dim lIcon() As Byte Dim lIconDir As ICONDIR Dim lIconDirEntry As ICONDIRENTRY On Error GoTo Gestion_Erreurs ' Extraction des données lData = pPackage.OleData ' Récupère l'en-tête lpos = LBound(lData) RtlMoveMemory lHeader, lData(lpos), Len(lHeader) ' Test si objet intégré If lHeader.ObjectType <> 2 Then Exit Function ' Test si package ReDim lBuffer(1 To 8) lpos = LBound(lData) + lHeader.ClassOffset RtlMoveMemory lBuffer(1), lData(lpos), 8 If StrConv(lBuffer, vbUnicode) <> "Package" & vbNullChar Then Exit Function ' En-tête OLE lpos = LBound(lData) + lHeader.HeaderSize RtlMoveMemory lOleHeader, lData(lpos), Len(lOleHeader) ' Taille du contenu lpos = LBound(lData) + lHeader.HeaderSize + 20 + lOleHeader.TypeLen RtlMoveMemory lLong, lData(lpos), 4 lpos = lpos + 4 ' on passe la taille ' Entier = 2 (taille 2) lpos = lpos + 2 ' Nom du fichier Do Until lData(lpos) = 0 lpos = lpos + 1 Loop lpos = lpos + 1 ' on passe le chr(0) ' Chemin complet du fichier Do Until lData(lpos) = 0 lpos = lpos + 1 Loop lpos = lpos + 1 ' on passe le chr(0) ' Long = 3 (taille 4) lpos = lpos + 4 ' Taille du chemin qui suit RtlMoveMemory lLong, lData(lpos), 4 lpos = lpos + 4 + lLong ' On passe le chemin du fichier ' Taille du fichier RtlMoveMemory lLong, lData(lpos), 4 ' Buffer pour contenir le fichier ReDim lBuffer(1 To lLong) lpos = lpos + 4 RtlMoveMemory lBuffer(1), lData(lpos), lLong ' En-tête de l'icone RtlMoveMemory lIconDir, lBuffer(1), Len(lIconDir) If pIconNumber > lIconDir.idCount Then pIconNumber = lIconDir.idCount RtlMoveMemory lIconDirEntry, lBuffer(1 + Len(lIconDir) + Len(lIconDirEntry) * (pIconNumber - 1)), Len(lIconDirEntry) ' Test si icone If lIconDir.idType <> 1 Then Exit Function ' Données de l'icone ReDim lIcon(1 To lIconDirEntry.dwBytesInRes) RtlMoveMemory lIcon(1), lBuffer(1 + lIconDirEntry.dwImageOffset), lIconDirEntry.dwBytesInRes ' Création de l'icone en mémoire lhIcon = CreateIconFromResourceEx(lIcon(1), lIconDirEntry.dwBytesInRes, 1, &H30000, lIconDirEntry.bWidth, lIconDirEntry.bHeight, 0) ' Si icone créée avec succès If lhIcon <> 0 Then ' Supprime l'ancienne icone If gNID.hIcon <> 0 Then DestroyIcon gNID.hIcon ' Rempli la structure pour l'API With gNID ' NIF_ICON pour affichage icone .uFlags = NIF_ICON .hIcon = lhIcon End With ' Modifie l'icone PutIconFromPackage = (Shell_NotifyIcon(NIM_MODIFY, gNID) <> 0) End If On Error GoTo 0 Exit Function Gestion_Erreurs: MsgBox "Error " & Err.Number & " (" & Err.Description & ") dans la fonction PutIconFromPackage du module Form_FrmSysTray" PutIconFromPackage = False End Function '--------------------------------------------------------------------------------------- ' Affichage d'une info-bulle ballon ' pTimeOut en secondes entre 10 et 30 ' Suelement à partir de win2000 '--------------------------------------------------------------------------------------- Public Function DisplayBallon(pText As String, Optional pTitle As String = "", Optional pTimeOut As Long = 10, Optional pIcon As ESysTrayIcon) As Boolean On Error GoTo Gestion_Erreurs ' Rempli la structure pour l'API With gNID ' NIF_INFO pour affichage ballon .uFlags = NIF_INFO .szInfo = pText & vbNullChar .szInfoTitle = pTitle & vbNullChar .uTimeoutAnduVersion = pTimeOut * 1000 .dwInfoFlags = pIcon End With ' Ajout l'icone Call Shell_NotifyIcon(NIM_MODIFY, gNID) On Error GoTo 0 Exit Function Gestion_Erreurs: MsgBox "Error " & Err.Number & " (" & Err.Description & ") dans la propriété SysTrayTipText du module Form_FrmSysTray" End Function '--------------------------------------------------------------------------------------- ' Affichage de l'icone '--------------------------------------------------------------------------------------- Public Function DisplaySysTray() As Boolean On Error GoTo Gestion_Erreurs ' Rempli la structure pour l'API With gNID .cbSize = gStructSize .hwnd = Me.hwnd .uID = vbNull ' NIF_ICON pour affichage icone ' NIF_TIP pour affichage tooltip ' NIF_MESSAGE pour callback .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE ' Les messages du systray seront renvoyés vers le formulaire dans ' l'évenement "souris déplacée" .uCallbackMessage = WM_MOUSEMOVE ' Le texte doit contenir un caractère nul If .szTip = "" Then .szTip = vbNullChar End With ' Ajout l'icone DisplaySysTray = (Shell_NotifyIcon(NIM_ADD, gNID) <> 0) On Error GoTo 0 Exit Function Gestion_Erreurs: MsgBox "Error " & Err.Number & " (" & Err.Description & ") dans la fonction DisplaySysTray du module Form_FrmSysTray" DisplaySysTray = False End Function '--------------------------------------------------------------------------------------- ' Supprime l'icone '--------------------------------------------------------------------------------------- Public Function HideSysTray() As Boolean On Error GoTo Gestion_Erreurs ' Supprime l'ancienne icone If gNID.hIcon <> 0 Then DestroyIcon gNID.hIcon ' Supprime l'icone de la barre HideSysTray = (Shell_NotifyIcon(NIM_DELETE, gNID) <> 0) On Error GoTo 0 Exit Function Gestion_Erreurs: MsgBox "Error " & Err.Number & " (" & Err.Description & ") dans la fonction HideSysTray du module Form_FrmSysTray" HideSysTray = False End Function '--------------------------------------------------------------------------------------- ' Affiche le menu dans le systray '--------------------------------------------------------------------------------------- Private Function PopupMenu(pMenuItems() As String) As Long Dim lResult As Long, lhMenu, lPt As POINTAPI Dim lCpt As Integer On Error GoTo Gestion_Erreurs 'Creer le menu contextuel lhMenu = CreatePopupMenu() 'Creer les items du menu contextuel For lCpt = LBound(pMenuItems) To UBound(pMenuItems) AppendMenu lhMenu, MF_STRING Or IIf(pMenuItems(lCpt) = "", MF_SEPARATOR, 0), 1 + lCpt - LBound(pMenuItems), pMenuItems(lCpt) Next 'Récupere l'emplacement de la souris GetCursorPos lPt 'Affiche le menu à l'emplacement de la souris 'Et récupere la valeur de l'item cliqué lResult = TrackPopupMenuEx(lhMenu, TPM_LEFTALIGN Or TPM_RETURNCMD _ Or TPM_RIGHTBUTTON, lPt.X, lPt.Y, GetParent(gNID.hwnd), ByVal 0&) 'Supprime le menu DestroyMenu lhMenu 'Renvoi le resultat PopupMenu = lResult On Error GoTo 0 Exit Function Gestion_Erreurs: MsgBox "Error " & Err.Number & " (" & Err.Description & ") dans la fonction PopupMenu du module Form_FrmSysTray" PopupMenu = 0 End Function '--------------------------------------------------------------------------------------- ' Fermeture du formulaire '--------------------------------------------------------------------------------------- Private Sub Form_Close() HideSysTray End Sub '--------------------------------------------------------------------------------------- ' Initialisation du formulaire '--------------------------------------------------------------------------------------- Private Sub Form_Open(Cancel As Integer) ' Taille de la structure NOTIFYICONDATA en focntion de la version If GetDllVersion("shell32.dll") >= 6 Then gStructSize = NOTIFYICONDATA_V3_SIZE ElseIf GetDllVersion("shell32.dll") >= 5 Then gStructSize = NOTIFYICONDATA_V2_SIZE Else gStructSize = NOTIFYICONDATA_V1_SIZE End If ' Affiche l'icone dans le systray DisplaySysTray End Sub '--------------------------------------------------------------------------------------- ' Conversion Twips -> Pixels '--------------------------------------------------------------------------------------- Private Function ConvertTwipsToPixels(pTwips As Long) As Long Dim lPtsPerPixel As Single Dim lhdc lhdc = GetDC(Me.hwnd) lPtsPerPixel = 1440 / GetDeviceCaps(lhdc, LOGPIXELSX) ReleaseDC 0, lhdc ConvertTwipsToPixels = pTwips \ lPtsPerPixel End Function '--------------------------------------------------------------------------------------- ' Affiche la fenêtre Access '--------------------------------------------------------------------------------------- Public Sub ShowAccessWindow() ShowWindow Application.hWndAccessApp, SW_SHOWNA End Sub '--------------------------------------------------------------------------------------- ' Masque la fenêtre Access '--------------------------------------------------------------------------------------- Public Sub HideAccessWindow() ShowWindow Application.hWndAccessApp, SW_HIDE End Sub '--------------------------------------------------------------------------------------- ' Affiche formulaire dans barre des tâches '--------------------------------------------------------------------------------------- Public Sub ShowFormInTaskBar(pForm As Access.Form) Dim lStyle lStyle = GetWindowLong(pForm.hwnd, GWL_EXSTYLE) Call SetWindowLong(pForm.hwnd, GWL_EXSTYLE, lStyle Or WS_EX_APPWINDOW) End Sub '--------------------------------------------------------------------------------------- ' Masque formulaire dans barre des tâches '--------------------------------------------------------------------------------------- Public Sub HideFormInTaskBar(pForm As Access.Form) Dim lStyle lStyle = GetWindowLong(pForm.hwnd, GWL_EXSTYLE) Call SetWindowLong(pForm.hwnd, GWL_EXSTYLE, lStyle Xor WS_EX_APPWINDOW) End Sub '--------------------------------------------------------------------------------------- ' Evenement sur icone du systray '--------------------------------------------------------------------------------------- Private Sub Détail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim lMsg As Long On Error GoTo Gestion_Erreurs ' Conversion de points/twips vers pixels pour retrouver le numéro du message d'origine lMsg = ConvertTwipsToPixels(X + Me.CurrentSectionLeft) - 1 Select Case lMsg Case WM_MOUSEMOVE ' Déplacement souris Case WM_LBUTTONDOWN ' Bouton gauche appuyé Case WM_LBUTTONUP ' Bouton gauche relâché Case WM_LBUTTONDBLCLK ' Double click gauche Case WM_RBUTTONDOWN ' Bouton droit appuyé Case WM_RBUTTONUP ' Bouton droit relâché Case WM_RBUTTONDBLCLK ' Double click droit Case WM_MBUTTONDOWN ' Bouton milieu appuyé Case WM_MBUTTONUP ' Bouton milieu relâché Case WM_MBUTTONDBLCLK ' Double click milieu Case NIN_BALLOONTIMEOUT ' Time out de l'info-bulle ballon Case NIN_BALLOONUSERCLICK ' Click sur info-bulle ballon End Select On Error GoTo 0 Exit Sub Gestion_Erreurs: MsgBox "Error " & Err.Number & " (" & Err.Description & ") dans la procédure Détail_MouseMove du module Form_FrmSysTray" End Sub
Merci Thierry pour ta réponse rapide.
Une question: as-tu modifié quelque chose par rapport au code que je t'ai envoyé car celui-ci remplit parfaitement sa fonction en 32 bits:
Une question: le systray s'affiche-t-il chez toi en 64 bits?
Car chez moi ni l'infobulle, ni le systray ne fonctionnent en 64 bits sur mon code (d'où ma question).
Je suis reparti du code 32 bits, pas de ta version en fait.
J'avais déjà fait une partie du travail, mais pas sur l'info-bulle.
Le code 32 bits devrait toujours fonctionner.
Avec le dernier code que j'ai posté, j'ai bien l'icône dans le systray en 64 bits.
Mais pas l'info-bulle.
Je n'ai pas eu le temps de creuser ce point, qui est en fait le plus complexe.
J'ai fait ça rapidement à la pause de midi, j'ai oublie de tester ton code sur mon PC...
Waho! Question réactivité tu te poses là!
OK donc fonctionnellement ton code est meilleur que le mien: je vais faire l'échange et tester en 64 bits. Au moins, je pourrai disposer des commandes systray.
Je te fais un retour dès que possible.
Merci encore et... désolé pour ta pause déjeuner !!!
OK,
je viens copier-coller ton code (hormis les événements sur clic) en lieu et place du mien.
J'ai bien le systray en 32 et 64 bits mais j'ai perdu le DisplayBallon sur les 2 versions et les déclarations de constantes et autres énumérations, çà me dépasse un peu .
Je reviens pour l'instant sur mon ancienne version.
Merci pour ton aide et fais moi signe si une solution se dessine.
J'ai fait une erreur dans la taille de szTip des structures NOTIFYICONDATA.
J'avais pris les déclarations d'une vieille version, c'est maintenant 128 au lieu de 64 (depuis Windows 2000, je pense qu'on peut donc passer à 128).
J'ai corrigé le code précédent sur ce point.
En plus j'ai fait un copier-coller un peu raté du code, les accents ont disparus (un peu gênant pour le Détail_MouseMove).
Sinon je dois creuser mais j'ai tenté de définir des tailles différentes de NOTIFYICONDATA pour 64 bits (NOTIFYICONDATA_V1_SIZE et NOTIFYICONDATA_V2_SIZE).
Pas sûr que ce soit ce qu'il faut faire, les tailles ne sont pas les tailles réelles apparemment.
J'ai remis des tailles identiques 32/64bits dans le code précédent.
Par contre je ne vois de quelles "constantes et énumérations" tu parles.
Pardon pour le vocabulaire inadéquat , je voulais parler des déclarations en général (ici, NOTIFYICONDATA). (la preuve que là on nage dans des sphères qui me dépassent) (cf ma signature plus bas)
Je pense que je vais tester çà demain matin, merci pour ton implication. Je ferai, bien sûr un retour et au final çà fera avancer le shmilblick puisque à terme le 32 bits est condamné (de plus en plus de clients achètent des versions access 64 sur des machines 64).
Voilà j'ai fait une petite évolution dans le code précédent.
Je n'ai pas encore mis à jour le message initial.
En tout cas ça marche chez moi (y compris l'info-bulle) sur :
- Windows 10, Office 2013 64bits
- Windows 8.1, Office 2003 32bits
J'espère que ça fonctionnera sur tes configurations.
Retour du matin, retour chagrin
Bonjour Thierry,
Merci pour ta correction, l'appli se lance effectivement correctement sous W10 pro 64 et 32 bits avec ,respectivement Access 2016 et 2013 : elle plante cependant en 64 bits.
Il reste une coquetterie dans le MouseMove qui me génère ce message:
J'ai tenté une correction en déclarant lMsg en LongPtr mais c'est pas mieux:
En fait l'appli plante en 64 bits si je la lance normalement, si je trace en mode pas à pas la procédure de lancement: là pas d'erreur ??? .
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 '--------------------------------------------------------------------------------------- ' Evenement sur icone du systray '--------------------------------------------------------------------------------------- Private Sub Détail_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim lMsg As LongPtr Dim ret On Error GoTo Gestion_Erreurs ' Conversion de points/twips vers pixels pour retrouver le numéro du message d'origine lMsg = ConvertTwipsToPixels(X + Me.CurrentSectionLeft) - 1 Select Case lMsg Case WM_MOUSEMOVE ' Déplacement souris Case WM_LBUTTONDOWN ' Bouton gauche appuyé Case WM_LBUTTONUP ' Bouton gauche relâché Case WM_LBUTTONDBLCLK ' Double click gauche RestaurerFenetre (Forms!f_menu.hwnd) Case WM_RBUTTONDOWN ' Bouton droit appuyé '****************************************************** 'Création des popup menus du systray Dim lResult As Long Dim lMenuItems(4) As String lMenuItems(1) = "Ouverture BTSub" lMenuItems(2) = "Fermeture BTMenu" lMenuItems(3) = "Dossier serveur" lMenuItems(4) = "Dossier local" lResult = PopupMenu(lMenuItems) '****************************************************** 'Evénement clic du popup menu Select Case lResult Case 1 ret = ShellExecute(Me.hwnd, "open", CurrentProject.Path & "\BTSub.accdb", "", CurrentProject.Path, 1) Case 2 Form_F_Menu.Form_Close Case 3 ret = Shell("explorer.exe /root, " & Nz(DFirst("OnSPath", "T_Param2"), "c:\"), vbNormalFocus) Case 4 ret = Shell("explorer.exe /root, " & CurrentProject.Path, vbNormalFocus) End Select Case WM_RBUTTONUP ' Bouton droit relâché Case WM_RBUTTONDBLCLK ' Double click droit Case WM_MBUTTONDOWN ' Bouton milieu appuyé Case WM_MBUTTONUP ' Bouton milieu relâché Case WM_MBUTTONDBLCLK ' Double click milieu Case NIN_BALLOONTIMEOUT ' Time out de l'info-bulle ballon Case NIN_BALLOONUSERCLICK ' Click sur info-bulle ballon End Select On Error GoTo 0 Exit Sub Gestion_Erreurs: MsgBox "Error " & Err.Number & " (" & Err.Description & ") dans la procédure Détail_MouseMove du module Form_FrmSysTray" End Sub
Ci-après le form_Open du menu:
Désolé de faire mon boulet, mais je suis un peu perdu.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181 '====================================================================================================================== Private Sub Form_Open(Cancel As Integer) ' 'F 'Ouverture du module (exécuté AVANT le resize) 'gestion des boutons de commande: libellé, largeur et option de visibilité 'initialisations ' 'E 'T_Menu/R_Menu paramètre les éléments du menu applicable ici (à terme prise en compte de la config du poste) ' 'S 'T_ExeMenu 'boutons de commande du menu: libellé et option de visibilité Dim LbI As Integer 'ordre physique des libellés Dim RS_Menu As Recordset Dim Ordre As Integer, SQL As String Dim data, intCmdNb As Integer, intCmdNbOnCol As Integer, chemIcn As String, strSQL As String Dim popMenu As Long On Error GoTo ErrHandler With Me DoCmd.MoveSize , , CM2Twips(lngWinWidth), CM2Twips(lngWinHeight) End With '''Masquage de la fenêtre access DoCmd.OpenForm "FrmSystray", , , , , acHidden Form_FrmSysTray.HideAccessWindow Form_Resize ' Vérifie si démarrage direct If IsNull(Command()) Or Command() = "" Then If MsgBox("Le démarrage direct de cette application court circuite des fonctions de mise à jour." & _ vbCrLf & _ "Voulez vous vraiment continuer ?", vbYesNo Or vbCritical, AppName) = vbNo Then Application.Quit End If End If ' Place l'icone du menu dans le systray Form_FrmSysTray.PutIconFromFile CurrentProject.Path & "\BT.ico" Form_FrmSysTray.ShowFormInTaskBar Forms("F_Menu") Form_FrmSysTray.SysTrayTipText = "Afficher le menu BT SYSTEM" Form_FrmSysTray.DisplayBallon "Afficher le menu BT SYSTEM", "BT SYSTEM", 10, SystrayError Or SystrayNoSound RestaurerFenetre (Me.hwnd) 'boucle attribution d'une definition active de T_Menu, à un bouton physique du menu 'dans l'ordre physique DoCmd.RunSQL "DELETE T_ExeMenu.* FROM T_ExeMenu;" LbI = 1 chemIcn = Nz(DLookup("OnSPath", "T_Param2"), CurrentProject.Path & "\") & "PC\IcnMnu\" 'requête dont le champ "MatchFld" à blanc signifie un bouton non utilisé/paramétré strSQL = "SELECT R_Menu_Ref.*, T_Menu.Libellé AS MatchFld FROM R_Menu_Ref LEFT JOIN T_Menu ON R_Menu_Ref.Libellé = T_Menu.Libellé ORDER BY R_Menu_Ref.Ordre;" Set RS_Menu = CurrentDb.OpenRecordset(strSQL) With RS_Menu 'repeter jusqu'à toutes lignes de T_Menu explorées Do While Not .EOF 'l Ordre = .Fields("ordre") 'Vérification existence picto Me.Controls("Lb" & LbI).Caption = vbCrLf & " " & Nz(.Fields("BtnCaption"), "") Me.Controls("Lb" & LbI).ControlTipText = Nz(.Fields("SLibellé"), "") Me.Controls("Lb" & LbI).BackColor = Nz(.Fields("btnColor"), 0) Me.Controls("Lb" & LbI).ForeColor = Nz(.Fields("btnForeColor"), 0) Me.Controls("Lb" & LbI).BorderColor = Nz(.Fields("btnBorderColor"), 0) Me.Controls("Lb" & LbI).HoverColor = Nz(.Fields("btnAlterColor"), 0) Me.Controls("Lb" & LbI).HoverForeColor = Nz(.Fields("btnAlterForeColor"), 0) Me.Controls("Lb" & LbI).PressedColor = 16777215 Me.Controls("Lb" & LbI).Visible = -1 If Nz(.Fields("MatchFld"), "") = "" Then Me.Controls("lb" & LbI).Picture = "" Me.Controls("lb" & LbI).Caption = "" Me.Controls("lb" & LbI).ControlTipText = "Indisponible : " & Me.Controls("lb" & LbI).ControlTipText End If 'ajout enrgt à la table T_ExeMenu: correspondance entre LbI et N° Ordre T_Menu SQL = "INSERT INTO T_ExeMenu ( N°, Ordre ) SELECT " & LbI & " AS N°, " & Ordre & " AS Ordre" DoCmd.RunSQL SQL LbI = LbI + 1 If LbI > 12 Then Exit Do .MoveNext Loop 'masquage des boutons non utilisés Do While LbI < 13 Me.Controls("Lb" & LbI).Visible = False LbI = LbI + 1 Loop .Close End With 'début acces à T_Param2 With CurrentDb.OpenRecordset("T_Param2") On Error Resume Next 'fichier de l'icone de l'application SetProperty "AppIcon", dbText, GetBTFrontPath & "BT.ico" 'gestion image du form. avec 2 possibilités non obligatoires If Not IsNull(CheckFile(GetBTFrontPath & "Image menu.png")) Then Controls("ctlimage").Picture = GetBTFrontPath & "Image menu.png" Else If Not IsNull(CheckFile(GetBTFrontPath & "Image accueil.jpg")) Then Controls("ctlimage").Picture = GetBTFrontPath & "Image accueil.jpg" End If End If On Error GoTo ErrHandler '****************************************************** 'INITIALISATIONS SPECIFIQUES DE L'APPLICATION '****************************************************** 'stockage du chemin dans Paramstart pour info et + éventuellement VbFrontauxPath = GetBTFrontPath() 'var. publique chemin access VbMSAccessPath = DLookup("MSAccessPath", Paramstart) If Right(VbMSAccessPath, 1) <> "\" Then VbMSAccessPath = VbMSAccessPath & "\" 'génération T_ExeKeyPaths : table de conversion des chemins paramétrables '-------------------------------------------------------------------------- 'vidage' SQL = "DELETE T_ExeKeyPaths.* FROM T_ExeKeyPaths;" DoCmd.RunSQL SQL 'ajouts 'app SQL = "INSERT INTO T_ExeKeyPaths ( PathId, ExePath ) SELECT '{app}' AS Expr1, '" & VbFrontauxPath & "' AS Expr2;" DoCmd.RunSQL SQL 'appcbt SQL = "INSERT INTO T_ExeKeyPaths ( PathId, ExePath ) SELECT '{AppCbt}' AS Expr1, '" & VbFrontauxPath & "CBT\' AS Expr2;" DoCmd.RunSQL SQL 'ServerData data = Nz(DLookup("SRPath", Paramstart), "?") SQL = "INSERT INTO T_ExeKeyPaths ( PathId, ExePath ) SELECT '{ServerData}' AS Expr1, '" & data & "' AS Expr2;" DoCmd.RunSQL SQL 'ServerCbt data = Nz(DLookup("SRPath", Paramstart), "?") SQL = "INSERT INTO T_ExeKeyPaths ( PathId, ExePath ) SELECT '{ServerCbt}' AS Expr1, '" & data & "PC\BTSystem2\CBT\' AS Expr2;" DoCmd.RunSQL SQL 'génération de T_ExeCbtEtCpl '--------------------------- 'vidage' SQL = "DELETE T_ExeCbtEtCpl.* FROM T_ExeCbtEtCpl;" DoCmd.RunSQL SQL 'ajouts DoCmd.OpenQuery "R_ExeCbtEtCpl_Add", acViewNormal, acEdit pexit: On Error Resume Next 'fin utilisation de T_Param2 .Close End With Exit Sub ErrHandler: If Err.Number <> 1 Then MsgBox "Procedure ouverture : erreur ligne " & Erl & " code: " & Err.Number & " - " & Err.Description, , AppName End If GoTo pexit End Sub
Le lMsg est bien un Long.
Cela plante sur quelle action ?
Déplacement de la souris sur le systray ? Double-click ?
Le problème est qu'on ne peut pas toujours bien déboguer dans le callback.
Au pire des MsgBox permettent de voir ce qui passe.
Oui, j'ai corrigéLe lMsg est bien un Long.
En fait:Cela plante sur quelle action ?
si je double clique sur l'accdb, l'appli se lance et plante après l'occultation d'Access et le Ballon et le Systray.
si je lance l'appli sans la démarrer (option Shift) là tout se lance correctement sauf pour le message de dépassement indiqué plus haut et lors du survol du SysTray.
Du coup, je ne sais pas où se trouve l'erreur que je n'arrive pas à tracer en pas à pas.
Note: Heu c'est quoi le callback?
Le callback c'est le détail_mousemove.
Tu peux mettre un exit sub au début du détail_mousemove pour déjà voir si c'est cette partie de code qui fait planter.
Il y a peut-être des autres déclarations d'API erronées ailleurs dans l'appli ?
Test effectué: même problème, çà plante au démarrage.Tu peux mettre un exit sub au début du détail_mousemove pour déjà voir si c'est cette partie de code qui fait planter.
Ce qui est étonnant, c'est que même si le systray ni le ballon ne s'affichaient pas dans ta première version avec les déclarations 64 bits que j'avais faites, je n'avais pas de plantage, même si le systray ne s'affichait pas:
...Ce qui me porte à penser que les déclarations dans les autres modules ne sont pas en cause.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278 '*************************************************************************************** '* CLASSE POUR SYSTRAY * '*************************************************************************************** '*************************************************************************************** ' Auteur : Thierry GASPERMENT (Arkham46) ' v0.3 (31/10/08) ' Adapté de : http://support.microsoft.com/kb/176085 '*************************************************************************************** '*************************************************************************************** '* EN-TETE * '*************************************************************************************** Option Explicit Option Base 1 Option Compare Database '*************************************************************************************** '* API * '*************************************************************************************** #If VBA7 Then #If Win64 Then Private Declare PtrSafe Function GetFileVersionInfo Lib "version.dll" Alias "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwHandle As Long, ByVal dwLen As Long, lpData As Any) As Long Private Declare PtrSafe Function GetFileVersionInfoSize Lib "version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long Private Declare PtrSafe Function VerQueryValue Lib "version.dll" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As LongPtr, puLen As Long) As Long Private Declare PtrSafe Sub RtlMoveMemory Lib "kernel32" (Destination As Any, Source As Any, ByVal length As LongPtr) Private Declare PtrSafe Function CreateIconFromResourceEx Lib "user32" _ (presbits As Byte, ByVal dwResSize As Long, ByVal fIcon As Long, _ ByVal dwVer As Long, ByVal cxDesired As Long, ByVal cyDesired As Long, ByVal uFlags As Long) As LongPtr Private Declare PtrSafe Function ShowWindow Lib "user32" (ByVal hwnd As LongPtr, ByVal nCmdShow As Long) As Long Private Declare PtrSafe Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" _ (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Long Private Declare PtrSafe Function ExtractIcon Lib "shell32" Alias "ExtractIconA" _ (ByVal hInst As LongPtr, ByVal lpszexename As String, _ ByVal hIcon As Long) As LongPtr Private Declare PtrSafe Function ExtractAssociatedIcon Lib "SHELL32.DLL" Alias "ExtractAssociatedIconA" (ByVal hInst As LongPtr, ByVal lpIconPath As String, lpiIcon As Long) As LongPtr Private Declare PtrSafe Function DestroyIcon Lib "user32.dll" (ByVal hIcon As LongPtr) As Long Private Declare PtrSafe Function CreatePopupMenu Lib "user32" () As LongPtr Private Declare PtrSafe Function TrackPopupMenuEx Lib "user32" _ (ByVal hMenu As LongPtr, ByVal wFlags As Long, ByVal X As Long, _ ByVal Y As Long, ByVal hwnd As LongPtr, ByVal lptpm As Any) As Long Private Declare PtrSafe Function AppendMenu Lib "user32" Alias "AppendMenuA" _ (ByVal hMenu As LongPtr, ByVal wFlags As Long, _ ByVal wIDNewItem As LongPtr, ByVal lpNewItem As Any) As Long Private Declare PtrSafe Function DestroyMenu Lib "user32" (ByVal hMenu As LongPtr) As Long Private Declare PtrSafe Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As Long Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare PtrSafe Function GetParent Lib "user32" (ByVal hwnd As LongPtr) As LongPtr Private Declare PtrSafe Function GetDC Lib "user32" (ByVal hwnd As LongPtr) As LongPtr Private Declare PtrSafe Function ReleaseDC Lib "user32" (ByVal hwnd As LongPtr, ByVal hDC As LongPtr) As Long Private Declare PtrSafe Function GetDeviceCaps Lib "Gdi32" (ByVal hDC As LongPtr, ByVal nIndex As Long) As Long Private Declare PtrSafe Function ShellExecute Lib "SHELL32.DLL" Alias "ShellExecuteA" _ (ByVal hwnd As LongPtr, ByVal lpOperation As String, ByVal lpFile As String, _ ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As LongPtr #Else Private Declare Function GetFileVersionInfo Lib "Version.dll" Alias "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwhandle As Long, ByVal dwlen As Long, lpData As Any) As Long Private Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long Private Declare Function VerQueryValue Lib "Version.dll" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, puLen As Long) As Long Private Declare Sub RtlMoveMemory Lib "kernel32" (Destination As Any, Source As Any, ByVal Length As Long) Private Declare Function CreateIconFromResourceEx Lib "user32" _ (presbits As Byte, ByVal dwResSize As Long, ByVal fIcon As Long, _ ByVal dwVer As Long, ByVal cxDesired As Long, ByVal cyDesired As Long, ByVal uFlags As Long) As Long Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" _ (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Long Private Declare Function ExtractIcon Lib "shell32" Alias "ExtractIconA" _ (ByVal hInst As Long, ByVal lpszexename As String, _ ByVal hIcon As Long) As Long Private Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As String, lpiIcon As Long) As Long Private Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Long) As Long Private Declare Function CreatePopupMenu Lib "user32" () As Long Private Declare Function TrackPopupMenuEx Lib "user32" _ (ByVal hMenu As Long, ByVal wFlags As Long, ByVal X As Long, _ ByVal Y As Long, ByVal hwnd As Long, ByVal lptpm As Any) As Long Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" _ (ByVal hMenu As Long, ByVal wFlags As Long, _ ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long Private Declare Function DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _ (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _ ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long #End If #Else Private Declare Function GetFileVersionInfo Lib "Version.dll" Alias "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwhandle As Long, ByVal dwlen As Long, lpData As Any) As Long Private Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long Private Declare Function VerQueryValue Lib "Version.dll" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, puLen As Long) As Long Private Declare Sub RtlMoveMemory Lib "kernel32" (Destination As Any, Source As Any, ByVal Length As Long) Private Declare Function CreateIconFromResourceEx Lib "user32" _ (presbits As Byte, ByVal dwResSize As Long, ByVal fIcon As Long, _ ByVal dwVer As Long, ByVal cxDesired As Long, ByVal cyDesired As Long, ByVal uFlags As Long) As Long Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" _ (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Long Private Declare Function ExtractIcon Lib "shell32" Alias "ExtractIconA" _ (ByVal hInst As Long, ByVal lpszexename As String, _ ByVal hIcon As Long) As Long Private Declare Function ExtractAssociatedIcon Lib "shell32.dll" Alias "ExtractAssociatedIconA" (ByVal hInst As Long, ByVal lpIconPath As String, lpiIcon As Long) As Long Private Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Long) As Long Private Declare Function CreatePopupMenu Lib "user32" () As Long Private Declare Function TrackPopupMenuEx Lib "user32" _ (ByVal hMenu As Long, ByVal wFlags As Long, ByVal X As Long, _ ByVal Y As Long, ByVal hwnd As Long, ByVal lptpm As Any) As Long Private Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" _ (ByVal hMenu As Long, ByVal wFlags As Long, _ ByVal wIDNewItem As Long, ByVal lpNewItem As Any) As Long Private Declare Function DestroyMenu Lib "user32" (ByVal hMenu As Long) As Long Private Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As Long Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _ (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _ ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long #End If '*************************************************************************************** '* Constantes * '*************************************************************************************** Private Const MF_STRING = &H0& Private Const MF_SEPARATOR = &H800& Private Const TPM_LEFTALIGN = &H0& Private Const TPM_RETURNCMD = &H100& Private Const TPM_RIGHTBUTTON = &H2& Private Const SW_HIDE = 0 Private Const SW_SHOWNORMAL = 1 Private Const SW_SHOWMINIMIZED = 2 Private Const SW_SHOWMAXIMIZED = 3 Private Const SW_SHOWNA = 8 Private Const SW_SHOWMINNOACTIVE = 7 Private Const NIM_ADD As Long = &H0 Private Const NIM_MODIFY As Long = &H1 Private Const NIM_DELETE As Long = &H2 Private Const NIF_TIP As Long = &H4 Private Const NIF_MESSAGE As Long = &H1 Private Const NIF_ICON As Long = &H2 Private Const NIF_INFO = &H10 Private Const NIIF_NONE = &H0 Private Const NIIF_INFO = &H1 Private Const NIIF_WARNING = &H2 Private Const NIIF_ERROR = &H3 Private Const NIIF_GUID = &H5 Private Const NIIF_ICON_MASK = &HF Private Const NIIF_NOSOUND = &H10 Private Const NOTIFYICON_VERSION = &H3 Private Const WM_MOUSEMOVE = &H200 Private Const WM_LBUTTONDBLCLK = &H203 Private Const WM_LBUTTONDOWN = &H201 Private Const WM_LBUTTONUP = &H202 Private Const WM_RBUTTONDBLCLK = &H206 Private Const WM_RBUTTONDOWN = &H204 Private Const WM_RBUTTONUP = &H205 Private Const WM_MBUTTONDOWN = &H207 Private Const WM_MBUTTONUP = &H208 Private Const WM_MBUTTONDBLCLK = &H209 Private Const LOGPIXELSX As Long = 88 ' Constantes pour nombre de pixels par pouces Private Const WS_EX_APPWINDOW = &H40000 Private Const GWL_EXSTYLE = -20 Private Const NOTIFYICONDATA_V1_SIZE As Long = 88 ' Taille structure avant v5 Private Const NOTIFYICONDATA_V2_SIZE As Long = 488 ' Taille structure à partir de v5 Private Const NIN_BALLOONSHOW = &H402 Private Const NIN_BALLOONHIDE = &H403 Private Const NIN_BALLOONTIMEOUT = &H404 Private Const NIN_BALLOONUSERCLICK = &H405 '*************************************************************************************** '* Enumérations * '*************************************************************************************** Public Enum ESysTrayIcon SystrayNoIcon = NIF_INFO SystrayInformation = NIIF_INFO SystrayWarning = NIIF_WARNING SystrayError = NIIF_ERROR SystrayNoSound = NIIF_NOSOUND End Enum '*************************************************************************************** '* Types * '*************************************************************************************** Private Type VS_FIXEDFILEINFO dwSignature As Long dwStrucVersionl As Integer dwStrucVersionh As Integer dwFileVersionMSl As Integer dwFileVersionMSh As Integer dwFileVersionLSl As Integer dwFileVersionLSh As Integer dwProductVersionMSl As Integer dwProductVersionMSh As Integer dwProductVersionLSl As Integer dwProductVersionLSh As Integer dwFileFlagsMask As Long dwFileFlags As Long dwFileOS As Long dwFileType As Long dwFileSubtype As Long dwFileDateMS As Long dwFileDateLS As Long End Type Private Type POINTAPI X As Long Y As Long End Type Private Type NOTIFYICONDATA cbSize As Long hwnd As LongPtr uID As Long uFlags As Long uCallbackMessage As Long hIcon As Long szTip As String * 128 dwState As Long dwStateMask As Long szInfo As String * 256 uTimeoutAnduVersion As Long szInfoTitle As String * 64 dwInfoFlags As Long End Type ' PT : Window sizing information for object ' used in OBJECTHEADER type. Private Type PT Width As Integer Height As Integer End Type Private Type OBJECTHEADER Signature As Integer ' Type signature (0x1c15). HeaderSize As Integer ' Size of header (sizeof(struct ' OBJECTHEADER) + cchName + ' cchClass). ObjectType As Long ' OLE Object type code (OT_STATIC, ' OT_LINKED, OT_EMBEDDED). NameLen As Integer ' Count of characters in object ' name (CchSz(szName) + 1). ClassLen As Integer ' Count of characters in class ' name (CchSz(szClass) + 1). NameOffset As Integer ' Offset of object name in ' structure (sizeof(OBJECTHEADER)). ClassOffset As Integer ' Offset of class name in ' structure (ibName + cchName). ObjectSize As PT ' Original size of object (see ' code below for value). OleInfo As String * 256 End Type Private Type OLEHEADER OleVersion As Long Format As Long TypeLen As Long End Type ' En-tete d'un fichier icone Private Type ICONDIR idReserved As Integer idType As Integer idCount As Integer End Type ' Données de chaque icone du fichier Private Type ICONDIRENTRY bWidth As Byte bHeight As Byte bColorCount As Byte bReserved As Byte wPlanes As Integer wBitCount As Integer dwBytesInRes As Long dwImageOffset As Long End Type '*************************************************************************************** '* Variables * '*************************************************************************************** Private gNID As NOTIFYICONDATA ' Données du systray Private gStructSize As Long ' Taille de la structure en fonction de la version
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager