作者共发了4篇帖子。 字体大小:较小 - 100% (默认)▼  内容转换:不转换▼
 
点击 回复
391 3
【示例】C++显示Win7任务栏进度条,右下角附加小图标以及窗口预览
一派护法 十九级
1楼 发表于:2016-1-14 14:48
【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;
}

【最终效果】
一派护法 十九级
2楼 发表于:2016-1-14 14:49
本程序使用的菜单资源很简单:

一派护法 十九级
3楼 发表于:2016-1-14 14:49
最小化后,任务栏图标进度看得更清楚一些:

一派护法 十九级
4楼 发表于:2016-1-14 14:50

回复帖子

内容:
用户名: 您目前是匿名发表
验证码:
(快捷键:Ctrl+Enter)
 

本帖信息

点击数:391 回复数:3
评论数: ?
作者:巨大八爪鱼
最后回复:巨大八爪鱼
最后回复时间:2016-1-14 14:50
 
©2010-2024 Arslanbar Ver2.0
除非另有声明,本站采用知识共享署名-相同方式共享 3.0 Unported许可协议进行许可。