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

📄 progress.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
字号:
/* 
Copyright 2001-2003 Free Software Foundation, Inc.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.  

You may contact the author at:

mailto::camille@bluegrass.net

or by snail mail at:

David Lindauer
850 Washburn Ave Apt 99
Louisville, KY 40222

 **********************************************************************
 * This file puts up a simple progress bar dialog
 * and allows you to update it
 *
 * only one progress bar allowed!
 *
 * David Lindauer, camille@bluegrass.net
 *
 * PUBLIC DOMAIN

 **********************************************************************
 */
#include <windows.h>
#include <stdio.h>
#include <commctrl.h>
#include <stdarg.h>

#include "header.h"
#include "progress.h"
#include "winconst.h"

static char *szProgName = "LADPROGRESS";
// ==============================================================
//
/*
 * Progress bar window, or zero if no progress bar
 */
HWND hWndProgress;

/* limit of progress bar */
static int proglim = 0;

// ==============================================================
//
/* progress bar dialog box */
int FAR PASCAL ProgressProc(HWND hWndDlg, UINT wmsg, WPARAM wparam, LPARAM
    lparam)
{
    switch (wmsg)
    {
        case WM_INITDIALOG:
            CenterWindow(hWndDlg);
            SetProgress(0, "");
            return TRUE;
        case WM_CLOSE:
            PostMessage(hWndDlg, WM_COMMAND, IDCANCEL, 0L);
            return TRUE;

        case WM_COMMAND:
            switch (LOWORD(wparam))
            {
            case IDCANCEL:
                /* They pressed cancel, get out */
                DeleteProgress();
                break;
            }
    }
    return 0;
}

// ==============================================================
//
/* Build the progress bar, set a limit and title */
void MakeProgress(HWND hWnd, HINSTANCE hInst, LPCSTR title, long value)
{
    /* Can't have a progress bar with a limit of 0 */
    if (value == 0)
        return ;

    /* Set new limit */
    proglim = value;

    /* Get out if bar already up */
    if (hWndProgress)
        return ;

    /* Make window and set title */
    hWndProgress = CreateDialog(hInst, "DLG_PROGRESS", hWnd, ProgressProc);
    SetWindowText(hWndProgress, title);

    SendMessage(hWndProgress, PBM_SETSTEP, 4, 0);
}

// ==============================================================
//
/* Delete the progress bar window */
void DeleteProgress(void)
{
    if (hWndProgress)
    {
        DestroyWindow(hWndProgress);
        hWndProgress = NULL;
    }
}

// ==============================================================
//
/* Set the text field and the progress bar current value fields */
void SetProgress(long value, LPCSTR fmt, ...)
{
    /* calculate percentage */
    long percent = value * 100 / proglim;
    char string[10], text[100];
    HWND hWndTemp;
    va_list argptr;

    /* Never greater than 100 percent */
    if (percent > 100)
        percent = 100;

    /* Collect the string for the caption field */

    va_start(argptr, fmt);
    vsprintf(text, fmt, argptr);
    va_end(argptr);

    /* Now set the text of the caption field */
    hWndTemp = GetDlgItem(hWndProgress, IDC_PBNAME);
    SendMessage(hWndTemp, WM_SETTEXT, 0, (LPARAM)text);

    /* Now set the percentage field on the right */
    sprintf(string, "%d%%   ", percent);
    hWndTemp = GetDlgItem(hWndProgress, IDC_PBPERCENT);
    SendMessage(hWndTemp, WM_SETTEXT, 0, (LPARAM)string);

    /* Now set the progress bar percentage */
    hWndTemp = GetDlgItem(hWndProgress, IDC_PROGRESSBAR);
    SendMessage(hWndTemp, PBM_SETPOS, percent, 0);
}

⌨️ 快捷键说明

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