程序运行过程中,如何修改呢?例如:有时候需要PBS_SMOOTH类型,有时候去掉,怎么做?我用ModifyStyle()修改了,可是显示的时候还是不变的,怎么回事〉?

解决方案 »

  1.   

    给你一段代码,看看吧:
    #if !defined(AFX_PROGRESSPAGE_H__7D3F22FE_100B_47D2_B9C9_F2C5F2E37538__INCLUDED_)
    #define AFX_PROGRESSPAGE_H__7D3F22FE_100B_47D2_B9C9_F2C5F2E37538__INCLUDED_#if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // ProgressPage.h : header file
    ///////////////////////////////////////////////////////////////////////////////
    // CProgressPage dialogclass CProgressPage : public CPropertyPage
    {
    DECLARE_DYNCREATE(CProgressPage)// Construction
    public:
    CProgressPage();
    ~CProgressPage();// Dialog Data
    //{{AFX_DATA(CProgressPage)
    enum { IDD = IDD_PROGRESS_DLG };
    UINT m_From;
    UINT m_To;
    UINT m_Pos;
    UINT m_Step;
    UINT m_Delta;
    BOOL m_bSmooth;
    BOOL m_bVertical;
    //}}AFX_DATA
    // Overrides
    // ClassWizard generate virtual function overrides
    //{{AFX_VIRTUAL(CProgressPage)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    // Generated message map functions
    //{{AFX_MSG(CProgressPage)
    virtual BOOL OnInitDialog();
    afx_msg void OnBtstep();
    afx_msg void OnSetpos();
    afx_msg void OnSetdelta();
    afx_msg void OnPbsVertical();
    afx_msg void OnPbsSmooth();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    public:
    CProgressCtrl m_Progress; void ChangeStyle(UINT dwStyle,BOOL bChange);
    };//{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_PROGRESSPAGE_H__7D3F22FE_100B_47D2_B9C9_F2C5F2E37538__INCLUDED_)
    // ProgressPage.cpp : implementation file
    //#include "stdafx.h"
    #include "CommCtrl2.h"
    #include "ProgressPage.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CProgressPage property pageIMPLEMENT_DYNCREATE(CProgressPage, CPropertyPage)CProgressPage::CProgressPage() : CPropertyPage(CProgressPage::IDD)
    {
    //{{AFX_DATA_INIT(CProgressPage)
    m_From = 0;
    m_To = 200;
    m_Pos = 0;
    m_Step = 10;
    m_Delta = 0;
    m_bSmooth = FALSE;
    m_bVertical = FALSE;
    //}}AFX_DATA_INIT
    m_psp.dwFlags &= ~PSP_HASHELP;
    }CProgressPage::~CProgressPage()
    {
    }void CProgressPage::DoDataExchange(CDataExchange* pDX)
    {
    CPropertyPage::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CProgressPage)
    DDX_Text(pDX, IDC_FROM, m_From);
    DDX_Text(pDX, IDC_TO, m_To);
    DDX_Text(pDX, IDC_POS, m_Pos);
    DDX_Text(pDX, IDC_STEP, m_Step);
    DDX_Text(pDX, IDC_DELTA, m_Delta);
    DDX_Check(pDX, IDC_PBS_SMOOTH, m_bSmooth);
    DDX_Check(pDX, IDC_PBS_VERTICAL, m_bVertical);
    //}}AFX_DATA_MAP
    }
    BEGIN_MESSAGE_MAP(CProgressPage, CPropertyPage)
    //{{AFX_MSG_MAP(CProgressPage)
    ON_BN_CLICKED(IDC_BTSTEP, OnBtstep)
    ON_BN_CLICKED(IDC_SETPOS, OnSetpos)
    ON_BN_CLICKED(IDC_SETDELTA, OnSetdelta)
    ON_BN_CLICKED(IDC_PBS_VERTICAL, OnPbsVertical)
    ON_BN_CLICKED(IDC_PBS_SMOOTH, OnPbsSmooth)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CProgressPage message handlersBOOL CProgressPage::OnInitDialog() 
    {
    CPropertyPage::OnInitDialog();

    // TODO: Add extra initialization here
    CWnd* pWnd = GetDlgItem(IDC_PROGRESSH);
    CRect rect;
    pWnd->GetWindowRect(&rect);
    ScreenToClient(&rect);
    m_Progress.Create(WS_VISIBLE|WS_CHILD,rect,this,IDC_PROGRESS);
    m_Progress.SetRange(static_cast<short>(m_From),static_cast<short>(m_To));
    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
    }void CProgressPage::OnBtstep() 
    {
    UpdateData();
    m_Progress.SetStep(m_Step);
    }void CProgressPage::OnSetpos() 
    {
    UpdateData();
    m_Progress.SetPos(m_Pos);
    }void CProgressPage::OnSetdelta() 
    {
    UpdateData();
    m_Progress.OffsetPos(m_Delta);
    }void CProgressPage::OnPbsVertical() 
    {
    UpdateData();
    ChangeStyle(PBS_VERTICAL,m_bVertical);
    }void CProgressPage::OnPbsSmooth() 
    {
    UpdateData();
    ChangeStyle(PBS_SMOOTH,m_bSmooth);
    }void CProgressPage::ChangeStyle(UINT dwStyle,BOOL bChange)
    {
    UINT nID;
    if(dwStyle == PBS_VERTICAL)
    {
    nID = (!bChange)?IDC_PROGRESSH :IDC_PROGRESSV;
    }
    else
    nID = IDC_PROGRESSH; CWnd* pWnd = GetDlgItem(nID);
    CRect rect;
    pWnd->GetWindowRect(&rect);
    ScreenToClient(&rect);
    if(bChange)
    {
    m_Progress.DestroyWindow(); m_Progress.Create(WS_VISIBLE|WS_CHILD|dwStyle,rect,
    this,IDC_PROGRESS);
    m_Progress.SetRange(m_From,m_To);
    }
    else
    {
    m_Progress.DestroyWindow(); m_Progress.Create(WS_VISIBLE|WS_CHILD,rect,
    this,IDC_PROGRESS);
    m_Progress.SetRange(m_From,m_To);
    }
    }