home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 6_2008-2009.ISO / data / zips / Icon(s)_Sy2159978142009.psc / ctlSysTrayBalloon.ctl < prev   
Text File  |  2009-08-15  |  52KB  |  1,253 lines

  1. VERSION 5.00
  2. Begin VB.UserControl ctlSysTrayBalloon 
  3.    AutoRedraw      =   -1  'True
  4.    ClientHeight    =   495
  5.    ClientLeft      =   0
  6.    ClientTop       =   0
  7.    ClientWidth     =   1320
  8.    InvisibleAtRuntime=   -1  'True
  9.    Picture         =   "ctlSysTrayBalloon.ctx":0000
  10.    ScaleHeight     =   33
  11.    ScaleMode       =   3  'Pixel
  12.    ScaleWidth      =   88
  13.    ToolboxBitmap   =   "ctlSysTrayBalloon.ctx":16C2
  14. End
  15. Attribute VB_Name = "ctlSysTrayBalloon"
  16. Attribute VB_GlobalNameSpace = False
  17. Attribute VB_Creatable = True
  18. Attribute VB_PredeclaredId = False
  19. Attribute VB_Exposed = False
  20. '-------------------------------------------------------------------------------------------
  21. ' Source : http://www.vbfrance.com/codes/SYSTRAY-BALLON-SEUL-CONTROLE-UTILISATEUR_50355.aspx
  22. '-------------------------------------------------------------------------------------------
  23. ' Codes ayant servis α l'origine :
  24. ' Original de la classe SysTray
  25. '       http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=64701&lngWId=1
  26. ' Original du control utilisateur SubClass
  27. '       http://www.vbfrance.com/code.aspx?ID=47896
  28. '-------------------------------------------------------------------------------------------
  29.  
  30. ' Comportement: Si plusieurs UserControl sont placΘs sur une forme et que vous demandez l'affichage
  31. '               de messages en mΩme temps sur chaque UserControl, Windows buffurise les demandes et
  32. '               affichera les messages les uns derriΦre les autres.
  33.  
  34. ' 2009 07 25 :
  35. '   Animation : Suppression du controle Timer et rΘutilisation du Timer API
  36. '   Animation : PossibilitΘ de faire clignoter l'icone seule (sans autre icone en alternance)
  37. '   Animation : Suppression Property de dΘfinition de vitesse. La vitesse est fournie avec la
  38. '               commande de Start
  39. '   Animation : Ajout propriΘtΘ Get "BlinkIsRunning"
  40. '   SysTray   : A la disparition du message, on supprime puis rΘinitialise l'icone du SysTray
  41. '               Cette manoeuvre dΘsactivait temporairement le SubClassing et supprimait aussi
  42. '               le clignotement en cours --> CrΘation Sub SysTrayRestart pour ne pas toucher
  43. '               au SubClassing
  44. '   GΘnΘral   : Les Read/WriteProperties mΘmorisaient les durΘes (Balloon et Blink), ainsi
  45. '               que les handles des icones.
  46. '               Les durΘes Θtant maintenant fournies avec les commandes Start, il n'est plus
  47. '               nΘcessaire de les mΘmoriser (en mode CrΘation), et mΘmoriser des Handles est
  48. '               dΘconseillΘ --> Suppression des Read/WriteProperties
  49. '   GΘnΘral   : Renommage des fonctions
  50. '   GΘnΘral   : Renommage de l'event "Erreur" en "PgmError"
  51. '   GΘnΘral   : "Animation" remplacΘ par "Blink" (variables et fonctions)
  52. '   GΘnΘral   : Correction - Lors d'un Event de la Souris, repasse la main au UserControl
  53. '               et pas α l'ic⌠ne (fermeture du menu en cas de perte du focus)
  54. '   GΘnΘral   : DΘtection du crash de Explorer pour rΘaffichage de l'icone
  55.  
  56. ' 2009 07 26
  57. '   GΘnΘral   : PossibilitΘ d'utiliser plusieurs UserControl dans un mΩme projet (identification
  58. '               des instances par pseudo constantes indexΘes)
  59. '   GΘnΘral   : Quand on cliquait sur l'icone dans le SysTray, l'image du composant sur la forme
  60. '               qui nous accueille, apparaissait. D√ au SetForground pour Θviter le maintien de
  61. '               de l 'affichage du menu contextuel quand on clique ailleurs.
  62. '               --> Passe le Foreground au Parent au lieu du UserControl
  63. '   GΘnΘral   : DΘtection du crash de Explorer : Notre icone appartenant au SysTray, il Θtait
  64. '               impossible de recevoir des messages. Il aurait donc fallu que ce soit la forme
  65. '               h⌠te qui gΦre cette dΘtection. Comme je veux que le UserControl soit complΦtement
  66. '               indΘpendant, j'ai rajoutΘ un Timer qui surveille le changement de handle du SysTray.
  67.  
  68. ' 2009 07 28
  69. '   GΘnΘral   : Mise en application du partage de mΘmoire (Long) pour dΘterminer les valeurs des
  70. '               constantes de Timer. MΘthode issue de la source de PCPT :
  71. '               http://www.vbfrance.com/codes/PUBLIC-SHARED-SANS-MODULE-VARIABLE-SINGLETON-IDENTIFICATION-INSTANCE_50369.aspx
  72.  
  73. ' 2009 08 05
  74. '   GΘnΘral   : Ajout procΘdure "BalloonTipShowLast" pour rΘafficher le dernier message
  75. '               Cette mΘmorisation sert aussi α la recherche du handle de la popup du message
  76. '   SysTray   : Il y a un problΦme lors du TimeOut d'un message : La fenΩtre ne se referme pas. La
  77. '               solution adoptΘe Θtait de dΘtruire et de recrΘer l'ic⌠ne du SysTray --> ModifiΘ pour
  78. '               utiliser une mΘthode plus propre : On envoie un message α la fenΩtre du message pour
  79. '               simuler un clic utilisateur (dans ce cas, la fermeture est Ok)
  80. '   GΘnΘral   : RemplacΘ les Properties "IconHandle" et "BlinkIconHandle" par "IconPicture" et
  81. '               "BlinkIconPicture" (ΘlΘment fourni = Image au lieu du handle = plus souple c⌠tΘ client)
  82. '               + Suppression de leurs propriΘtΘs Get
  83. '               Nota : dans la dΘfinition de chacune de ces propriΘtΘs, le "As Image" peut Ωtre
  84. '                      remplacΘ par "As Picture" sans problΦme
  85.  
  86. Option Explicit
  87.  
  88. ' The data type for the icon in side the task bar, very simple
  89. Private Type NOTIFYICONDATAW        ' "W" = Version Unicode
  90.     icoSize                 As Long ' 936, et pas 940
  91.     icoHwnd                 As Long
  92.     icoId                   As Long
  93.     icoFlags                As Long
  94.     icoCallbackMessage      As Long
  95.     icoSource               As Long
  96.     icoTooltip(0 To 255)    As Byte ' 256 bytes Unicode = 128 caractΦres "VB"
  97.     icoState                As Long
  98.     icoStateMask            As Long
  99.     szInfo(0 To 511)        As Byte ' 512 bytes Unicode = 256 caractΦres "VB"
  100.     uTimeOutOrVersion       As Long
  101.     szInfoTitle(0 To 127)   As Byte ' 128 bytes Unicode = 64 caractΦres "VB"
  102.     dwInfoFlags             As Long
  103. '    guidItem                As Long ' Ne pas activer, sinon la taille passe α 940 _
  104.                                        et le "Shell_NotifyIconW" plante
  105. End Type
  106.  
  107. ' The structure that contains all the possible types of balloons
  108. Public Enum eBalloonIconTypes
  109.     NIIF_NONE = &H0
  110.     NIIF_INFO = &H1
  111.     NIIF_WARNING = &H2
  112.     NIIF_ERROR = &H3
  113.     NIIF_NOSOUND = &H10
  114. End Enum
  115.  
  116. Private Enum WindowMessageConstants
  117.     WM_ALL = -1
  118.     WM_NULL = &H0
  119.     WM_CREATE = &H1
  120.     WM_DESTROY = &H2
  121.     WM_MOVE = &H3
  122.     WM_SIZE = &H5
  123.     WM_ACTIVATE = &H6
  124.     WM_SETFOCUS = &H7
  125.     WM_KILLFOCUS = &H8
  126.     WM_ENABLE = &HA
  127.     WM_SETREDRAW = &HB
  128.     WM_SETTEXT = &HC
  129.     WM_GETTEXT = &HD
  130.     WM_GETTEXTLENGTH = &HE
  131.     WM_PAINT = &HF
  132.     WM_CLOSE = &H10
  133.     WM_QUERYENDSESSION = &H11
  134.     WM_QUIT = &H12
  135.     WM_QUERYOPEN = &H13
  136.     WM_ERASEBKGND = &H14
  137.     WM_SYSCOLORCHANGE = &H15
  138.     WM_ENDSESSION = &H16
  139.     WM_SHOWWINDOW = &H18
  140.     WM_WININICHANGE = &H1A
  141.     WM_SETTINGCHANGE = &H1A
  142.     WM_DEVMODECHANGE = &H1B
  143.     WM_ACTIVATEAPP = &H1C
  144.     WM_FONTCHANGE = &H1D
  145.     WM_TIMECHANGE = &H1E
  146.     WM_CANCELMODE = &H1F
  147.     WM_SETCURSOR = &H20
  148.     WM_MOUSEACTIVATE = &H21
  149.     WM_CHILDACTIVATE = &H22
  150.     WM_QUEUESYNC = &H23
  151.     WM_GETMINMAXINFO = &H24
  152.     WM_PAINTICON = &H26
  153.     WM_ICONERASEBKGND = &H27
  154.     WM_NEXTDLGCTL = &H28
  155.     WM_SPOOLERSTATUS = &H2A
  156.     WM_DRAWITEM = &H2B
  157.     WM_MEASUREITEM = &H2C
  158.     WM_DELETEITEM = &H2D
  159.     WM_VKEYTOITEM = &H2E
  160.     WM_CHARTOITEM = &H2F
  161.     WM_SETFONT = &H30
  162.     WM_GETFONT = &H31
  163.     WM_SETHOTKEY = &H32
  164.     WM_GETHOTKEY = &H33
  165.     WM_QUERYDRAGICON = &H37
  166.     WM_COMPAREITEM = &H39
  167.     WM_GETOBJECT = &H3D
  168.     WM_COMPACTING = &H41
  169.     WM_WINDOWPOSCHANGING = &H46
  170.     WM_WINDOWPOSCHANGED = &H47
  171.     WM_POWER = &H48
  172.     WM_COPYDATA = &H4A
  173.     WM_CANCELJOURNAL = &H4B
  174.     WM_NOTIFY = &H4E
  175.     WM_INPUTLANGCHANGEREQUEST = &H50
  176.     WM_INPUTLANGCHANGE = &H51
  177.     WM_TCARD = &H52
  178.     WM_HELP = &H53
  179.     WM_USERCHANGED = &H54
  180.     WM_NOTIFYFORMAT = &H55
  181.     WM_CONTEXTMENU = &H7B
  182.     WM_STYLECHANGING = &H7C
  183.     WM_STYLECHANGED = &H7D
  184.     WM_DISPLAYCHANGE = &H7E
  185.     WM_GETICON = &H7F
  186.     WM_SETICON = &H80
  187.     WM_NCCREATE = &H81
  188.     WM_NCDESTROY = &H82
  189.     WM_NCCALCSIZE = &H83
  190.     WM_NCHITTEST = &H84
  191.     WM_NCPAINT = &H85
  192.     WM_NCACTIVATE = &H86
  193.     WM_GETDLGCODE = &H87
  194.     WM_SYNCPAINT = &H88
  195.     WM_NCMOUSEMOVE = &HA0
  196.     WM_NCLBUTTONDOWN = &HA1
  197.     WM_NCLBUTTONUP = &HA2
  198.     WM_NCLBUTTONDBLCLK = &HA3
  199.     WM_NCRBUTTONDOWN = &HA4
  200.     WM_NCRBUTTONUP = &HA5
  201.     WM_NCRBUTTONDBLCLK = &HA6
  202.     WM_NCMBUTTONDOWN = &HA7
  203.     WM_NCMBUTTONUP = &HA8
  204.     WM_NCMBUTTONDBLCLK = &HA9
  205.     WM_KEYFIRST = &H100
  206.     WM_KEYDOWN = &H100
  207.     WM_KEYUP = &H101
  208.     WM_CHAR = &H102
  209.     WM_DEADCHAR = &H103
  210.     WM_SYSKEYDOWN = &H104
  211.     WM_SYSKEYUP = &H105
  212.     WM_SYSCHAR = &H106
  213.     WM_SYSDEADCHAR = &H107
  214.     WM_KEYLAST = &H108
  215.     WM_IME_STARTCOMPOSITION = &H10D
  216.     WM_IME_ENDCOMPOSITION = &H10E
  217.     WM_IME_COMPOSITION = &H10F
  218.     WM_IME_KEYLAST = &H10F
  219.     WM_INITDIALOG = &H110
  220.     WM_COMMAND = &H111
  221.     WM_SYSCOMMAND = &H112
  222.     WM_TIMER = &H113
  223.     WM_HSCROLL = &H114
  224.     WM_VSCROLL = &H115
  225.     WM_INITMENU = &H116
  226.     WM_INITMENUPOPUP = &H117
  227.     WM_MENUSELECT = &H11F
  228.     WM_MENUCHAR = &H120
  229.     WM_ENTERIDLE = &H121
  230.     WM_MENURBUTTONUP = &H122
  231.     WM_MENUDRAG = &H123
  232.     WM_MENUGETOBJECT = &H124
  233.     WM_UNINITMENUPOPUP = &H125
  234.     WM_MENUCOMMAND = &H126
  235.     WM_CTLCOLORMSGBOX = &H132
  236.     WM_CTLCOLOREDIT = &H133
  237.     WM_CTLCOLORLISTBOX = &H134
  238.     WM_CTLCOLORBTN = &H135
  239.     WM_CTLCOLORDLG = &H136
  240.     WM_CTLCOLORSCROLLBAR = &H137
  241.     WM_CTLCOLORSTATIC = &H138
  242.     WM_MOUSEFIRST = &H200
  243.     WM_MOUSEMOVE = &H200
  244.     WM_LBUTTONDOWN = &H201
  245.     WM_LBUTTONUP = &H202
  246.     WM_LBUTTONDBLCLK = &H203
  247.     WM_RBUTTONDOWN = &H204
  248.     WM_RBUTTONUP = &H205
  249.     WM_RBUTTONDBLCLK = &H206
  250.     WM_MBUTTONDOWN = &H207
  251.     WM_MBUTTONUP = &H208
  252.     WM_MBUTTONDBLCLK = &H209
  253.     WM_MOUSEWHEEL = &H20A
  254.     WM_PARENTNOTIFY = &H210
  255.     WM_ENTERMENULOOP = &H211
  256.     WM_EXITMENULOOP = &H212
  257.     WM_NEXTMENU = &H213
  258.     WM_SIZING = &H214
  259.     WM_CAPTURECHANGED = &H215
  260.     WM_MOVING = &H216
  261.     WM_DEVICECHANGE = &H219
  262.     WM_MDICREATE = &H220
  263.     WM_MDIDESTROY = &H221
  264.     WM_MDIACTIVATE = &H222
  265.     WM_MDIRESTORE = &H223
  266.     WM_MDINEXT = &H224
  267.     WM_MDIMAXIMIZE = &H225
  268.     WM_MDITILE = &H226
  269.     WM_MDICASCADE = &H227
  270.     WM_MDIICONARRANGE = &H228
  271.     WM_MDIGETACTIVE = &H229
  272.     WM_MDISETMENU = &H230
  273.     WM_ENTERSIZEMOVE = &H231
  274.     WM_EXITSIZEMOVE = &H232
  275.     WM_DROPFILES = &H233
  276.     WM_MDIREFRESHMENU = &H234
  277.     WM_IME_SETCONTEXT = &H281
  278.     WM_IME_NOTIFY = &H282
  279.     WM_IME_CONTROL = &H283
  280.     WM_IME_COMPOSITIONFULL = &H284
  281.     WM_IME_SELECT = &H285
  282.     WM_IME_CHAR = &H286
  283.     WM_IME_REQUEST = &H288
  284.     WM_IME_KEYDOWN = &H290
  285.     WM_IME_KEYUP = &H291
  286.     WM_MOUSEHOVER = &H2A1
  287.     WM_MOUSELEAVE = &H2A3
  288.     WM_CUT = &H300
  289.     WM_COPY = &H301
  290.     WM_PASTE = &H302
  291.     WM_CLEAR = &H303
  292.     WM_UNDO = &H304
  293.     WM_RENDERFORMAT = &H305
  294.     WM_RENDERALLFORMATS = &H306
  295.     WM_DESTROYCLIPBOARD = &H307
  296.     WM_DRAWCLIPBOARD = &H308
  297.     WM_PAINTCLIPBOARD = &H309
  298.     WM_VSCROLLCLIPBOARD = &H30A
  299.     WM_SIZECLIPBOARD = &H30B
  300.     WM_ASKCBFORMATNAME = &H30C
  301.     WM_CHANGECBCHAIN = &H30D
  302.     WM_HSCROLLCLIPBOARD = &H30E
  303.     WM_QUERYNEWPALETTE = &H30F
  304.     WM_PALETTEISCHANGING = &H310
  305.     WM_PALETTECHANGED = &H311
  306.     WM_HOTKEY = &H312
  307.     WM_PRINT = &H317
  308.     WM_PRINTCLIENT = &H318
  309.     WM_HANDHELDFIRST = &H358
  310.     WM_HANDHELDLAST = &H35F
  311.     WM_AFXFIRST = &H360
  312.     WM_AFXLAST = &H37F
  313.     WM_PENWINFIRST = &H380
  314.     WM_PENWINLAST = &H38F
  315.     WM_USER = &H400
  316.     WM_APP = &H8000
  317. End Enum
  318.  
  319. Private Const GWL_WNDPROC = (-4)
  320.  
  321. ' Shell_notify styles
  322. Private Const NIS_HIDDEN = &H1
  323. Private Const NIS_SHAREDICON = &H2
  324. ' The events we can extract from the balloons
  325. Private Const NIN_BALLOONSHOW = (WM_USER + 2)
  326. Private Const NIN_BALLOONHIDE = (WM_USER + 3)
  327. Private Const NIN_BALLOONTIMEOUT = (WM_USER + 4)
  328. Private Const NIN_BALLOONUSERCLICK = (WM_USER + 5)
  329. ' Constants releated to adding and removing the icon from the task tray and response level
  330. Private Const NIF_ICON = &H2
  331. Private Const NIF_MESSAGE = &H1
  332. Private Const NIF_TIP = &H4
  333. Private Const NIF_INFO = &H10
  334. ' These inform windows what action we are about to perform with the icon
  335. Private Const NIM_ADD = &H0
  336. Private Const NIM_MODIFY = &H1
  337. Private Const NIM_DELETE = &H2
  338. Private Const NIM_SETVERSION = &H4
  339.  
  340. Private Const NOTIFYICON_VERSION = &H3
  341.  
  342. ' MΘthode de variable partagΘe en Singleton
  343. Private Const SECTION_MAP_READ      As Long = &H4
  344. Private Const SECTION_MAP_WRITE     As Long = &H2
  345. Private Const FILE_MAP_READ         As Long = SECTION_MAP_READ
  346. Private Const FILE_MAP_WRITE        As Long = SECTION_MAP_WRITE
  347. Private Const INVALID_HANDLE_VALUE  As Long = &HFFFFFFFF
  348. Private Const PAGE_READWRITE        As Long = &H4
  349. ' Variable partagΘe : Ce nom de reconnaissance est commun α tous les UC de mon type
  350. '   (indΘpendant de l'application qui le supporte)
  351. Private Const OBJECTNAME            As String = "CodesSources_ctlSysTrayBalloon"
  352.  
  353. ' Message privΘ dΘdiΘ au Tray (filtrage des ΘvΦnements)
  354. Private Const WM_USER_TRAY = WM_USER + 1
  355.  
  356. ' APIs
  357. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
  358. Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
  359. Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  360. Private Declare Function Shell_NotifyIconW Lib "shell32.dll" (ByVal dwMessage As Long, lpData As NOTIFYICONDATAW) As Long
  361. Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
  362. Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
  363. Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
  364. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  365.  
  366. ' APIs pour la simulation du clic sur message lors d'un TimeOut
  367. Private Const GW_CHILD = 5
  368. Private Const GW_HWNDNEXT = 2
  369. Private Const TOOLTIPS_CLASSA As String = "tooltips_class32"
  370. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long
  371. Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
  372. Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
  373. Private Declare Function GetDesktopWindow Lib "user32" () As Long
  374.  
  375. ' MΘthode de variable partagΘe en Singleton (merci PCPT @ http://www.vbfrance.com/codes/PUBLIC-SHARED-SANS-MODULE-VARIABLE-SINGLETON-IDENTIFICATION-INSTANCE_50369.aspx )
  376. 'Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
  377. Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
  378. Private Declare Function CreateFileMapping Lib "kernel32.dll" Alias "CreateFileMappingA" (ByVal hFile As Long, ByRef lpFileMappigAttributes As Any, ByVal flProtect As Long, ByVal dwMaximumSizeHigh As Long, ByVal dwMaximumSizeLow As Long, ByVal lpName As String) As Long
  379. Private Declare Function MapViewOfFile Lib "kernel32.dll" (ByVal hFileMappingObject As Long, ByVal dwDesiredAccess As Long, ByVal dwFileOffsetHigh As Long, ByVal dwFileOffsetLow As Long, ByVal dwNumberOfBytesToMap As Long) As Long
  380. Private Declare Function OpenFileMapping Lib "kernel32.dll" Alias "OpenFileMappingA" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal lpName As String) As Long
  381. Private Declare Function UnmapViewOfFile Lib "kernel32.dll" (ByRef lpBaseAddress As Any) As Long
  382.  
  383. ' Le code assembleur
  384. Private mAsm(63)                As Byte
  385. ' Adresse de l'ancien CallBack
  386. Private mOldCallBackProc        As Long
  387. Private lShellTrayHandle        As Long  ' MΘmoire du handle du Shell_TrayWnd pour test crash Explorer
  388. Private bCrashTimerRunning      As Boolean
  389.  
  390. ' MΘthode de variable partagΘe en Singleton
  391. Private myID                    As Long     ' Identifiant de notre instance de control (unique dans tout le systΦme)
  392. Private bAutoDecrement          As Boolean  ' Sera passΘ α False dans l'init (on veut garder un ID unique)
  393.  
  394. ' Ces pseudo constantes sont initialisΘes dans "UserControl_ReadProperties"
  395. ' Elles identifient le composant parmi les autres composants du mΩme type
  396. ' Cette identification est nΘcessaire pour le SubClassing, pour Ωtre s√r que le message
  397. '   reτu nous est bien destinΘ
  398. ' "mAPP_SYSTRAY_ID" est renvoyΘ dans wParam, mais il n'y a que nous qui allons recevoir
  399. '   les messages issus de notre ic⌠ne, cela ne sert pas α grand chose
  400. Private mAPP_SYSTRAY_ID         As Long
  401. Private mAPP_TIMER_EVENT_ID_0   As Long
  402. Private mAPP_TIMER_EVENT_ID_1   As Long
  403. Private mAPP_TIMER_EVENT_ID_2   As Long
  404.  
  405. ' Handle de l'icone α afficher dans le SysTray
  406. Private mIconHandle             As Long
  407.  
  408. ' MΘmo dernier message
  409. Private mMessageTitle           As String
  410. Private mMessageText            As String
  411. Private mMessageStyle           As eBalloonIconTypes
  412.  
  413. ' DurΘe du Timer du Balloon
  414. Private mBalloonMilliSeconds    As Long
  415. ' Etat du Timer du Balloon
  416. Private bBalloonTmrRunning      As Boolean
  417. Private bBallonClickForTimeout  As Boolean
  418.  
  419. ' Handle de l'icone α afficher en alternance dans le SysTray (Blink)
  420. Private mBlinkIconHandle        As Long    ' optionel
  421. ' DurΘe du Timer de cycle du Flash
  422. Private mBlinkMilliSeconds      As Long
  423. ' Etat du Timer de cycle du Flash
  424. Private bBlinkTmrRunning        As Boolean
  425.  
  426. ' These are modular level variables that allow us to determine certain aspects of the icon
  427. ' and share control of the forms events
  428. Private mIconLoaded             As Boolean
  429. Private mIconData               As NOTIFYICONDATAW
  430.  
  431. ' Les evenements retenus pour renvoie α la forme qui nous hΘberge
  432. Public Event MouseMove()    ' pas beaucoup d'intΘrΩt puisque ce c'est le Move sur notre ic⌠ne uniquement
  433. Public Event Click()
  434. Public Event DblClick(Button As Integer)
  435. Public Event MouseDown(Button As Integer)
  436. Public Event MouseUp(Button As Integer)
  437. Public Event BalloonClosed()
  438. Public Event BalloonClicked()
  439. Public Event BalloonShow()
  440. Public Event BalloonTimeOut()
  441. Public Event PgmError(Source As String, Code As Long, Description As String)
  442. '
  443.  
  444. ' ######################################################################################################################
  445. ' /!\ NE PAS DEPLACER CETTE FONCTION /!\ '
  446. '----------------------------------------'
  447. ' Cette fonction doit rester la premiere '
  448. ' fonction "public" du module de classe  '
  449. '----------------------------------------'
  450. Public Function CallBackProc(ByVal hwnd As Long, _
  451.                              ByVal uMsg As Long, _
  452.                              ByVal wParam As Long, _
  453.                              ByVal lParam As Long) As Long
  454.     
  455.     Dim Follow As Boolean
  456.     
  457. 'Debug.Print Time, "CallBackProc", "hwnd "; Hex(hwnd), "Msg "; Hex(uMsg), "wP "; Hex(wParam), "lP "; Hex(lParam)
  458.     
  459.     If mOldCallBackProc = 0 Then Exit Function
  460.     
  461.     ' Par defaut le controle gΦre l'ΘvΦnement
  462.     ' A mettre α False quand on ne veut pas propager l'ΘvΦnement α l'objet original
  463.     Follow = True
  464.     
  465.     Select Case uMsg
  466.     
  467.         Case WM_TIMER
  468.             If wParam = mAPP_TIMER_EVENT_ID_0 Then
  469.                 ' Teste si l'explorer a crashΘ en regardant si son handle a ΘtΘ modifiΘ
  470.                 Call CrashTimerProc
  471.                 
  472.             ElseIf wParam = mAPP_TIMER_EVENT_ID_1 Then
  473.                 ' Timer de fin d'apparition du Balloon
  474.                 Call BalloonTimerStop
  475.                 Call BalloonTipClose
  476.             
  477.             ElseIf wParam = mAPP_TIMER_EVENT_ID_2 Then
  478.                 ' Timer de fin d'un cycle d'animation
  479.                 Call BlinkSwapIcons
  480.             End If
  481.             Follow = False
  482.         
  483.         Case WM_USER_TRAY
  484.             ' Le CallBack dΘfini dans l'objet mIconData permet de filtrer.
  485.             ' Les ΘvΦnements sont dans lParam
  486.             Select Case lParam
  487.                 '----------------- Balloon
  488.                 ' Ballon, qui n'est pas d'Alsace, dommage
  489.                 Case NIN_BALLOONSHOW        ' 402
  490.                     ' Un Balloon vient d'Ωtre initialisΘ
  491.                     Call BalloonTimerStart
  492.                     RaiseEvent BalloonShow
  493.  
  494.                 Case NIN_BALLOONUSERCLICK   ' 405
  495.                     ' L'utilisateur vient de cliquer sur le ballon
  496.                     If Not bBallonClickForTimeout Then
  497.                         ' Cas normal
  498.                         RaiseEvent BalloonClicked
  499.                     Else
  500.                         ' Cas o∙ c'est le programme qui a cliquΘ pour
  501.                         '   faire disparaitre le message en fin de TimeOut
  502.                         RaiseEvent BalloonTimeOut
  503.                     End If
  504.  
  505.                 Case NIN_BALLOONHIDE        ' 403
  506.                     ' Fin du ballon = TimeOut (ne fonctionne pas ici)
  507.                     Call BalloonTimerStop
  508.                     RaiseEvent BalloonTimeOut
  509.  
  510.                 Case NIN_BALLOONTIMEOUT     ' 404
  511.                     ' FermΘ par l'utilisateur
  512.                     ' Non non, il n'y a pas d'erreur : L'event "TimeOut" apparait
  513.                     '   quand on ferme volontairement le message
  514.                     Call BalloonTimerStop
  515.                     RaiseEvent BalloonClosed
  516.                 
  517.                 '----------------- Mouse
  518.                 ' DΘplacement sur l'icone (bof)
  519.                 Case WM_MOUSEMOVE
  520.                     RaiseEvent MouseMove
  521.                 
  522.                 ' Bouton gauche
  523.                 Case WM_LBUTTONDBLCLK
  524.                     ' Passe notre container en avant plan pour Ωtre s√r que l'Θventuel menu
  525.                     '   disparaisse si la souris clique ailleurs (problΦme connu)
  526.                     Call SetForegroundWindow(UserControl.Parent.hwnd)
  527.                     RaiseEvent DblClick(1)
  528.                 Case WM_LBUTTONUP
  529.                     ' Voir explication ci-dessus
  530.                     Call SetForegroundWindow(UserControl.Parent.hwnd)
  531.                     RaiseEvent Click
  532.                     RaiseEvent MouseUp(1)
  533.                 Case WM_LBUTTONDOWN
  534.                     ' Voir explication ci-dessus
  535.                     Call SetForegroundWindow(UserControl.Parent.hwnd)
  536.                     RaiseEvent MouseDown(1)
  537.                     
  538.                 ' Bouton droit
  539.                 Case WM_RBUTTONDBLCLK
  540.                     ' Voir explication ci-dessus
  541.                     Call SetForegroundWindow(UserControl.Parent.hwnd)
  542.                     RaiseEvent DblClick(2)
  543.                 Case WM_RBUTTONUP
  544.                     ' Voir explication ci-dessus
  545.                     Call SetForegroundWindow(UserControl.Parent.hwnd)
  546.                     RaiseEvent MouseUp(2)
  547.                 Case WM_RBUTTONDOWN
  548.                     ' Voir explication ci-dessus
  549.                     Call SetForegroundWindow(UserControl.Parent.hwnd)
  550.                     RaiseEvent MouseDown(2)
  551.                     
  552.                 ' Bouton central
  553.                 Case WM_MBUTTONDBLCLK
  554.                     ' Voir explication ci-dessus
  555.                     Call SetForegroundWindow(UserControl.Parent.hwnd)
  556.                     RaiseEvent DblClick(4)
  557.                 Case WM_MBUTTONUP
  558.                     ' Voir explication ci-dessus
  559.                     Call SetForegroundWindow(UserControl.Parent.hwnd)
  560.                     RaiseEvent MouseUp(4)
  561.                 Case WM_MBUTTONDOWN
  562.                     ' Voir explication ci-dessus
  563.                     Call SetForegroundWindow(UserControl.Parent.hwnd)
  564.                     RaiseEvent MouseDown(4)
  565.                 
  566.                 Case Else
  567.                     Debug.Print "## Event reτu non traitΘ. uMsg "; Hex(uMsg), "wParam "; Hex(wParam), "lParam "; Hex(lParam)
  568.             End Select
  569.     End Select
  570.     ' Si l'evenement doit etre transmis α la fonction CallBackProc originale
  571.     If Follow = True Then
  572.         CallBackProc = CallWindowProc(mOldCallBackProc, hwnd, uMsg, wParam, lParam)
  573.     End If
  574.  
  575. End Function
  576.  
  577.  
  578. ' ######################################################################################################################
  579. ' UserControl
  580.  
  581. Private Sub UserControl_Initialize()
  582.     
  583.     '####### Code assembleur
  584.     Dim Ofs As Long
  585.     Dim Ptr As Long
  586.     
  587.     '-----  Structure pour retrouver l'adresse de la "Me.CallBackProc" (1Φre procΘdure)
  588.     CopyMemory Ptr, ByVal (ObjPtr(Me)), 4
  589.     CopyMemory Ptr, ByVal (Ptr + 489 * 4), 4
  590.     ' CrΘe la veritable fonction CallBackProc (α optimiser)
  591.     Ofs = VarPtr(mAsm(0))
  592.     MovL Ofs, &H424448B            '8B 44 24 04          mov         eax,dword ptr [esp+4]
  593.     MovL Ofs, &H8245C8B            '8B 5C 24 08          mov         ebx,dword ptr [esp+8]
  594.     MovL Ofs, &HC244C8B            '8B 4C 24 0C          mov         ecx,dword ptr [esp+0Ch]
  595.     MovL Ofs, &H1024548B           '8B 54 24 10          mov         edx,dword ptr [esp+10h]
  596.     MovB Ofs, &H68                 '68 44 33 22 11       push        Offset RetVal
  597.     MovL Ofs, VarPtr(mAsm(59))
  598.     MovB Ofs, &H52                 '52                   push        edx
  599.     MovB Ofs, &H51                 '51                   push        ecx
  600.     MovB Ofs, &H53                 '53                   push        ebx
  601.     MovB Ofs, &H50                 '50                   push        eax
  602.     MovB Ofs, &H68                 '68 44 33 22 11       push        ObjPtr(Me)
  603.     MovL Ofs, ObjPtr(Me)
  604.     MovB Ofs, &HE8                 'E8 1E 04 00 00       call        Me.CallBackProc
  605.     MovL Ofs, Ptr - Ofs - 4
  606.     MovB Ofs, &HA1                 'A1 20 20 40 00       mov         eax,RetVal
  607.     MovL Ofs, VarPtr(mAsm(59))
  608.     MovL Ofs, &H10C2               'C2 10 00             ret         10h
  609.  
  610. End Sub
  611.  
  612. Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
  613.  
  614.     '####### MΘthode de variable partagΘe en Singleton :
  615.     ' Pas de dΘcrΘment lors de la fermeture car ce dΘcrΘment ne fait que dΘcompter la variable
  616.     ' Dans notre cas, on a besoin d'un ID unique qui ne sera pas rΘutilisable par un autre UC
  617.     ' La variable commune est un compteur/dΘcompteur
  618.     ' Il est donc normal que la valeur de l'ID ne fasse que s'incrΘmenter au fur et α mesure
  619.     '   de son utilisation, mΩme entre deux fermetures du programme
  620.     bAutoDecrement = False
  621.     ' DΘfinition de notre ID
  622.     myID = SingletonIncrement(OBJECTNAME)
  623.     ' Calcule des valeurs des constantes α utiliser :
  624.     '   1000 : NumΘro de dΘpart
  625.     '      4 : Nombre de "constantes" α choisir par instance
  626.     mAPP_SYSTRAY_ID = 1000 + (4 * (myID - 1))
  627.     mAPP_TIMER_EVENT_ID_0 = mAPP_SYSTRAY_ID + 1
  628.     mAPP_TIMER_EVENT_ID_1 = mAPP_SYSTRAY_ID + 2
  629.     mAPP_TIMER_EVENT_ID_2 = mAPP_SYSTRAY_ID + 3
  630. 'Debug.Print "ID : "; myID, UserControl.Ambient.DisplayName, mAPP_SYSTRAY_ID, mAPP_TIMER_EVENT_ID_0, mAPP_TIMER_EVENT_ID_1, mAPP_TIMER_EVENT_ID_2
  631.  
  632. End Sub
  633.  
  634. ' Arrete le SubClassing
  635. Private Sub UserControl_Terminate()
  636.     ' If the icon is still in the tray, remove it
  637.     If mIconLoaded = True Then Call SysTrayRemoveIcon
  638.     StopSubclassing
  639.     If bAutoDecrement Then Call SingletonDecrement(OBJECTNAME)
  640. End Sub
  641.  
  642. Private Sub UserControl_Resize()
  643.     UserControl.Width = 1215    ' pour le comportement de l'icone
  644.     UserControl.Height = 375    ' de notre Ctrl sur la forme
  645. End Sub
  646.  
  647.  
  648. ' ######################################################################################################################
  649. ' PropriΘtΘs
  650. '                                                             ------- IconPicture
  651. Public Property Set IconPicture(ByVal NewValue As Image)      ' ou As Picture
  652.     ' MΘmorise le handle de cette icone
  653.     If mIconHandle <> NewValue.Picture.Handle Then
  654.         mIconHandle = NewValue.Picture.Handle
  655.         mIconData.icoSource = NewValue
  656.         If mIconLoaded Then Call SysTrayIconRefresh
  657.     End If
  658. End Property
  659. '                                                             ------- BlinkIconPicture
  660. Public Property Set BlinkIconPicture(ByVal NewValue As Image) ' ou As Picture
  661.     mBlinkIconHandle = NewValue.Picture.Handle
  662. End Property
  663. '                                                             ------- Tooltip
  664. Public Property Get Tooltip() As String
  665.     ' Simply return the tool tip
  666.     Tooltip = mIconData.icoTooltip
  667. End Property
  668. Public Property Let Tooltip(Message128 As String)
  669.     ' Ensure the delimiter of null is kept here
  670.     ConvertUnicodeStringToArray Message128, mIconData.icoTooltip, 256
  671.     If mIconLoaded Then Call SysTrayIconRefresh
  672. End Property
  673. '                                                             ------- BlinkIsRunning
  674. Public Property Get BlinkIsRunning() As Boolean
  675.     BlinkIsRunning = bBlinkTmrRunning
  676. End Property
  677. '                                                             ------- ID (identifiant unique)
  678. Public Property Get ID() As Long
  679.     ID = myID
  680. End Property
  681.  
  682.  
  683. ' ######################################################################################################################
  684. ' MΘthodes
  685.  
  686. Public Function SysTrayAddIcon() As Boolean
  687.  
  688.     ' Ajoute notre ic⌠ne dans la barre des tΓches
  689.     
  690.     On Error GoTo ErrorHandler
  691.     
  692.     If mIconLoaded = False Then
  693.         If Initialize Then
  694.             mIconData.icoFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
  695.             ' On peut faire un Add mΩme si elle est dΘjα chargΘe
  696.             If Shell_NotifyIconW(NIM_ADD, mIconData) = 1 Then
  697.                 Call Shell_NotifyIconW(NIM_SETVERSION, mIconData)
  698.             End If
  699.             Call StartSubclassing
  700.             ' TΘmoin du SysTray chargΘ
  701.             mIconLoaded = True
  702.             ' Renvoie un Ok
  703.             SysTrayAddIcon = True
  704.         End If
  705.     Else
  706.         RaiseEvent PgmError("SysTrayAddIcon", -1, "Ic⌠ne standard non dΘfinie")
  707.     End If
  708.     Exit Function
  709.     
  710. ErrorHandler:
  711.     ' ProblΦme
  712.     SysTrayAddIcon = False
  713.     RaiseEvent PgmError("SysTrayAddIcon", Err.Number, Err.Description)
  714. End Function
  715.  
  716. Public Function SysTrayRemoveIcon()
  717.     
  718.     ' Supprime l'ic⌠ne de la barre des tΓches
  719.     
  720.     On Error GoTo ErrorHandler
  721.     
  722.     If mIconLoaded Then
  723.         ' Stoppe Θventuel balloon et clignotement
  724.         Call BalloonTimerStop
  725.         Call BlinkTimerStop
  726.         ' Supprime l'ic⌠ne de la barre des tΓches
  727.         Call Shell_NotifyIconW(NIM_DELETE, mIconData)
  728.         mIconLoaded = False
  729.         Call StopSubclassing
  730.         ' Renvoie Ok
  731.         SysTrayRemoveIcon = True
  732.     Else
  733.         RaiseEvent PgmError("SysTrayRemoveIcon", -1, "SysTray non chargΘ")
  734.     End If
  735.     Exit Function
  736.     
  737. ErrorHandler:
  738.     ' ProblΦme
  739.     SysTrayRemoveIcon = False
  740.     RaiseEvent PgmError("SysTrayRemoveIcon", Err.Number, Err.Description)
  741. End Function
  742.  
  743. Public Function BalloonTipShow(ByVal Title64Unicode As String, _
  744.                                Optional ByVal Message256Unicode As String = "", _
  745.                                Optional ByVal Style As eBalloonIconTypes = NIIF_NONE, _
  746.                                Optional ByVal Timeout_mSec As Long = 0) As Boolean
  747.     
  748.     ' You must know the following in order to
  749.     ' use this feature properly:
  750.     
  751.     '      If the timeout is bigger than the systems maximum then it will be brought down.
  752.     '      (Typically, the maximum is 30 seconds)
  753.     
  754.     '      If the timeout is less than the systems minimum then it will be raised upwards.
  755.     '      (Typically, the minimum is 10 seconds)
  756.     
  757.     On Error GoTo ErrorHandler
  758.     
  759.     If mIconLoaded Then
  760.         ' DurΘe (si) : Timer sera dΘclenchΘ dans WinProc sur NIN_BALLOONSHOW
  761.         mBalloonMilliSeconds = Timeout_mSec
  762.         ' MΘmorise le message
  763.         mMessageTitle = Title64Unicode
  764.         mMessageText = Message256Unicode
  765.         mMessageStyle = Style
  766.         
  767.         With mIconData
  768.             ' Convert the title and message into an array
  769.             ConvertUnicodeStringToArray Message256Unicode, .szInfo, 512
  770.             ConvertUnicodeStringToArray Title64Unicode, .szInfoTitle, 128
  771.             
  772.             ' Store the timeout value here and the icon
  773.             .uTimeOutOrVersion = Timeout_mSec     ' ne sert α rien, c'est le Timer qui s'en occupera
  774.             .dwInfoFlags = Style
  775.             .icoFlags = NIF_INFO
  776.         End With
  777.         
  778.         ' Update the icon with the new information
  779.         Shell_NotifyIconW NIM_MODIFY, mIconData
  780.         
  781.         ' Completed it correctly
  782.         BalloonTipShow = True
  783.     Else
  784.         RaiseEvent PgmError("BalloonTipShow", -1, "SysTray non chargΘ")
  785.     End If
  786.     Exit Function
  787.  
  788. ErrorHandler:
  789.     ' ProblΦme
  790.     BalloonTipShow = False
  791.     RaiseEvent PgmError("BalloonTipShow", Err.Number, Err.Description)
  792. End Function
  793.  
  794. Public Sub BalloonTipShowLast()
  795.     ' RΘaffiche le dernier message mΘmorisΘ
  796.     If mMessageTitle <> "" And mMessageText <> "" And mBalloonMilliSeconds <> 0 Then
  797.         Call BalloonTipShow(mMessageTitle, mMessageText, mMessageStyle, mBalloonMilliSeconds)
  798.     End If
  799. End Sub
  800.  
  801. Public Sub BalloonTipClose()
  802.  
  803.     Dim r As Long
  804.     
  805.     On Error GoTo ErrorHandler
  806.     
  807. '    ' Bon. Avec une structure NOTIFYICONDATA (sans le W final), ces instructions suppriment
  808. '    '   bien le message, mais avec le W, τa ne marche pas, en tous les cas, dans un contr⌠le
  809. '    '   utilisateur, je pense que le problΦme vient de lα.
  810. '    If mIconLoaded Then
  811. '        mIconData.szInfo(0) = 0
  812. '        mIconData.szInfoTitle(0) = 0
  813. '        mIconData.dwInfoFlags = NIIF_NONE
  814. '        mIconData.icoFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
  815. '        Shell_NotifyIconW NIM_MODIFY, mIconData
  816. '    End If
  817.     
  818.     ' Solution de secours :
  819.     If mIconLoaded Then
  820.         ' La fermeture du message fonctionne quand on clique dessus.
  821.         ' On va donc simuler un click afin de fermer le message
  822.         ' On recherche le handle de la fenΩtre de message
  823.         r = FindMessageObject(mMessageText)
  824.         If r > 0 Then
  825.             ' Ce boolΘen permettra de savoir si le clic est d√ au programme
  826.             bBallonClickForTimeout = True
  827.             ' Envoie le message au message
  828.             Call SendMessage(r, WM_MBUTTONDOWN, ByVal 0&, ByVal 0&)
  829.             Call SendMessage(r, WM_MBUTTONUP, ByVal 0&, ByVal 0&)
  830.             bBallonClickForTimeout = False
  831.         Else
  832.             ' FenΩtre message non trouvΘe, peut Ωtre qu'elle n'est dΘjα plus affichΘe
  833.         End If
  834.     End If
  835.     Exit Sub
  836.     
  837. ErrorHandler:
  838.     ' ProblΦme
  839.     RaiseEvent PgmError("BalloonTipClose", Err.Number, Err.Description)
  840. End Sub
  841.  
  842. Public Sub BlinkStart(ByVal CycleMilliSeconds As Long)
  843.     ' Vitesse limite
  844.     If CycleMilliSeconds < 200 Then CycleMilliSeconds = 200
  845.     ' MΘmorise la vitesse demandΘe
  846.     mBlinkMilliSeconds = CycleMilliSeconds
  847.     If mIconLoaded Then
  848.         ' ArrΩte Θventuel clignotement en cours
  849.         If bBlinkTmrRunning Then Call BlinkTimerStop
  850.         ' DΘmarre le Timer
  851.         Call BlinkTimerStart
  852.     Else
  853.         RaiseEvent PgmError("BlinkStart", -1, "SysTray non dΘmarrΘ")
  854.     End If
  855. End Sub
  856.  
  857. Public Sub BlinkStop()
  858.     ' Stoppe le Timer
  859.     Call BlinkTimerStop
  860.     ' Remet l'icone standard
  861.     mIconData.icoSource = mIconHandle
  862.     If mIconLoaded Then Call SysTrayIconRefresh
  863. End Sub
  864.  
  865. ' ######################################################################################################################
  866. ' MΘthodes pour l'utilisation de Singleton
  867.  
  868. '   *- METHODE INCREMENT -*
  869. Friend Function SingletonIncrement(ByVal sSpaceName As String) As Long
  870. '   incrΘmente la valeur LONG partagΘe, retourne cette valeur
  871. '   mΘthode α appeler une seule fois (par la classe ou le usercontrol lui-mΩme, lors de sa crΘation)
  872. '   retour α conserver durant la durΘe de vie de l'instance (variable privΘe ou lecture seule)
  873.  
  874.     Static iSingleCall  As Integer
  875.     Dim lFM             As Long
  876.     Dim lRet            As Long
  877.     
  878. '   un seul appel de fonction par instance
  879.     iSingleCall = iSingleCall + 1
  880.     
  881.     If iSingleCall = 1 Then
  882. '       filemapping
  883.         lFM = OpenFileMapping(FILE_MAP_READ, 0, sSpaceName)
  884.  
  885.         If lFM = 0 Then
  886. '           mapping fermΘ = premiΦre utilisation. crΘation du mapping
  887.             lFM = CreateFileMapping(INVALID_HANDLE_VALUE, ByVal 0&, PAGE_READWRITE, 0&, 4&, sSpaceName)
  888.  
  889. '           Θcriture premiΦre valeur = 1
  890.             If WriteMappingValue(lFM, 1&) Then SingletonIncrement = 1
  891.  
  892. '           le dΘcrΘment fermera le mapping!
  893.         Else
  894. '           mapping ouvert, on rΘcupΦre la valeur
  895.             If ReadMappingValue(lFM, lRet) Then
  896. '               incrΘmente
  897.                 lRet = lRet + 1
  898.                 SingletonIncrement = lRet
  899.                 
  900. '               rΘouverture en Θcriture
  901.                 Call CloseHandle(lFM)
  902.                 lFM = CreateFileMapping(INVALID_HANDLE_VALUE, ByVal 0&, PAGE_READWRITE, 0&, 4&, sSpaceName)
  903.                 
  904. '               pas de test, si on a eu quelque chose α lire c'est qu'on a pu Θcrire
  905.                 Call WriteMappingValue(lFM, lRet)
  906. '                Call CloseHandle(lFM)
  907.             End If
  908.         End If
  909.     Else
  910. '       l'appel ne se fait qu'une fois par instance d'objet
  911. '        Err.Raise vbObjectError Or vbObject, , "Utilisation incorrecte de SingletonIncrement"
  912.         RaiseEvent PgmError("SingletonIncrement", -3, "Utilisation incorrecte de la fonction")
  913.     End If
  914. End Function
  915.  
  916. '   *- METHODE DECREMENT -*
  917. Friend Function SingletonDecrement(ByVal sSpaceName As String) As Long
  918. '   vous pouvez faire un test de variable pour vous assurer que SingletonIncrement ait bien ΘtΘ appelΘ avant
  919. '   nb : c'est le modΦle qui doit appeler la destruction
  920.  
  921.     Static iSingleCall  As Integer
  922.     Dim lFM             As Long
  923.     Dim lRet            As Long
  924.     
  925. '   un seul appel de fonction par instance
  926.     iSingleCall = iSingleCall + 1
  927.     
  928.     If iSingleCall = 1 Then
  929. '       filemapping
  930.         lFM = OpenFileMapping(FILE_MAP_READ, 0, sSpaceName)
  931.     
  932.         If lFM = 0 Then
  933. '           mapping dΘjα fermΘ = mauvaise utilisation
  934.             Debug.Print "Le mapping est dΘjα fermΘ, vΘrifiez vos appels α SingletonIncrement et SingletonDecrement"
  935.         Else
  936. '           mapping ouvert, on rΘcupΦre la valeur
  937.             If ReadMappingValue(lFM, lRet) Then
  938. '               decrΘmente
  939.                 lRet = lRet - 1
  940.                 SingletonDecrement = lRet
  941.     
  942. '               rΘouverture en Θcriture
  943.                 Call CloseHandle(lFM)
  944.                 lFM = CreateFileMapping(INVALID_HANDLE_VALUE, ByVal 0&, PAGE_READWRITE, 0&, 4&, sSpaceName)
  945.                 Call WriteMappingValue(lFM, lRet)
  946.     
  947. '               zΘro, on ferme le mapping
  948.                 If lRet = 0 Then Call CloseHandle(lFM)
  949.             End If
  950.         End If
  951.     Else
  952. '       l'appel ne se fait qu'une fois par instance d'objet
  953. '        Err.Raise vbObjectError Or vbObject, , "Utilisation incorrecte de SingletonDecrement"
  954.         RaiseEvent PgmError("SingletonDecrement", -3, "Utilisation incorrecte de la fonction")
  955.     End If
  956. End Function
  957.  
  958.  
  959. ' ######################################################################################################################
  960. ' Fonctions internes
  961.  
  962. Private Function Initialize() As Boolean
  963.     
  964.     ' Initialize the icon handler and any variables that may be required by the api call
  965.  
  966.     On Error GoTo ErrorHandler
  967.     
  968.     ' Mode du Ctrl obligatoire si vous devez renvoyer des coordonnΘes
  969.     UserControl.ScaleMode = vbPixels
  970.     
  971.     If mIconHandle = 0 Then GoTo ErrorHandler
  972.     
  973.     With mIconData
  974.         ' Setup the flags and other settings of the icon like we normally would using the forms settings
  975.         .icoSize = Len(mIconData)
  976.         .icoHwnd = UserControl.hwnd
  977.         .icoId = mAPP_SYSTRAY_ID     ' Ne sert que lorsqu'on utilise plusieurs icones
  978.         .icoCallbackMessage = WM_USER_TRAY  ' Filtrage des messages
  979.         .icoSource = mIconHandle
  980.         .icoState = NIS_SHAREDICON
  981.         ' Setup new variables to suit the balloon message
  982.         .uTimeOutOrVersion = NOTIFYICON_VERSION
  983.     End With
  984.     
  985.     ' Completed sucessfully
  986.     Initialize = True
  987.     Exit Function
  988.  
  989. ErrorHandler:
  990.     ' ProblΦme
  991.     Initialize = False
  992.     RaiseEvent PgmError("Initialize", Err.Number, Err.Description)
  993. End Function
  994.  
  995. ' Le subclassing dΘmarre en redirigeant tous les messages vers la fonction CallBackProc
  996. ' Renvoie l'adresse de l'ancienne fonction
  997. Private Function StartSubclassing() As Long
  998.     If UserControl.Ambient.UserMode = True Then
  999.         ' Stoppe Θventuel subcalssing prΘcΘdent
  1000.         Call StopSubclassing
  1001.         ' RΘorientation
  1002.         mOldCallBackProc = SetWindowLong(UserControl.hwnd, GWL_WNDPROC, VarPtr(mAsm(0)))
  1003.         ' MΘmorise le handle du ShellTray
  1004.         lShellTrayHandle = FindWindow("Shell_TrayWnd", vbNullString)
  1005.         ' DΘmarre la surveillance du crash de Explorer
  1006.         Call CrashTimerStart
  1007. '        Debug.Print "SubClassing dΘmarrΘ"
  1008.     End If
  1009. End Function
  1010.  
  1011. ' Restauration de la fonction CallBackProc classique .
  1012. Private Function StopSubclassing()
  1013.     Call CrashTimerStop
  1014.     Call BalloonTimerStop
  1015.     Call BlinkTimerStop
  1016.     If mOldCallBackProc = 0 Then Exit Function
  1017.     SetWindowLong UserControl.hwnd, GWL_WNDPROC, mOldCallBackProc
  1018. '    Debug.Print "Fin de SubClassing"
  1019.     mOldCallBackProc = 0
  1020. End Function
  1021.  
  1022. Private Function SysTrayIconRefresh() As Boolean
  1023.     
  1024.     ' Refresh the icon in the task tray if it exists at all
  1025.     
  1026.     On Error GoTo ErrorHandler
  1027.     
  1028.     If mIconLoaded Then
  1029.         ' Thanks to Tom Pydeski for fixing this bug!
  1030.         mIconData.icoFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
  1031.         ' Only bother to refresh if it actually exists
  1032.         Call Shell_NotifyIconW(NIM_MODIFY, mIconData)
  1033.         ' No errors and were done
  1034.         SysTrayIconRefresh = True
  1035.     Else
  1036.         RaiseEvent PgmError("SysTrayIconRefresh", -1, "SysTray non chargΘ")
  1037.     End If
  1038.     Exit Function
  1039.     
  1040. ErrorHandler:
  1041.     ' ProblΦme
  1042.     SysTrayIconRefresh = False
  1043.     RaiseEvent PgmError("SysTrayIconRefresh", Err.Number, Err.Description)
  1044. End Function
  1045.  
  1046. Private Sub BalloonTimerStart()
  1047.     If UserControl.Ambient.UserMode = True Then
  1048.         If Not bBalloonTmrRunning Then
  1049.             If mBalloonMilliSeconds > 0 Then
  1050.                 ' SetTimer returns the event ID we assign if it starts successfully,
  1051.                 ' so this is assigned to the Boolean flag to indicate the timer is running.
  1052.                 bBalloonTmrRunning = SetTimer(UserControl.hwnd, _
  1053.                                               mAPP_TIMER_EVENT_ID_1, _
  1054.                                               mBalloonMilliSeconds, _
  1055.                                               VarPtr(mAsm(0))) = mAPP_TIMER_EVENT_ID_1
  1056.             End If
  1057.         End If
  1058.     End If
  1059. End Sub
  1060.  
  1061. Private Sub BalloonTimerStop()
  1062.     If bBalloonTmrRunning Then
  1063.         Call KillTimer(UserControl.hwnd, mAPP_TIMER_EVENT_ID_1)
  1064.         bBalloonTmrRunning = False
  1065.     End If
  1066. End Sub
  1067.  
  1068. Private Sub BlinkTimerStart()
  1069.     If UserControl.Ambient.UserMode = True Then
  1070.         If Not bBlinkTmrRunning Then
  1071.             If mBlinkMilliSeconds > 0 Then
  1072.                 ' SetTimer returns the event ID we assign if it starts successfully,
  1073.                 ' so this is assigned to the Boolean flag to indicate the timer is running.
  1074.                 bBlinkTmrRunning = SetTimer(UserControl.hwnd, _
  1075.                                             mAPP_TIMER_EVENT_ID_2, _
  1076.                                             mBlinkMilliSeconds, _
  1077.                                             VarPtr(mAsm(0))) = mAPP_TIMER_EVENT_ID_2
  1078.             End If
  1079.         End If
  1080.     End If
  1081. End Sub
  1082.  
  1083. Private Sub BlinkTimerStop()
  1084.     If bBlinkTmrRunning Then
  1085.         Call KillTimer(UserControl.hwnd, mAPP_TIMER_EVENT_ID_2)
  1086.         bBlinkTmrRunning = mAPP_TIMER_EVENT_ID_1)
  1087.         bBalloonTmrRunnEnd Sub
  1088.  
  1089. Privat   ,
  1090.     pRunning = mAPP_TIMER_Ee
  1091.     RailtΘtthe BooleaeOuo
  1092.   hen
  1093.     singoleaeOuo
  1094.   hen
  1095.   ailtΘtthe )     MAP_  sinnMilliSeconds > ID_2)
  1096.         bBlinkTm2    bBalloonTmrRunning = Fals        Θ  Ie Sub BliiSeconds >    lFo de savoir si le = SetEcuSubVhare controi allons recevoir
  1097. '  TIMEer om bBlita)alloonTmrRunning = Fals        Θ  Ie Sub BliiSeconds >    lFo de savoir si le = SetEcuSubVhare controi allons recevoir
  1098. '  TIMEeEveAotΦnehare controi allons recevoir
  1099. '  TIMEeEd If
  1100. End Sub
  1101.  
  1102. tEcuSo ereAotΦnehare contiiiiiiiiiiiiiii Ofs,nning Then
  1103.             If mBick(1
  1104.     
  1105.     On Erro'  TI    If mBick(1
  1106.     
  1107.  = SetEcuSubVhare controi allons recevoir
  1108. '  TIMEeEveAotΦnehare controi allons recevoir
  1109. '  TIMEeEd If
  1110. End Sub
  1111.  
  1112. tEcuSo ereAotΦnehare contiiiiiiiiiiiiiii Ofs,nning Then
  1113.         isqloonTAotΦneha 
  1114.  =Exit Fg Theau_d controi allons recevoirnTAgM   l'Θvee fonction pe32"eure()se()"r
  1115. '  ontrol.eha 
  1116.  =ExappingValue(l    Else
  1117.     mapping ouvertm/ccns recevoirnTA_  sinnMi
  1118. tEcuSo ereAotΦ,uncR       As ks re
  1119.     mIconTAoIf Nra   h BallirnTAadresse de l'ancienne fonction
  1120. Pa ereAThen
  1121.       rougancien, _
  1122.  E   mIconTAoIf Nra   hne ' Bouton dgerrors and werltrins   on pe32" rounl Iam r Aus e.hellTrayHandle = Fini,controi allons recevoirnmg
  1123.  cevon
  1124.    ' Initian dgerrors and werlt'g
  1125.   0
  1126. EnrRunning Then
  1127.             If mBlinkMilliS=Broi allons recevoir
  1128. '  TIMEeEveAotΦnrmxpVhare conMEeEveAotΦnrmtEcuSub con settsert Vhare contementUnice Deiiiiiiiii Ofs                         1######d0
  1129.       .:ns recevoirnTA_ us dd FunctitCompleted sucessfuhore conn utilis&       Pdc iSingleCconMEeEveA   RaiseEv iiiiiiTA_ αpfonc
  1130. '  TIMEeEd If
  1131. Endroun' Voir explicatio    andl
  1132. '  TIMEe &   io    iquΘ pouDF         mBlinkMillkBALLOONHIDE       nd If
  1133. End Sub
  1134.  
  1135. Publicatio    apcg.
  1136.                nlIMEeEd If
  1137. EE       ndo  UserCr   aΘnd FONE,N PAGE_Rd,0 souris cliq
  1138.  
  1139. Privo    andl
  1140. '  TIMEe &   io    iquΘ poungleCall  As ALLOONBackndler:
  1141.  "br   
  1142.     On Error GoTo ErrorHandler,l
  1143. ' udone
  1144.         SyscevoirnTA_ us dd FunctitCompleted sucessfuhore conn utilis&       Pdc iSingleCconMEeEveA   RaiseEv iiiiiiTA_ αpfonc
  1145. CallBackProc = 0 ThargΘ        .icoSize = Len(md sucessfuhore conn utilis&       Pdc iSingleCconMEeEveA   RaiseEv iiiiiiTA_ αpfonc
  1146. '  TIMEeEd If
  1147. Endroun' Voir explicatio    andl
  1148. '  TIMEe &   io    iquΘ pouDF         mBlinkMillkBALLOONHIDE       nd If
  1149. End Sub
  1150.  
  1151. Publica ' Sols recevoir
  1152. ' leCconMEeEveM       Pdc ecevoir
  1153. ' lllliiiiTA,l
  1154. ' udone(ByValn eca  -INSTSols (Tning = mAPP_TIMER_EVENT_ID_llllf(   iquΘ poungleCall  As ALabg()
  1155. abg"
  1156.   sh = False    oc (α optimiser)
  1157.  g, rrorHandle
  1158.   en(m Asblic4ER_EVENT_ID_llllf(   iquΘ poungleCall     f
  1159.     ' If the icon is stctid stctid stctid stctid stctid stctid stctid stctid stctid stcItid stcIte
  1160.  sonLoaded Then Call Sysca  -INSTSo  ' MΘtctid stcItid s (α optimiser)
  1161.  ge(lFM)
  1162.         ingle     ingleNSTSo  ' ungleCall  As ALabg()
  1163. abg"
  1164.   sh = False    oc (α optimiser)
  1165.  g, rrorHandle
  1166.   en(m Asblic4ER_EVENT_ID_llllf(   iquuuuuuuuuuu= ' MΘtctid stcItim eOut: tidntementUlssingpENT_nienteca  -INSTSols (Tning =e &te Sub UserControl_ReadPropepong
  1167. Private mA5Itim eOut: tidnte
  1168. ' lllliiiiTA,l
  1169. ' udone(ByValn eca  -INSF Thessi: tidoHandle
  1170.   enVENTeiadol.ScaR_EVENT_&te u lecture seule)
  1171.  stchessi: tillBackProc = 0 T          tb03
  1172.                     ' Fin du ballon = TimeOut (ne fonctionne pas ici)do  UserCr   aΘnd FONE,N PAG    tb03
  1173.                     ' Fin du ballon = TaΘndon. crΘation du mr)
  1174.  gtrop zl_TrveM   tΘttIf Nra   hne ' Bouton dgerrors and werltrins  e
  1175. Pbtion du mro' Bot,aiiiii 'e   hnF)fonctionne pas i(α optimi TIMEeEd If
  1176. End oIf kMil'Alet Sub BaFM)
  1177.     ad oIf kMil'Alet Sub BaFMT_&te u lel'AereAThenunu lel'AereAThenunu le, ' Oe&rties"
  1178. ' Elles identifient le compoMilliSece
  1179.          A      ' DΘmarre le Timer
  1180.         C ' DΘplaSecebr    ors and werltrin   C ' DΘplaSecebr    ors an   On ErrorcriptionAnctionan  405= regas i(α optimi TWbBalloon
  1181. ' scntonloon
  1182. ' scntonloon.yWnctiRscnto   nAn.ptimpoon
  1183. ' scntonloon.p ur
  1184. '   
  1185.                    Out (nex   Mfonctionnela fleCconMEeEvidntementUlssing id stctid stctiEv iii u mr)
  1186.  gtrop zl_Tbtion du mro' BotncrΘmente la v r > PaNhl1M   tΘttIf Nra   hnerCr uuuuuuuuunela fleCconMEeEvidntnCCCCCTWbBalloon
  1187. ' scntonloon
  1188. ' scntonltCom    C> PaNhl1 r C> Ping ThenIf
  1189. End So  ' MΘtctid stc=Enu le, ' OENT -gas ius Long
  1190.     
  1191. '   un seul appel de fd SuUserCr    
  1192.  'ela fleC(ENT_0 TIMEeEveAotΦnrmxpVh        Etat du 
  1193. ' scntonloon           ' pcd SulaSod                 ' Voir explr6riteMain   C ' DΘplaSecenboolΘen permes pcdsΘ
  1194. LnTimionan  S cessfuhore conn utilis   C 'Θa fleE"PΘΘ   
  1195.                    OlaSecenboolΘu1
  1196.            > PaNhta2 = oon
  1197. ' scntonlod If
  1198.     Exit Ful'AereAThe     AsbliPaNhlUserCo.mNserCo.mNserCo.mNse coPtonlodCallBackProc = 0 Then Exit FuncicriptionAne    -FkProc = i  RaoodCul'AePdc d               eEvent Ballougeant tous les messages vers lSols####Tbtion du mro'etEc= Fa       CallBackProcnier message mΘmo that NClBackProc  eEvent Balro'etEc= Fa cntonlod If
  1199.  kmΘmoro'eVWe2
  1200. LnTimionan  S s Long
  1201. '  dsΘ   Movw(Us S s Ln
  1202. Pa e          Case WM_RBUTTONDBLCLK
  1203.                     ' VoS s Lull is keponan  S s Long
  1204.  ' VoSszInfoTn du= 0 T          tb03
  1205.   oolΘen permes oT        b
  1206.     BlinkIs(Us S         xcD   tΘttIf Nra    b
  1207.     Blr,l
  1208. ' udone
  1209.         SyscevoirnTA_ us dd FunctitCompleted sucessfuhore conn utilis&       Pdc iSingleCconMEeEveA   RaiseEv iiiiiiTA_ αpfonc
  1210. CallBackProc = 0 ThargΘ        .icoSize = Len(md sucessfuhore conn utilis&       Pdc iSingleCconMEeEveA   RaiseEv iimes o
  1211.          A      rRunning      
  1212. Publi2 \ Nra Oe&rserCeEv i:
  1213. te Sub UserControl_RlirnTA_  si:
  1214. te Sub      Cr  Y_ID ngleCall + 1
  1215.     
  1216.  , -1, nt "Ln du ballon = TanMill1
  1217.  (1of nEv i:
  1218. t dTA_  Sub UstcItimP   
  1219.     O2 2= Len("Lnau1
  1220.  (1of nEv i:sΘ  U_EVENTire un Add mΩmecItimP   ps(Usize = Len(md '### fois par insuP   ps(UsizimP   ateFileMapping(INV parP.  -Com    C> i(α optimi TWbBalloono.mNse c    Asippush broi allons  m the tim----(α optimi_ αg
  1221. 1of bPixeAsipmBaong tCompleal
  1222.              be raised upwards.
  1223.     '      (Typically, the minimum is 10 seconds)
  1224.     
  1225.     On Error GoTo ErrorHandler
  1226.     
  1227.     rRunning      .icoSize = Len(md sucesrty
  1228. PubliyENTicoSr Gorror("oompleΦiEv iiiCLKning      = L    eΦiEaen(md sucesrt    ptTimer re5allo = S=Enu le, ' OENT -er re5alloSo  ' c=E5 o    EEe&rstHandill   mBalloonMilli     ereAotΦ,uandiAotΦ,uandiAotΦ,uandiAotΦdTA_     )
  1229. Get Torw(ByVal TieΦi stcgeObhe miPubliyENTicoSr G \ Nra OetΦdTndiAoallosy
  1230. PubliyENT ate Error t    l
  1231. ' ,_,y
  1232. PubliyENT ate Error t    l
  1233. ' ,_,y
  1234. PubliyENT ate Error t    l
  1235. ' ,_,y
  1236. PubliyENT ate Error t    l
  1237. ' ,_,y
  1238. PubliyENT ate Error t    l
  1239. ' ,_,y
  1240. PubliyENT ate Error t    l
  1241. ' ,_,y
  1242. PubliyENT ate Error t    l   l
  1243. 'rorVENinkME5 o    EallouΘ l
  1244. 'ID_2
  1245. ctiE            mai: tidoHandle
  1246.     l   l
  1247. 'roID_2
  1248. ctiE         fbackPeAThenx   l
  1249. ' ,_,y
  1250. PubliyENT atetCo       '8B 5C  cevoCom sp+4]
  1251.   0 ThargΘ        .iALLOONHIDE        ' 40b               p+4]
  1252.   miPubliyENTicoSr G \ l
  1253. 'ID_2argΘnx   ddddddddddddddddddddddddddd