How to display text in system tray icon with win32 API?

后端 未结 3 1071
萌比男神i
萌比男神i 2021-02-06 02:26

Trying to create a small monitor application that displays current internet usage as percentage in system tray in C using win32 API.

Also wanting to use colour backgrou

3条回答
  •  南旧
    南旧 (楼主)
    2021-02-06 03:14

    The system tray only accepts icons to show, not text.

    To get a text shown there, you have to first create a memory bitmap, draw your text on it, then convert that memory bitmap to a memory icon and have the system tray show that icon.

    Example code below:

    CDC dcMem;
    dcMem.CreateCompatibleDC(NULL);
    
    CBitmap* pOld = dcMem.SelectObject( &m_bmpIcon );
    
    CBrush back( RGB(0,0,0) );
    dcMem.FillRect( CRect(0,0,16,16), &back );
    
    CBrush brush( COLORDOWN );
    dcMem.FillRect( rcRecv, &brush );
    
    dcMem.SelectObject( pOld );
    
    HICON hIcon = CreateIconIndirect( &m_TaskBarIconInfo );  
    

提交回复
热议问题