⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 progressbar.c

📁 在ecos 下mingui 的移植开发
💻 C
字号:
// $Id: progressbar.c,v 1.7 2000/11/17 07:02:01 ymwei Exp $//// progressbar.c: the Progress Bar Control module.//// Copyright (C) 1999, 2000, Wei Yongming.//// Current maintainer: Wei Yonming./***  This library is free software; you can redistribute it and/or**  modify it under the terms of the GNU Library General Public**  License as published by the Free Software Foundation; either**  version 2 of the License, or (at your option) any later version.****  This library is distributed in the hope that it will be useful,**  but WITHOUT ANY WARRANTY; without even the implied warranty of**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU**  Library General Public License for more details.****  You should have received a copy of the GNU Library General Public**  License along with this library; if not, write to the Free**  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,**  MA 02111-1307, USA*//***  Alternatively, the contents of this file may be used under the terms **  of the Mozilla Public License (the "MPL License") in which case the**  provisions of the MPL License are applicable instead of those above.*///// Note://   Originally by Zhao Jianghua. //// Create date: 1999/8/29//// Modify records:////  Who             When        Where       For What                Status//-----------------------------------------------------------------------------//  WEI Yongming    1999/10/27  Tsinghua    unsigned int            Finished//  WEI Yongming    1999/10/27  Tsinghua    FPException fixing      Finished//  WEI Yongming    2000/02/24  Tsinghua    Add MPL License         Finished//  WEI Yongming    2000/11/05  Wudaokou    Use memory DC.          Finished////#include <stdio.h>#include <stdlib.h>#include <pthread.h>#include <semaphore.h>#include "common.h"#include "minigui.h"#include "gdi.h"#include "window.h"#include "control.h"#include "cliprect.h"#include "internals.h"#include "ctrlclass.h"#include "ctrlmisc.h"#include "progressbar.h"#ifndef lintstatic char fileid[] = "$Id: progressbar.c,v 1.7 2000/11/17 07:02:01 ymwei Exp $";#endif#define  WIDTH_PBAR_BORDER  2 BOOL RegisterProgressBarControl (void){    WNDCLASS WndClass;    WndClass.spClassName = "progressbar";    WndClass.dwStyle     = 0;    WndClass.hCursor     = GetSystemCursor (0);    WndClass.iBkColor    = PIXEL_darkgray;    WndClass.WinProc     = ProgressBarCtrlProc;    return AddNewControlClass (&WndClass) == ERR_OK;}void ProgressBarControlCleanup (void){    // do nothing    return;}void pbarOnDraw (HWND hwnd, HDC hdc,             PROGRESSDATA* pData, BOOL fVertical){    RECT    rcClient;    int     x, y, w, h;    ldiv_t   ndiv_progress;    unsigned int     nAllPart;    unsigned int     nNowPart;    int     whOne, nRem;    int     ix, iy;    int     i;    char    szText[8] = "\0";    int     step;        if (pData->nMax == pData->nMin)        return;        if ((pData->nMax - pData->nMin) > 5)        step = 5;    else        step = 1;    GetClientRect (hwnd, &rcClient);    x = rcClient.left + WIDTH_PBAR_BORDER;    y = rcClient.top + WIDTH_PBAR_BORDER;    w = RECTW (rcClient) - (WIDTH_PBAR_BORDER << 1);    h = RECTH (rcClient) - (WIDTH_PBAR_BORDER << 1);    ndiv_progress = ldiv (pData->nMax - pData->nMin, step);    nAllPart = ndiv_progress.quot;        ndiv_progress = ldiv (pData->nPos - pData->nMin, step);    nNowPart = ndiv_progress.quot;    if (fVertical)        ndiv_progress = ldiv (h, nAllPart);    else        ndiv_progress = ldiv (w, nAllPart);            whOne = ndiv_progress.quot;    nRem = ndiv_progress.rem;    SetBrushColor (hdc, PIXEL_darkgray);    FillBox (hdc, x, y, w, h);    SetBrushColor (hdc, PIXEL_blue);     if(whOne >= 4) {        if (fVertical) {            for (i = 0, iy = y + h - 1; i < nNowPart; ++i) {                if ((iy - whOne) < y)                     whOne = iy - y;                FillBox (hdc, x, iy - whOne, w, whOne - 1);                iy -= whOne;                if(nRem > 0) {                    iy --;                    nRem --;                }            }        }        else {            for (i = 0, ix = x + 1; i < nNowPart; ++i) {                if ((ix + whOne) > (x + w))                     whOne = x + w - ix;                FillBox (hdc, ix, y, whOne - 1, h);                ix += whOne;                if(nRem > 0) {                    ix ++;                    nRem --;                }            }        }    }    else {        // no vertical support        double d = (nNowPart*1.0)/nAllPart;                SetBrushColor (hdc, PIXEL_blue);        FillBox (hdc, x, y, (int)(w*d), h - 1);        SetTextColor (hdc, PIXEL_lightwhite);        SetBkMode (hdc, BM_TRANSPARENT);        sprintf (szText, "%d%%", (int)(d*100));        TextOut (hdc, x + ((w - GetSysCharWidth () * strlen (szText))>>1),                       y + ((h - GetSysCharHeight())>>1),                       szText);    }}static void pbarNormalizeParams (const CONTROL* pCtrl,                 PROGRESSDATA* pData, BOOL fNotify){    if (pData->nPos > pData->nMax) {        if (fNotify)            NotifyParent ((HWND)pCtrl, pCtrl->id, PBN_REACHMAX);        pData->nPos = pData->nMax;    }    if (pData->nPos < pData->nMin) {        if (fNotify)            NotifyParent ((HWND)pCtrl, pCtrl->id, PBN_REACHMIN);        pData->nPos = pData->nMin;    }}int	ProgressBarCtrlProc (HWND hwnd, int message, WPARAM wParam, LPARAM lParam){    HDC           hdc;    PCONTROL      pCtrl;    PROGRESSDATA* pData;        pCtrl = Control (hwnd);         switch (message)    {        case MSG_CREATE:            if (!(pData = malloc (sizeof (PROGRESSDATA)))) {                fprintf(stderr, "Create progress bar control failure!\n");                return -1;            }                        pData->nMax     = 100;            pData->nMin     = 0;            pData->nPos     = 0;            pData->nStepInc = 10;                        pCtrl->dwAddData2 = (DWORD)pData;        break;            case MSG_DESTROY:            free ((void *)(pCtrl->dwAddData2));        break;        case MSG_NCPAINT:        return 0;                case MSG_GETDLGCODE:            return DLGC_STATIC;        case MSG_GETTEXTLENGTH:        case MSG_GETTEXT:        case MSG_SETTEXT:            return -1;        case MSG_PAINT:        {            RECT rcClient;            HDC mem_dc;                        GetClientRect (hwnd, &rcClient);            hdc = BeginPaint (hwnd);            mem_dc = CreateCompatibleDC (hdc);            Draw3DDownFrame (mem_dc, rcClient.left, rcClient.top,                              rcClient.right - 1, rcClient.bottom - 1,                              PIXEL_invalid);            pbarOnDraw (hwnd, mem_dc, (PROGRESSDATA *)pCtrl->dwAddData2,                             pCtrl->dwStyle & PBS_VERTICAL);                 BitBlt (mem_dc, 0, 0, rcClient.right, rcClient.bottom, hdc, 0, 0, 0);            DeleteCompatibleDC (mem_dc);            EndPaint (hwnd, hdc);        }        break;        case PBM_SETRANGE:            pData = (PROGRESSDATA *)pCtrl->dwAddData2;            pData->nMin = min (wParam, lParam);            pData->nMax = max (wParam, lParam);            if (pData->nPos > pData->nMax)                pData->nPos = pData->nMax;            if (pData->nPos < pData->nMin)                pData->nPos = pData->nMin;        break;                case PBM_SETSTEP:            pData = (PROGRESSDATA *)pCtrl->dwAddData2;            pData->nStepInc = wParam;        break;                case PBM_SETPOS:            pData = (PROGRESSDATA *)pCtrl->dwAddData2;                        if (pData->nPos == wParam)                break;            pData->nPos = wParam;            pbarNormalizeParams (pCtrl, pData, pCtrl->dwStyle & PBS_NOTIFY);            InvalidateRect (hwnd, NULL, FALSE);        break;                case PBM_DELTAPOS:            pData = (PROGRESSDATA *)pCtrl->dwAddData2;            if (wParam == 0)                break;                        pData->nPos += wParam;            pbarNormalizeParams (pCtrl, pData, pCtrl->dwStyle & PBS_NOTIFY);                            InvalidateRect (hwnd, NULL, FALSE);        break;                case PBM_STEPIT:            pData = (PROGRESSDATA *)pCtrl->dwAddData2;                        if (pData->nStepInc == 0)                break;            pData->nPos += pData->nStepInc;            pbarNormalizeParams (pCtrl, pData, pCtrl->dwStyle & PBS_NOTIFY);            InvalidateRect (hwnd, NULL, FALSE);        break;                    default:        break;    }        return DefaultControlProc (hwnd, message, wParam, lParam);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -