Update Icon in Task manager of my own program?

Just starting out? Need help? Post your questions and find answers here.
novablue
Enthusiast
Enthusiast
Posts: 165
Joined: Sun Nov 27, 2016 6:38 am

Update Icon in Task manager of my own program?

Post by novablue »

I have seen in programs like qtox that when i switch status between Online/Away/Busy that it also changes the program icon in the task manager under the processes panel. i have tried changing my window icon during runtime but it does not change the icon in the task manager, how is it done?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Update Icon in Task manager of my own program?

Post by RASHAD »

Hi

Code: Select all

  OpenWindow(0,0,0,400,300,"Icontest",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  ;Change flag when you change your application task
  
  ButtonGadget(0,10,10,100,25,"Change Icon")
  
  CatchImage(0, ?Icon)  
  ;CatchImage(0, ?Icon2)
  ;CatchImage(0, ?Icon3)
  
  AddWindowTimer(0,125,10)
Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Quit = 1
    Case #PB_Event_Gadget
      Select EventGadget()
        Case 0
          flag = 1
      EndSelect
             
    Case #PB_Event_Timer
      If flag = 1
        flag = 0
        SendMessage_(WindowID(0),#WM_SETICON,#False,ImageID(0))
      ;ElseIf flag = 2
        ;flag = 0
        ;SendMessage_(WindowID(0),#WM_SETICON,#False,ImageID(1))
      EndIf
EndSelect
  
Until Quit = 1

DataSection
Icon:
  Data.b 0, 0, 1, 0, 1, 0, 32, 32, 4, 0, 0, 0, 0, 0, 232, 2, 0, 0, 22, 0, 0, 0, 40, 0, 0, 0, 32, 0, 0, 0, 64, 0, 0, 0, 1, 0, 4, 0, 0, 0
  Data.b 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 128, 0, 0, 0, 128, 128, 0, 128, 0
  Data.b 0, 0, 128, 0, 128, 0, 128, 128, 0, 0, 128, 128, 128, 0, 192, 192, 192, 0, 0, 0, 255, 0, 0, 255, 0, 0, 0, 255, 255, 0, 255, 0, 0, 0, 255, 0, 255, 0, 255, 255
  Data.b 0, 0, 255, 255, 255, 0, 0, 9, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 144, 0, 0, 159, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 249, 0, 9, 255
  Data.b 255, 255, 255, 135, 119, 255, 255, 135, 120, 255, 255, 255, 255, 144, 159, 255, 255, 255, 247, 7, 135, 255, 255, 72, 112, 8, 255, 255, 255, 249, 159, 255, 255, 255, 119, 136, 136, 127, 247, 120
  Data.b 136, 112, 255, 255, 255, 249, 159, 255, 255, 255, 120, 136, 136, 112, 0, 136, 136, 135, 255, 255, 255, 249, 159, 255, 255, 255, 135, 136, 136, 136, 136, 136, 136, 136, 255, 255, 255, 249, 159, 255
  Data.b 255, 255, 128, 136, 136, 136, 136, 136, 136, 120, 255, 255, 255, 249, 159, 255, 119, 136, 7, 136, 136, 136, 136, 136, 136, 119, 248, 119, 255, 249, 159, 240, 120, 112, 120, 136, 136, 136, 136, 136
  Data.b 136, 135, 7, 119, 15, 249, 159, 128, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 8, 249, 159, 119, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 136, 119, 249, 159, 120
  Data.b 136, 136, 136, 136, 136, 135, 120, 136, 136, 136, 136, 136, 128, 249, 159, 119, 136, 136, 136, 136, 135, 15, 240, 120, 136, 136, 136, 136, 112, 249, 159, 248, 7, 136, 136, 136, 112, 255, 255, 7
  Data.b 136, 136, 136, 112, 143, 249, 159, 255, 240, 136, 136, 136, 0, 255, 255, 0, 136, 136, 136, 15, 255, 249, 159, 255, 240, 136, 136, 136, 0, 255, 255, 0, 136, 136, 136, 15, 255, 249, 159, 255
  Data.b 116, 136, 136, 136, 112, 15, 255, 7, 136, 136, 136, 7, 255, 249, 159, 128, 120, 136, 136, 136, 128, 0, 0, 8, 136, 136, 136, 135, 8, 249, 159, 8, 136, 136, 255, 248, 136, 112, 7, 136
  Data.b 136, 136, 136, 136, 128, 249, 159, 120, 143, 255, 255, 255, 255, 136, 136, 143, 255, 255, 255, 136, 128, 249, 159, 132, 136, 143, 255, 255, 255, 255, 255, 255, 255, 255, 136, 136, 120, 249, 159, 240
  Data.b 136, 135, 143, 255, 255, 255, 255, 255, 255, 248, 120, 136, 15, 249, 159, 248, 119, 135, 8, 255, 255, 255, 255, 255, 255, 128, 120, 119, 127, 249, 159, 255, 255, 255, 112, 255, 255, 255, 255, 255
  Data.b 255, 119, 255, 248, 255, 249, 159, 255, 255, 255, 135, 255, 255, 255, 255, 255, 255, 120, 255, 255, 136, 249, 159, 255, 255, 255, 120, 255, 255, 119, 119, 255, 255, 135, 255, 255, 255, 249, 159, 255
  Data.b 255, 255, 120, 255, 248, 120, 135, 143, 255, 128, 255, 255, 255, 249, 159, 255, 255, 255, 128, 120, 247, 143, 255, 127, 135, 8, 255, 255, 255, 249, 9, 255, 255, 255, 255, 119, 112, 255, 255, 119
  Data.b 119, 255, 255, 255, 255, 144, 0, 159, 255, 255, 255, 255, 143, 255, 255, 248, 255, 255, 255, 255, 249, 0, 0, 9, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 153, 144, 0, 224, 0
  Data.b 0, 7, 192, 0, 0, 3, 128, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  Data.b 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  Data.b 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 0, 1, 192, 0
  Data.b 0, 3, 224, 0, 0, 7
Iconend:
Icon1:
Icon2:
EndDataSection
Egypt my love
BarryG
Addict
Addict
Posts: 3324
Joined: Thu Apr 18, 2019 8:17 am

Re: Update Icon in Task manager of my own program?

Post by BarryG »

That doesn't change it in the Task Manager, Rashad. You did it for the Taskbar.
novablue
Enthusiast
Enthusiast
Posts: 165
Joined: Sun Nov 27, 2016 6:38 am

Re: Update Icon in Task manager of my own program?

Post by novablue »

Thanks @RASHAD but this is as far as i have gotten too. What i want to know is how programs like qtox change the icon in the TASK MANAGER process panel during runtime: https://imgur.com/a/1OObL8X

The program is also Opensource maybe someone with a little more skill could look into the code and find out? :)
novablue
Enthusiast
Enthusiast
Posts: 165
Joined: Sun Nov 27, 2016 6:38 am

Re: Update Icon in Task manager of my own program?

Post by novablue »

I have found out how it works now: its the systray icon that the task manager displays. This is not much use to me since i don't want a systray icon. Maybe there is a way to hide the systray icon and it would still display it in the task manager..
firace
Addict
Addict
Posts: 903
Joined: Wed Nov 09, 2011 8:58 am

Re: Update Icon in Task manager of my own program?

Post by firace »

Try this (change the paths to point to your icons first):

Code: Select all

Procedure ChangeWindowIcon(Image$)  
  hIcon = LoadImage(0,Image$)
  SetClassLongPtr_(WindowID(0),#GCL_HICON,hIcon )
EndProcedure 

OpenWindow(0, 200, 200, 320,240, "Test Window", #PB_Window_SystemMenu )

AddWindowTimer(0,1, 2000)

Repeat    
  EventID.l = WaitWindowEvent()  
  If EventID = #PB_Event_Timer
    state ! 1
    If state :
      ChangeWindowIcon("c:\path2\icon2.ico") 
    Else
      ChangeWindowIcon("c:\path1\icon1.ico") 
      
    EndIf 
    
  EndIf
  
Until EventID = #PB_Event_CloseWindow

novablue
Enthusiast
Enthusiast
Posts: 165
Joined: Sun Nov 27, 2016 6:38 am

Re: Update Icon in Task manager of my own program?

Post by novablue »

firace wrote: Wed Sep 08, 2021 7:19 am Try this (change the paths to point to your icons first):

Code: Select all

Procedure ChangeWindowIcon(Image$)  
  hIcon = LoadImage(0,Image$)
  SetClassLongPtr_(WindowID(0),#GCL_HICON,hIcon )
EndProcedure 

OpenWindow(0, 200, 200, 320,240, "Test Window", #PB_Window_SystemMenu )

AddWindowTimer(0,1, 2000)

Repeat    
  EventID.l = WaitWindowEvent()  
  If EventID = #PB_Event_Timer
    state ! 1
    If state :
      ChangeWindowIcon("c:\path2\icon2.ico") 
    Else
      ChangeWindowIcon("c:\path1\icon1.ico") 
      
    EndIf 
    
  EndIf
  
Until EventID = #PB_Event_CloseWindow

It seems the task manager only dynamically displays the Icon of the exe (not the window) if the systray icon is changed.
Post Reply