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 );
}
执行步骤:
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 );
}
相关文章推荐
- GUI 剖析之控件篇之复选框
- GUI 剖析之控件篇之 组合框
- GUI 剖析之控件篇之 列表框
- GUI 剖析之列表框控件(ListView)
- GUI 剖析之控件篇之 静态文本框
- GUI 剖析之控件篇之 编辑框
- GUI 剖析之控件篇之 动画控件
- GUI 剖析之控件篇之 滑动条控件
- GUI 剖析之控件篇之 图片控件
- 为OLED屏增加GUI支持6:进度条控件
- 为OLED屏增加GUI支持6:进度条控件
- GUI 剖析之 控件篇1)按钮控件
- 为OLED屏添加GUI支持6:进度条控件
- 用htc实现进度条控件
- GUI典型控件总结
- 又一个用VB编写ActiveX自定义控件的例子——进度条控件
- Unity3D学习笔记(一)GUI控件的调用
- MFC控件(三)(进度条控件和滑块控件)
- .net WinForm 控件的事件委托剖析
- QT中线程调用GUI主线程控件的问题