Page 1 of 1

Update : Windows 7 Notify Icon

Posted: Thu Oct 27, 2011 6:33 am
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

Re: Windows 7 Notify Icon

Posted: Thu Oct 27, 2011 8:31 am
by electrochrisso
Thanks and great stuff RASHAD. :)
What resources do you use to master the API mate :?:

Re: Windows 7 Notify Icon

Posted: Thu Oct 27, 2011 6:45 pm
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

Re: Windows 7 Notify Icon

Posted: Thu Oct 27, 2011 7:48 pm
by RASHAD
@electrochrisso
Google,Sparkie,NM,FB,.... :mrgreen:

@Tomi
Code updated
Check and respond

Re: Windows 7 Notify Icon

Posted: Thu Oct 27, 2011 11:37 pm
by PureGuy
Line: 100 CanvasGadget() is not a funktion, array, macro or linked list :?:

Which PureBasic version do I need for this ???

Re: Windows 7 Notify Icon

Posted: Fri Oct 28, 2011 12:03 am
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

Re: Windows 7 Notify Icon

Posted: Fri Oct 28, 2011 2:20 am
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:

Re: Windows 7 Notify Icon

Posted: Fri Oct 28, 2011 8:53 am
by Tomi
mercy rashad :D very good now

Re: Windows 7 Notify Icon

Posted: Sat Oct 29, 2011 5:46 pm
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

Re: Update : Windows 7 Notify Icon

Posted: Mon Oct 31, 2011 1:17 am
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

Re: Update : Windows 7 Notify Icon

Posted: Mon Oct 31, 2011 5:42 pm
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


Re: Update : Windows 7 Notify Icon

Posted: Tue Nov 01, 2011 4:56 pm
by Tomi
that's better than your before job! :D Thanks rashad for release your code :D

Re: Update : Windows 7 Notify Icon

Posted: Fri Nov 04, 2011 8:02 pm
by fsw
On Windows 7 64bit the icon is always visible.

Re: Update : Windows 7 Notify Icon

Posted: Fri Nov 04, 2011 8:09 pm
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