目前共有4篇帖子。 字體大小:較小 - 100% (默認)▼  內容轉換:不轉換▼
 
點擊 回復
388 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)
 

本帖信息

點擊數:388 回複數:3
評論數: ?
作者:巨大八爪鱼
最後回復:巨大八爪鱼
最後回復時間:2016-1-14 14:50
 
©2010-2024 Arslanbar Ver2.0
除非另有聲明,本站採用共享創意姓名標示-相同方式分享 3.0 Unported許可協議進行許可。