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
|
'***************************************************************************************
'* 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 *
'***************************************************************************************
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
'***************************************************************************************
'* 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 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
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
'***************************************************************************************
'* 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 As Long
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 As Long
' 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 As Long
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 As Long
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 As Long, 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") >= 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)
Dim lPtsPerPixel As Single
Dim lhdc As Long
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 As Long
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 As Long
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 |
Partager