尝试创建一个小型监视器应用程序,使用win32 API在C中的系统托盘中显示当前Internet使用率百分比.
还希望根据相对于月份剩余天数使用的颜色来使用彩色背景或彩色文本.
编辑:澄清我希望系统托盘图标是动态的.随着百分比的变化,我更新了系统托盘图标.寻找仅使用普通旧win32(即没有MFC或WTL)的解决方案.
好的,这是我的win32解决方案:
HICON CreateSmallIcon( HWND hWnd ) { static TCHAR *szText = TEXT ( "100" ); HDC hdc, hdcMem; HBITMAP hBitmap = NULL; HBITMAP hOldBitMap = NULL; HBITMAP hBitmapMask = NULL; ICONINFO iconInfo; HFONT hFont; HICON hIcon; hdc = GetDC ( hWnd ); hdcMem = CreateCompatibleDC ( hdc ); hBitmap = CreateCompatibleBitmap ( hdc, 16, 16 ); hBitmapMask = CreateCompatibleBitmap ( hdc, 16, 16 ); ReleaseDC ( hWnd, hdc ); hOldBitMap = (HBITMAP) SelectObject ( hdcMem, hBitmap ); PatBlt ( hdcMem, 0, 0, 16, 16, WHITENESS ); // Draw percentage hFont = CreateFont (12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TEXT ("Arial")); hFont = (HFONT) SelectObject ( hdcMem, hFont ); TextOut ( hdcMem, 0, 0, szText, lstrlen (szText) ); SelectObject ( hdc, hOldBitMap ); hOldBitMap = NULL; iconInfo.fIcon = TRUE; iconInfo.xHotspot = 0; iconInfo.yHotspot = 0; iconInfo.hbmMask = hBitmapMask; iconInfo.hbmColor = hBitmap; hIcon = CreateIconIndirect ( &iconInfo ); DeleteObject ( SelectObject ( hdcMem, hFont ) ); DeleteDC ( hdcMem ); DeleteDC ( hdc ); DeleteObject ( hBitmap ); DeleteObject ( hBitmapMask ); return hIcon; }