【C++代码】
#include <tchar.h>
#include <Windows.h>
#include <CommCtrl.h>
#include <Shobjidl.h>
#include "resource.h"
#pragma comment(lib, "Comctl32.lib")
#pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#define WM_TASKBARBUTTONCREATED wm_taskbarbuttoncreated
HINSTANCE hInst;
UINT WM_TASKBARBUTTONCREATED;
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
if (uMsg == WM_TASKBARBUTTONCREATED)
{
ITaskbarList3* pITaskBarList3;
CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_INPROC_SERVER, IID_ITaskbarList3, (LPVOID *)&pITaskBarList3);
pITaskBarList3->HrInit();
pITaskBarList3->SetProgressState(hWnd, TBPF_NORMAL);
pITaskBarList3->SetProgressValue(hWnd, 50, 100);
HINSTANCE hShellInst = GetModuleHandle(TEXT("shell32.dll"));
HICON hicon;
LoadIconMetric(hShellInst, MAKEINTRESOURCE(247), LIM_LARGE, &hicon);
pITaskBarList3->SetOverlayIcon(hWnd, hicon, TEXT("My Overlay Icon"));
DestroyIcon(hicon);
RECT rcClip;
rcClip.left = rcClip.top = 0;
rcClip.right = 98;
rcClip.bottom = 156;
pITaskBarList3->SetThumbnailClip(hWnd, &rcClip);
pITaskBarList3->SetThumbnailTooltip(hWnd, TEXT("My ToolTip"));
}
switch (uMsg)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch (wmId)
{
case ID_FILE_EXIT:
DestroyWindow(hWnd);
break;
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
HPEN hpen = CreatePen(PS_SOLID, 2, RGB(37, 45, 141));
HPEN hpenOld = (HPEN)SelectObject(hdc, hpen);
HBRUSH hbrush = GetSysColorBrush(COLOR_HIGHLIGHT);
HBRUSH hbrOld = (HBRUSH)SelectObject(hdc, hbrush);
Rectangle(hdc, 10, 10, 90, 90);
SelectObject(hdc, hpenOld);
DeleteObject(hpen);
SelectObject(hdc, hbrOld);
DeleteObject(hbrush);
SetTextColor(hdc, RGB(40, 210, 118));
TextOut(hdc, 10, 100, TEXT("Name"), 4);
EndPaint(hWnd, &ps);
}
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return FALSE;
}
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
HINSTANCE hShellInst = GetModuleHandle(TEXT("shell32.dll"));
WNDCLASSEX wcex;
ZeroMemory(&wcex, sizeof(WNDCLASSEX));
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
LoadIconMetric(hShellInst, MAKEINTRESOURCE(4), LIM_LARGE, &wcex.hIcon);
LoadIconMetric(hShellInst, MAKEINTRESOURCE(4), LIM_SMALL, &wcex.hIconSm);
wcex.hInstance = hInst = hInstance;
wcex.lpfnWndProc = WndProc;
wcex.lpszClassName = TEXT("My Taskbar Window");
wcex.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
RegisterClassEx(&wcex);
WM_TASKBARBUTTONCREATED = RegisterWindowMessage(TEXT("TaskbarButtonCreated"));
HWND hwnd = CreateWindow(wcex.lpszClassName, TEXT("Welcome"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hwnd)
return 1;
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
【最终效果】