您的位置:首页 > 产品设计 > UI/UE

GUI 剖析之控件篇之 进度条

2012-11-18 13:59 246 查看
进度条控件:



执行步骤:
1. 拖放进度条控件至对话框
2. 执行以下代码(假设ID为:IDC_PROGRESS1)
#include "Commctrl.h"
#pragma comment(lib,"comctl32.lib")

设置进度条控件范围:
static LONGnMinPos=0, nMaxPos=100,nPos=0;
hwndPress=GetDlgItem(hDlg,IDC_PROGRESS1);
SendMessage(hwndPress,SBM_SETRANGE,nMinPos,nMaxPos
);
改变进度条进度位置:
SendMessage(hwndPress,PBM_SETPOS, (WPARAM)nPos,
0 );
设置进度条颜色:
SendMessage(hwndPress,PBM_SETBARCOLOR ,0,RGB(0,0,0));
设置进度条背景色:
SendMessage(hwndPress,PBM_SETBKCOLOR ,0,RGB(0,0,0));
设置进度条状态:
SendMessage(hwndPress,PBM_SETSTATE,PBST_NORMAL,0);//这里的PBST_PAUSED也可以是PBST_NORMAL或PBST_ERROR
还有的其他消息可以去参考MSDN.

ps:下面是我参考MSDN写的一个类,用于手动创建进度条(包含两个文件)
ProgressBarWhenEnter.h

#pragma once

#include "stdafx.h"

class CProgress

{

public:

CProgress(RECT rect,HINSTANCE hInst,int ID,HWND hParent);

~CProgress();

BOOL Create();

void SetStartPos(long InitPos);

void SetPos(long nPos);

void SetRange(long nMinPos,long nMaxPos);

private:

RECT m_Rect;

HINSTANCE m_hInst;

int m_ID;

HWND m_hProcess;

HWND m_hParent;

};

ProgressBarWhenEnter.cpp

#pragma once

#include "stdafx.h"

#include "ProgressBarWhenEnter.h"

CProgress::CProgress(RECT rect,HINSTANCE hInst,int ID,HWND hParent)

{

INITCOMMONCONTROLSEX iccx;

iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);

iccx.dwICC = ICC_PROGRESS_CLASS;

if (!InitCommonControlsEx(&iccx))

return;

m_Rect=rect;

m_hInst=hInst;

m_ID=ID;

m_hParent=hParent;

}

CProgress::~CProgress()

{

DestroyWindow(m_hProcess);

}

BOOL CProgress::Create()

{

m_hProcess=CreateWindowEx(0, PROGRESS_CLASS, 0,

WS_CHILD | WS_VISIBLE|PBS_SMOOTH, m_Rect.left, m_Rect.top, m_Rect.right, m_Rect.bottom,

m_hParent, (HMENU)m_ID, m_hInst, 0);

if (m_hProcess!=NULL)

{

return TRUE;

}

return FALSE;

}

void CProgress::SetStartPos(long InitPos)

{

SendMessage(m_hProcess, PBM_SETPOS, (WPARAM)InitPos, 0);

}

void CProgress::SetPos(long nPos)

{

SendMessage(m_hProcess, PBM_SETPOS, (WPARAM)nPos, 0);

}

void CProgress::SetRange(long nMinPos,long nMaxPos)

{

SendMessage(m_hProcess,SBM_SETRANGE,nMinPos,nMaxPos );

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: