December 03, 2020, 08:14:55 PM

Author Topic: [bmx] fmc.SystemTray by Fabian. [ 1+ years ago ]  (Read 734 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] fmc.SystemTray by Fabian. [ 1+ years ago ]
« on: June 29, 2017, 12:28:43 AM »
Title : fmc.SystemTray
Author : Fabian.
Posted : 1+ years ago

Description : Since 2006-11-06 my modules stored in the code archives are out of synchronization. To have the latest version you need to use the bmk/syncmods utility or the MaxIDE.

You need to add "webspace100.we.funpic.de/root/mod" as a new line to "cfg/modservers.cfg" in your BlitzMax installation directory.

You can't synchronize with the default BlitzMax 1.22 IDE. If you don't have another IDE, you need to download a <a href="http://webspace100.we.funpic.de/root/programs/MaxIDE.exe" target="_blank">tweaked MaxIDE[/url]. You need to specify "fmc" as additional module scope.

Alternative you can synchronize with the bmk tool: bmk syncmods fmc

For a better description see my <a href="../Community/posts37e4.html?topic=69294" target="_blank">thread[/url] in the programming forum introducing these modules.


Code :
Code: BlitzMax
  1. Strict
  2. Module fmc.SystemTray
  3. ?Win32
  4.  
  5. ModuleInfo "Version: 0.01"
  6. ModuleInfo "Modserver: Fabian"
  7.  
  8. Import brl.win32maxgui
  9. Import fmc.ObjectTool
  10.  
  11. Type TTrayIcon
  12.   Field Link:TLink
  13.   Field NID:Object
  14.   Field SystemIcon:TSystemIcon
  15.   Field Menu:TGadget
  16.   Field ToolTip$
  17.  
  18.   Function Create:TTrayIcon ( SystemIcon:TSystemIcon = Null , Menu:TGadget = Null , ToolTip$ = "" )
  19.     Local TrayIcon:TTrayIcon = New TTrayIcon
  20.     Local NID:TNotifyIconData = New TNotifyIconData
  21.     TrayIcon.Link = List.AddLast ( TrayIcon )
  22.     TrayIcon.NID = NID
  23.     TrayIcon.Menu = Menu
  24.     TrayIcon.ToolTip = ToolTip
  25.     NID.Size = SizeOf NID
  26.     NID.Win = Window
  27.     NID.ID = Int Byte Ptr TrayIcon
  28.     NID.Flags = 7
  29.     NID.CallbackMessage = $200
  30.     If SystemIcon
  31.       TrayIcon.SystemIcon = SystemIcon
  32.       NID.Icon = SystemIcon.Icon
  33.     EndIf
  34.     MemCopy Varptr NID.Tip00 , StringPtr ( ToolTip ) , 2 * Min ( Len ToolTip , 63 )
  35.     Shell_NotifyIconW 0 , NID
  36.     Return TrayIcon
  37.   EndFunction
  38.  
  39.   Method SetSystemIcon ( NewSystemIcon:TSystemIcon )
  40.     If Link
  41.       SystemIcon = NewSystemIcon
  42.       If SystemIcon
  43.         TNotifyIconData ( NID ).Icon = SystemIcon.Icon
  44.       Else
  45.         TNotifyIconData ( NID ).Icon = 0
  46.       EndIf
  47.       Shell_NotifyIconW 1 , NID
  48.     EndIf
  49.   EndMethod
  50.  
  51.   Method SetMenu ( NewMenu:TGadget )
  52.     If Link
  53.       Menu = NewMenu
  54.     EndIf
  55.   EndMethod
  56.  
  57.   Method SetToolTip ( NewToolTip$ )
  58.     If Link
  59.       ToolTip = NewToolTip
  60.       MemClear Varptr TNotifyIconData ( NID ).Tip00 , 126
  61.       MemCopy Varptr TNotifyIconData ( NID ).Tip00 , StringPtr ( ToolTip ) , 2 * Min ( Len ToolTip , 63 )
  62.       Shell_NotifyIconW 1 , NID
  63.     EndIf
  64.   EndMethod
  65.  
  66.   Method GetSystemIcon:TSystemIcon ( )
  67.     If Link
  68.       Return SystemIcon
  69.     EndIf
  70.   EndMethod
  71.  
  72.   Method GetMenu:TGadget ( )
  73.     If Link
  74.       Return Menu
  75.     EndIf
  76.   EndMethod
  77.  
  78.   Method GetToolTip$ ( )
  79.     If Link
  80.       Return ToolTip
  81.     EndIf
  82.   EndMethod
  83.  
  84.   Method Destroy ( )
  85.     If Link
  86.       Shell_NotifyIconW 2 , NID
  87.       Link.Remove
  88.       Link = Null
  89.     EndIf
  90.   EndMethod
  91. EndType
  92.  
  93. Type TSystemIcon
  94.   Field Icon
  95.  
  96.   Function FromExeRes:TSystemIcon ( ResName$ = "101" , TryInt = True )
  97.     Local NamePtr:Short Ptr
  98.     Local NameInt = Int ResName
  99.     Local W:Short Ptr
  100.     If TryInt And NameInt
  101.       NamePtr = Short Ptr NameInt
  102.     Else
  103.       W = ResName.ToWString ( )
  104.       NamePtr = W
  105.     EndIf
  106.     Local Icon = LoadImageW ( GetModuleHandleW ( Null ) , NamePtr , 1 , 0 , 0 , 0 )
  107.     If W
  108.       MemFree W
  109.     EndIf
  110.     If Icon
  111.       Local SystemIcon:TSystemIcon = New TSystemIcon
  112.       SystemIcon.Icon = Icon
  113.       Return SystemIcon
  114.     EndIf
  115.   EndFunction
  116.  
  117.   Function FromFile:TSystemIcon ( FileName$ )
  118.     Local W:Short Ptr = FileName.ToWString ( )
  119.     Local Icon = LoadImageW ( 0 , W , 1 , 0 , 0 , 16 )
  120.     MemFree W
  121.     If Icon
  122.       Local SystemIcon:TSystemIcon = New TSystemIcon
  123.       SystemIcon.Icon = Icon
  124.       Return SystemIcon
  125.     EndIf
  126.   EndFunction
  127.  
  128.   Method Delete ( )
  129.     DestroyIcon Icon
  130.   EndMethod
  131. EndType
  132.  
  133. Private
  134.  
  135. Global WinGad:TGadget = CreateWindow ( "" , 0 , 0 , 0 , 0 , Desktop ( ) , WINDOW_HIDDEN )
  136. Global Window = QueryGadget ( WinGad , QUERY_HWND )
  137. Global WinProc = SetWindowLongW ( Window , -4 , Int Byte Ptr Proc )
  138. Global List:TList = CreateList ( )
  139.  
  140. Type TNotifyIconData
  141.   Field Size
  142.   Field Win
  143.   Field ID
  144.   Field Flags
  145.   Field CallbackMessage
  146.   Field Icon
  147.   Field Tip00:Long
  148.   Field Tip01:Long
  149.   Field Tip02:Long
  150.   Field Tip03:Long
  151.   Field Tip04:Long
  152.   Field Tip05:Long
  153.   Field Tip06:Long
  154.   Field Tip07:Long
  155.   Field Tip08:Long
  156.   Field Tip09:Long
  157.   Field Tip10:Long
  158.   Field Tip11:Long
  159.   Field Tip12:Long
  160.   Field Tip13:Long
  161.   Field Tip14:Long
  162.   Field Tip15:Long
  163. EndType
  164.  
  165. Function Proc ( Win , Msg , WP , LP )
  166.   If Win = Window And Msg = $200
  167.     For Local TrayIcon:TTrayIcon = EachIn List
  168.       If WP = Int Byte Ptr TrayIcon
  169.         If LP = 514
  170.           TEvent.Create ( EVENT_GADGETACTION , TrayIcon ).Emit
  171.         EndIf
  172.         If LP = 517
  173.           If TrayIcon.Menu
  174.             PopupWindowMenu WinGad , TrayIcon.Menu
  175.           EndIf
  176.         EndIf
  177.         Return
  178.       EndIf
  179.     Next
  180.     Return
  181.   EndIf
  182.   Return CallWindowProcW ( WinProc , Win , Msg , WP , LP )
  183. EndFunction
  184.  
  185. Extern "Win32"
  186.   Function Shell_NotifyIconW ( Msg , Data:Byte Ptr )
  187.   Function GetModuleHandleW ( Name:Short Ptr )
  188.   Function LoadImageW ( Inst , Name:Short Ptr , T , W , H , L )
  189.   Function DestroyIcon ( Icon )
  190.   Function SetWindowLongW ( Win , Pos , Val )
  191.   Function CallWindowProcW ( Proc , Win , Msg , WP , LP )
  192. EndExtern
  193. ?


Comments :


Brendane(Posted 1+ years ago)

 Fabian: There are lots of .ToWString() calls here. This allocates an unmanaged string which must be freed at some point with MemFree.


Fabian.(Posted 1+ years ago)

 Ok, thanks; I cleaned up the code; now it's using pub.TypeSystem to get the string ptr.I also removed some unneeded code.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal