Update : Windows 7 Notify Icon

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Update : Windows 7 Notify Icon

Post by RASHAD »

Windows 7 System Tray and Notify Icon using PB
No limit to the functions that can be atchived

Code: Select all

Global hwnd

CreateImage(0, 20, 20, 32|#PB_Image_Transparent)
StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_Gradient|#PB_2DDrawing_AllChannels)     
  BackColor (RGBA(40,250,250,200))
  FrontColor(RGBA(0,0,0,0))
  LinearGradient(0, 0, 20, 20)
  Box(0,0,20,20)  
StopDrawing()

CreateImage(1, 20, 20, 32|#PB_Image_Transparent)
StartDrawing(ImageOutput(1))
  DrawingMode(#PB_2DDrawing_Gradient|#PB_2DDrawing_AllChannels)     
  BackColor (RGBA(0,100,230,230))
  FrontColor(RGBA(250,120,120,0))
  LinearGradient(0, 0, 20, 20)
  Box(0,0,20,20) 
StopDrawing()

Procedure HFTaskBar(hWnd, Flag)
  Protected TBL.ITaskbarList

  CoInitialize_(0)
  If CoCreateInstance_(?CLSID_TaskBarList, 0, 1, ?IID_ITaskBarList, @TBL) = #S_OK
    TBL\HrInit()
    If Flag
      TBL\DeleteTab(hWnd)
    Else
      TBL\AddTab(hWnd)
    EndIf
    TBL\Release()
  EndIf
  CoUninitialize_()

  DataSection
    CLSID_TaskBarList:
    Data.l $56FDF344
    Data.w $FD6D, $11D0
    Data.b $95, $8A, $00, $60, $97, $C9, $A0, $90
    IID_ITaskBarList:
    Data.l $56FDF342
    Data.w $FD6D, $11D0
    Data.b $95, $8A, $00, $60, $97, $C9, $A0, $90
  EndDataSection
EndProcedure

Procedure NotifyIcon(Parameter)
TrayWnd       = FindWindow_("Shell_TrayWnd", 0)
TrayNofifyWnd = FindWindowEx_(TrayWnd, 0, "TrayNotifyWnd", 0)
GetWindowRect_(TrayNofifyWnd,r.RECT)
width = 15
height = 15
x=r\left - 20
y=r\top + 13
Repeat
  GetWindowRect_(TrayNofifyWnd,r.RECT)
  x=r\left - 20
If FindWindow_("CiceroUIWndFrame", 0) > 65704
   x=r\left - 65
EndIf
  MoveWindow_(hwnd,x,y,width,height,1)
  BringWindowToTop_(hwnd)
  Delay(Parameter) 
ForEver
EndProcedure

TrayWnd       = FindWindow_("Shell_TrayWnd", 0)
TrayNofifyWnd = FindWindowEx_(TrayWnd, 0, "TrayNotifyWnd", 0)
;NotifyButton  = FindWindowEx_(TrayNofifyWnd, #Null, "Button", #Null)
GetWindowRect_(TrayNofifyWnd,r.RECT)
width = 15
height = 15
x=r\left - 20 
y=r\top + 13
If FindWindow_("CiceroUIWndFrame", 0) > 65704
   x=r\left - 65
EndIf

; SHAppBarMessage_(#ABM_GETTASKBARPOS,Pos.AppBarData)
; 
; ; If Pos\uEdge <> 1 And Pos\uEdge <> 3
; ;     End
; ; EndIf

OpenWindow(0,0,0,400,300,"",#PB_Window_SystemMenu|#PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_SizeGadget|#PB_Window_ScreenCentered )
ButtonGadget(0,10,270,80,22,"Show Icon")
    CreatePopupMenu(0)
      MenuItem(1, "Open")
      MenuItem(2, "Save")
      MenuItem(3, "Save as")
      MenuItem(4, "Quit")
    CloseSubMenu()
    CreatePopupMenu(1)
      MenuItem(1, "This is a Test")
    CloseSubMenu()
hwnd = OpenWindow(1,x,y,width,height,"",#PB_Window_BorderLess)
HFTaskBar(WindowID(1), #True)
StickyWindow(1,1)
CanvasGadget(1,0,0,15,15)
SetGadgetAttribute(1, #PB_Canvas_Cursor,#PB_Cursor_Hand)
SetGadgetAttribute(1, #PB_Canvas_Image , ImageID(1))


Thread = CreateThread(@NotifyIcon(),200)

Repeat

  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
          Quit = 1
          
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 0
              HideWindow(1,0)
              SetActiveWindow(0)
              
           Case 1  
              Select EventType()
              
                Case #PB_EventType_MouseEnter
                    SetGadgetAttribute(1, #PB_Canvas_Image , ImageID(0))
                    ;DisplayPopupMenu(1, WindowID(0),x+10,y-15)
                
                Case #PB_EventType_MouseLeave
                    SetGadgetAttribute(1, #PB_Canvas_Image , ImageID(1))
                    
                Case #PB_EventType_LeftButtonDown
                    DisplayPopupMenu(0, WindowID(0),x,y-4)
                
                Case #PB_EventType_RightButtonDown
                    HideWindow(1,1)
                
                Case #PB_EventType_Focus
                
                Case #PB_EventType_LostFocus
                
              EndSelect
                
          EndSelect
          
      Case #PB_Event_SizeWindow
        ResizeGadget(0,10, WindowHeight(0) - 30,80,22) 
          
  EndSelect   
  
Until Quit = 1 

Have fun


Edit :Code updated
Last edited by RASHAD on Sat Oct 29, 2011 5:47 pm, edited 2 times in total.
Egypt my love
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: Windows 7 Notify Icon

Post by electrochrisso »

Thanks and great stuff RASHAD. :)
What resources do you use to master the API mate :?:
PureBasic! Purely the best 8)
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Re: Windows 7 Notify Icon

Post by Tomi »

hi rashad, i use more than one lng in win os, then there is an icon in systry always, your project icon cover lng icon (7 x64)
see this
Image
thanks always
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Windows 7 Notify Icon

Post by RASHAD »

@electrochrisso
Google,Sparkie,NM,FB,.... :mrgreen:

@Tomi
Code updated
Check and respond
Egypt my love
PureGuy
Enthusiast
Enthusiast
Posts: 102
Joined: Mon Aug 30, 2010 11:51 am

Re: Windows 7 Notify Icon

Post by PureGuy »

Line: 100 CanvasGadget() is not a funktion, array, macro or linked list :?:

Which PureBasic version do I need for this ???
User avatar
Demivec
Addict
Addict
Posts: 4270
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Windows 7 Notify Icon

Post by Demivec »

PureGuy wrote:Line: 100 CanvasGadget() is not a funktion, array, macro or linked list :?:

Which PureBasic version do I need for this ???
Version 4.60 rc2
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: Windows 7 Notify Icon

Post by electrochrisso »

@electrochrisso
Google,Sparkie,NM,FB,.... :mrgreen:
I was hoping you might use an all in one book of API tricks.
Perhaps you could write one, I'd be first in line to buy a copy. :wink:
PureBasic! Purely the best 8)
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Re: Windows 7 Notify Icon

Post by Tomi »

mercy rashad :D very good now
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Windows 7 Notify Icon

Post by RASHAD »

Improved
Much better

Code: Select all


Global hwnd

CreateImage(0, 20, 20, 32|#PB_Image_Transparent)
StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_Gradient|#PB_2DDrawing_AllChannels)     
  BackColor (RGBA(40,250,250,200))
  FrontColor(RGBA(0,0,0,0))
  LinearGradient(0, 0, 20, 20)
  Box(0,0,20,20)  
StopDrawing()

CreateImage(1, 20, 20, 32|#PB_Image_Transparent)
StartDrawing(ImageOutput(1))
  DrawingMode(#PB_2DDrawing_Gradient|#PB_2DDrawing_AllChannels)     
  BackColor (RGBA(0,100,230,230))
  FrontColor(RGBA(250,120,120,0))
  LinearGradient(0, 0, 20, 20)
  Box(0,0,20,20) 
StopDrawing()

Procedure NotifyIcon(Parameter)
TrayWnd       = FindWindow_("Shell_TrayWnd", 0)
TrayNofifyWnd = FindWindowEx_(TrayWnd, 0, "TrayNotifyWnd", 0)
GetWindowRect_(TrayNofifyWnd,r.RECT)
width = 15
height = 15
x=r\left - 20
y=r\top + 13
Repeat
  GetWindowRect_(TrayNofifyWnd,r.RECT)
  x=r\left - 20
If FindWindow_("CiceroUIWndFrame", 0) > 65750
   x=r\left - 65
EndIf
  MoveWindow_(hwnd,x,y,width,height,1)
  BringWindowToTop_(hwnd)
  Delay(Parameter)
ForEver
EndProcedure

TrayWnd       = FindWindow_("Shell_TrayWnd", 0)
TrayNofifyWnd = FindWindowEx_(TrayWnd, 0, "TrayNotifyWnd", 0)
GetWindowRect_(TrayNofifyWnd,r.RECT)
width = 15
height = 15
x=r\left - 20 
y=r\top + 13
If FindWindow_("CiceroUIWndFrame", 0) > 65750
   x=r\left - 65
EndIf

OpenWindow(0,0,0,400,300,"Windows 7 Notify Icon",#PB_Window_Invisible|#PB_Window_SystemMenu|#PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_SizeGadget|#PB_Window_ScreenCentered )
ButtonGadget(0,10,270,80,22,"Show Icon")
    CreatePopupMenu(0)
      MenuItem(1, "Open")
      MenuItem(2, "Save")
      MenuItem(3, "Save as")
      MenuItem(4, "Quit")
    CloseSubMenu()
hwnd = OpenWindow(1,x,y,width,height,"",#PB_Window_BorderLess,WindowID(0))
StickyWindow(1,1)
CanvasGadget(1,0,0,15,15)
SetGadgetAttribute(1, #PB_Canvas_Cursor,#PB_Cursor_Hand)
SetGadgetAttribute(1, #PB_Canvas_Image , ImageID(1))

Thread = CreateThread(@NotifyIcon(),200)
HideWindow(0,0)

Repeat

  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
          Quit = 1
          
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 0
              HideWindow(1,0)
              SetActiveWindow(0)
              
           Case 1  
              Select EventType()
              
                Case #PB_EventType_MouseEnter
                    SetGadgetAttribute(1, #PB_Canvas_Image , ImageID(0))
                
                Case #PB_EventType_MouseLeave
                    SetGadgetAttribute(1, #PB_Canvas_Image , ImageID(1))
                    
                Case #PB_EventType_LeftButtonDown
                    DisplayPopupMenu(0, WindowID(0),x,y-4)
                
                Case #PB_EventType_RightButtonDown
                    HideWindow(1,1)
                
                Case #PB_EventType_Focus
                
                Case #PB_EventType_LostFocus
                
              EndSelect
                
          EndSelect
          
      Case #PB_Event_SizeWindow
        ResizeGadget(0,10, WindowHeight(0) - 30,80,22) 
          
  EndSelect   
  
Until Quit = 1
Egypt my love
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

Re: Update : Windows 7 Notify Icon

Post by em_uk »

Is this meant to appear in the tasktray?

Kinda floats in the middle of nowhere for me on Win7x64 PB4.60

Image
----

R Tape loading error, 0:1
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Update : Windows 7 Notify Icon

Post by RASHAD »

Update

Code: Select all

Global hwnd,width,height,x,y

Structure _NOTIFYICONDATA
  cbSize.i
  hwnd.i
  uId.i
  uFlags.i
  uCallBackMessage.i
  hIcon.i
  szTip.s{64}
EndStructure

CreateImage(0, 20, 20, 32|#PB_Image_Transparent)
StartDrawing(ImageOutput(0))
  DrawingMode(#PB_2DDrawing_Gradient|#PB_2DDrawing_AllChannels)     
  BackColor (RGBA(40,250,250,200))
  FrontColor(RGBA(0,0,0,0))
  LinearGradient(0, 0, 20, 20)
  Box(0,0,20,20)  
StopDrawing()

CreateImage(1, 20, 20, 32|#PB_Image_Transparent)
StartDrawing(ImageOutput(1))
  DrawingMode(#PB_2DDrawing_Gradient|#PB_2DDrawing_AllChannels)     
  BackColor (RGBA(0,100,230,230))
  FrontColor(RGBA(250,120,120,0))
  LinearGradient(0, 0, 20, 20)
  Box(0,0,20,20) 
StopDrawing()

Procedure NotifyIcon(Parameter)
TrayWnd       = FindWindow_("Shell_TrayWnd", 0)
TrayNofifyWnd = FindWindowEx_(TrayWnd, 0, "TrayNotifyWnd", 0)
GetWindowRect_(TrayNofifyWnd,r.RECT)
Repeat
  GetWindowRect_(TrayNofifyWnd,r.RECT)
  x=r\left
  MoveWindow_(hwnd,x,y,width,height,1)
  BringWindowToTop_(hwnd)
  Delay(Parameter)
ForEver
EndProcedure

TrayWnd            = FindWindow_("Shell_TrayWnd", 0)
TrayNofifyWnd      = FindWindowEx_(TrayWnd, 0, "TrayNotifyWnd", 0)
GetWindowRect_(TrayNofifyWnd,r.RECT)
width = 20
height = r\bottom-r\top
x=r\left                                                                                                                                             
y=r\top

OpenWindow(0,0,0,400,300,"Windows 7 Notify Icon",#PB_Window_Invisible|#PB_Window_SystemMenu|#PB_Window_MaximizeGadget| #PB_Window_MinimizeGadget| #PB_Window_SizeGadget|#PB_Window_ScreenCentered )
ButtonGadget(0,10,270,80,22,"Show Icon")
    CreatePopupMenu(0)
      MenuItem(1, "Open")
      MenuItem(2, "Save")
      MenuItem(3, "Save as")
      MenuItem(4, "Quit")
    CloseSubMenu()
hwnd = OpenWindow(1,x,y,width,height,"",#PB_Window_BorderLess,WindowID(0))
StickyWindow(1,1)
SetWindowColor(1,#Red)
SetWindowLongPtr_(WindowID(1),#GWL_EXSTYLE,GetWindowLongPtr_(WindowID(1),#GWL_EXSTYLE)|#WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(1),#Red,0,#LWA_COLORKEY)
CanvasGadget(1,1,(height-16)/2,20,18)
SetGadgetAttribute(1, #PB_Canvas_Cursor,#PB_Cursor_Hand)
SetGadgetAttribute(1, #PB_Canvas_Image , ImageID(1))

  nim._NOTIFYICONDATA
  nim\cbSize = SizeOf(nim)
  nim\hWnd = WindowID(0)
  nim\uId = 100
  nim\uFlags = #NIF_ICON | #NIF_TIP | #NIF_MESSAGE
  nim\uCallBackMessage = #WM_MOUSEMOVE
  nim\hIcon = 0 
  nim\szTip = "OK NotifyIcon Test" + Chr(0)

Shell_NotifyIcon_(#NIM_ADD, nim)

Thread = CreateThread(@NotifyIcon(),200)
HideWindow(0,0)

Repeat

  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
          Shell_NotifyIcon_(#NIM_DELETE, nim)
          Quit = 1
          
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 0
              If IsWindowVisible_(hWnd)
                 HideWindow(1,1)
              Else
                 Shell_NotifyIcon_(#NIM_ADD, nim)
                 HideWindow(1,0)
              EndIf
              SetActiveWindow(0)
              
           Case 1  
              Select EventType()
              
                Case #PB_EventType_MouseEnter
                    Shell_NotifyIcon_(#NIM_SETFOCUS, nim)
                    SetGadgetAttribute(1, #PB_Canvas_Image , ImageID(0))
                
                Case #PB_EventType_MouseLeave
                    SetGadgetAttribute(1, #PB_Canvas_Image , ImageID(1))
                    
                Case #PB_EventType_LeftButtonDown
                    DisplayPopupMenu(0, WindowID(0),x,y-4)
                
                Case #PB_EventType_RightButtonDown
                    Shell_NotifyIcon_(#NIM_DELETE, nim)
                    HideWindow(1,1)
                
                Case #PB_EventType_Focus
                
                Case #PB_EventType_LostFocus
                
              EndSelect
                
          EndSelect
          
      Case #PB_Event_SizeWindow
        ResizeGadget(0,10, WindowHeight(0) - 30,80,22) 
          
  EndSelect   
  
Until Quit = 1

Egypt my love
User avatar
Tomi
Enthusiast
Enthusiast
Posts: 270
Joined: Wed Sep 03, 2008 9:29 am

Re: Update : Windows 7 Notify Icon

Post by Tomi »

that's better than your before job! :D Thanks rashad for release your code :D
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: Update : Windows 7 Notify Icon

Post by fsw »

On Windows 7 64bit the icon is always visible.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Update : Windows 7 Notify Icon

Post by RASHAD »

fsw Hi
Remark or delete

Code: Select all

;Shell_NotifyIcon_(#NIM_SETFOCUS, nim)
Press Mouse right click while over the icon to hide it
Press the button to show it again

Thanks for reporting
Egypt my love
Post Reply