StatusBar 状态栏

本文介绍了一个用于创建和操作C++状态栏控件的类库的使用方法,包括初始化、销毁、部分重置、插入控件、文本设置等核心功能。详细解释了如何在父窗口中创建状态栏,以及如何通过窗口消息进行状态栏的动态更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

statusbar.hpp
#ifndef    statusbarH
#define statusbarH

#include <Windows.h>
#include <list>

namespace NSTS {
class CStatusBar {
public:
CStatusBar (void);
~CStatusBar (void);

public:
bool Init (HWND hParent, int iSize, int agiParts[], HINSTANCE hInst);
void Destroy (void);
bool ResetParts (int iSize, int agiParts[]);
void Flash (void);

bool InsertCtrl (int iPos, HWND hwnd);
bool RemoveCtrl (int iPos);

bool SetText (int iPos, const TCHAR* pszText);
bool GetText (int iPos, TCHAR* pszText);

bool SetBk (COLORREF clrBk);
COLORREF GetBk (void);

bool SetIcon (int iPos, HICON hIcon);
HICON GetIcon (int iPos);
bool SetIcon (int iPos, UINT uId) {
HICON hIcon = LoadIcon (m_hInst, MAKEINTRESOURCE (uId));
bool fRet = SetIcon (iPos, hIcon);
DestroyIcon (hIcon);
return fRet;
};

bool SetTip (int iPos, const TCHAR* pszText);
bool GetTip (int iPos, TCHAR* pszText);

bool SetMinHeight (int iHeight);
int GetHeight (void);

bool SetUnicode (BOOL fUnicode);
bool IsUnicode (void);

HWND GetParent (void) const { return m_hParent; };
HWND GetSelf (void) const { return m_hSelf; };

private:
void InsertCtrlCore (int iPos, HWND hwnd);

private:
HWND m_hSelf;
HWND m_hParent;
int m_iSize;
HINSTANCE m_hInst;

COLORREF m_clrBk;

struct SBControl {
int iPos;
HWND hwnd;
};
std::list <CStatusBar::SBControl> m_lstCtrls; // used for RemoveCtrl
};
}

#endif // statusbarH
statusbar.cpp
#include "statusbar.hpp"
#include <commctrl.h>

namespace NSTS {
CStatusBar::
CStatusBar (void)
{
m_hSelf = m_hParent = NULL;
m_iSize = 0;
m_hInst = NULL;
m_clrBk = CLR_DEFAULT;
m_lstCtrls.clear ();
}


CStatusBar::
~CStatusBar (void)
{
if (m_hSelf != NULL) {
if (IsWindow (m_hSelf)) {
DestroyWindow (m_hSelf);
}
m_hSelf = NULL;
}

m_hParent = NULL;
m_hInst = NULL;
m_clrBk = CLR_DEFAULT;
m_lstCtrls.clear ();
}

bool
CStatusBar::
Init (HWND hParent, int iSize, int agiParts[], HINSTANCE hInst)
{
if (hParent == NULL || !IsWindow (hParent) ||
iSize <=0 ||
agiParts == NULL ||
hInst == NULL) {
return false;
}

InitCommonControls ();

m_hInst = hInst;
m_hSelf = CreateWindowEx(
0, // no extended styles
STATUSCLASSNAME, // name of status bar class
(LPCTSTR) NULL, // no text when first created
SBT_TOOLTIPS | SBARS_SIZEGRIP | WS_CHILD | WS_VISIBLE, // creates a child window
0, 0, 0, 0, // ignores size and position
hParent, // handle to parent window
NULL, // child window identifier
hInst, // handle to application instance
NULL); // no window creation data

if (m_hSelf == NULL) {
return false;
}

return ResetParts (iSize, agiParts);
}

void
CStatusBar::
Destroy (void)
{
if (m_hSelf != NULL && IsWindow (m_hSelf)) {
DestroyWindow (m_hSelf);
m_hSelf = NULL;
}
}

bool
CStatusBar::
ResetParts (int iSize, int agiParts[])
{
HLOCAL hloc;
int* piParts;
int i;
std::list <CStatusBar::SBControl>::iterator it;

if (m_hSelf == NULL || !IsWindow (m_hSelf)) {
return false;
}

hloc = LocalAlloc (LHND, sizeof (int) * iSize);

if (hloc == NULL) {
return false;
}

piParts = (int*)LocalLock (hloc);

for (i = 0; i < iSize; ++i) {
piParts [i] = agiParts [i];
}

SendMessage (m_hSelf, SB_SETPARTS, (WPARAM)iSize, (LPARAM)piParts);

LocalUnlock (hloc);
LocalFree (hloc);

m_iSize = iSize;

for (it = m_lstCtrls.begin (); it != m_lstCtrls.end (); ++it) {
if (it->hwnd != NULL && IsWindow (it->hwnd)) {
InsertCtrlCore (it->iPos, it->hwnd);
}
}

return true;
}


void
CStatusBar::
Flash (void)
{
if (m_hSelf != NULL && IsWindow (m_hSelf)) {
SendMessage (m_hSelf, WM_SIZE, (WPARAM)0, (LPARAM)0);
}
}


void
CStatusBar::
InsertCtrlCore (int iPos, HWND hwnd)
{
RECT rcPart, rcCtrl;
int iPartWidth, iCtrlWidth, iPartHeight, iCtrlHeight;
int iWidth, iHeight, iX, iY;

/** HWND, draw it */
SendMessage (m_hSelf, SB_GETRECT, (WPARAM)iPos, (LPARAM)&rcPart);
GetWindowRect (hwnd, &rcCtrl);

iPartWidth = rcPart.right - rcPart.left;
iPartHeight = rcPart.bottom - rcPart.top;
iCtrlWidth = rcCtrl.right - rcCtrl.left;
iCtrlHeight = rcCtrl.bottom - rcCtrl.top;

iX = rcPart.left;

if (iPartWidth < iCtrlWidth) {
iWidth = iPartWidth;
} else {
iWidth = iCtrlWidth;
}

if (iPartHeight <= iCtrlHeight) {
iHeight = iPartHeight;
iY = rcPart.top;
} else {
iHeight = iCtrlHeight;
iY = rcPart.top + (iPartHeight - iCtrlHeight) / 2;
}


/** set parent */
SetParent (hwnd, m_hSelf);

/** move it to the correct pos */
MoveWindow (
hwnd,
iX,
iY,
iWidth,
iHeight,
FALSE);

/** show it */
ShowWindow (hwnd, SW_SHOW);
}


bool
CStatusBar::
InsertCtrl (int iPos, HWND hwnd)
{
CStatusBar::SBControl ctrl = {iPos, hwnd};

if (m_hSelf == NULL || !IsWindow (m_hSelf) ||
hwnd == NULL || !IsWindow (hwnd) ||
iPos < 0 || iPos >= m_iSize) {
return false;
}

InsertCtrlCore (iPos, hwnd);

m_lstCtrls.push_back (ctrl);
return true;
}


bool
CStatusBar::
RemoveCtrl (int iPos)
{
std::list <CStatusBar::SBControl>::iterator it;
if (m_hSelf == NULL || !IsWindow (m_hSelf) ||
iPos < 0 || iPos >= m_iSize) {
return false;
}

for (it = m_lstCtrls.begin (); it != m_lstCtrls.end (); ++it) {
if (it->iPos == iPos) {
if (it->hwnd != NULL && IsWindow (it->hwnd)) {
DestroyWindow (it->hwnd);
m_lstCtrls.erase (it);
return true;
}
m_lstCtrls.erase (it);
return false;
}
}

return false;
}


bool
CStatusBar::
SetText (int iPos, const TCHAR* pszText)
{
if (m_hSelf == NULL || !IsWindow (m_hSelf) ||
pszText == NULL ||
iPos < 0 || iPos >= m_iSize) {
return false;
}

return SendMessage (m_hSelf, SB_SETTEXT, (WPARAM)iPos, (LPARAM)pszText);
}

bool
CStatusBar::
GetText (int iPos, TCHAR* pszText)
{
if (m_hSelf == NULL || !IsWindow (m_hSelf) ||
pszText == NULL ||
iPos < 0 || iPos >= m_iSize) {
return false;
}

SendMessage (m_hSelf, SB_GETTEXT, (WPARAM)iPos, (LPARAM)pszText);
return true;
}

bool
CStatusBar::
SetBk (COLORREF clrBk)
{
if (m_hSelf == NULL || !IsWindow (m_hSelf)) {
return false;
}

m_clrBk = SendMessage (m_hSelf, SB_SETBKCOLOR, (WPARAM)0, (LPARAM)clrBk);
return true;
}

COLORREF
CStatusBar::
GetBk (void)
{
return m_clrBk;
}

bool
CStatusBar::
SetIcon (int iPos, HICON hIcon)
{
if (m_hSelf == NULL || !IsWindow (m_hSelf) ||
iPos < 0 || iPos >= m_iSize ||
hIcon == NULL) {
return false;
}

return SendMessage (m_hSelf, SB_SETICON, (WPARAM)iPos, (LPARAM)hIcon);
}

HICON
CStatusBar::
GetIcon (int iPos)
{
if (m_hSelf == NULL || !IsWindow (m_hSelf) ||
iPos < 0 || iPos >= m_iSize) {
return NULL;
}

return (HICON)SendMessage (m_hSelf, SB_GETICON, (WPARAM)iPos, (LPARAM)0);
}

bool
CStatusBar::
SetTip (int iPos, const TCHAR* pszTip)
{
if (m_hSelf == NULL || !IsWindow (m_hSelf) ||
iPos < 0 || iPos >= m_iSize ||
pszTip == NULL) {
return false;
}

SendMessage (m_hSelf, SB_SETTIPTEXT, (WPARAM)iPos, (LPARAM)pszTip);
return true;
}

bool
CStatusBar::
GetTip (int iPos, TCHAR* pszTip)
{
if (m_hSelf == NULL || !IsWindow (m_hSelf) ||
iPos < 0 || iPos >= m_iSize ||
pszTip == NULL) {
return false;
}

SendMessage (m_hSelf, SB_GETTIPTEXT, (WPARAM)iPos, (LPARAM)pszTip);
return true;
}

bool
CStatusBar::
SetMinHeight (int iHeight)
{
std::list <CStatusBar::SBControl>::iterator it;
if (m_hSelf == NULL || !IsWindow (m_hSelf) ||
iHeight < 0) {
return false;
}

SendMessage (m_hSelf, SB_SETMINHEIGHT, (WPARAM)iHeight, (LPARAM)0);
Flash ();
for (it = m_lstCtrls.begin (); it != m_lstCtrls.end (); ++it) {
if (it->hwnd != NULL && IsWindow (it->hwnd)) {
InsertCtrlCore (it->iPos, it->hwnd);
}
}
return true;
}


int
CStatusBar::
GetHeight (void)
{
RECT rect;
if (m_hSelf == NULL || !IsWindow (m_hSelf)) {
return 0;
}

if (GetWindowRect (m_hSelf, &rect)) {
return (rect.bottom - rect.top);
}

return 0;
}

bool
CStatusBar::
SetUnicode (BOOL fUnicode)
{
if (m_hSelf == NULL || !IsWindow (m_hSelf)) {
return false;
}

SendMessage (m_hSelf, SB_SETUNICODEFORMAT, (WPARAM)fUnicode, (LPARAM)0);
return true;
}

bool
CStatusBar::
IsUnicode (void)
{
if (m_hSelf == NULL || !IsWindow (m_hSelf)) {
return false;
}

return SendMessage (m_hSelf, SB_GETUNICODEFORMAT, (WPARAM)0, (LPARAM)0);
}

}

 

Usage:

NSTS::CStatusBar sb;

extern HWND hParent;
extern HINSTANCE hInst;

int i = 3;
int lens[3] = {100, 100, -1};
sb.Init (hParent, 3, lens, hInst);

sb.SetBk (...);
sb.InsertCtrl (hwnd);
...

------

在父窗口中,WM_SIZE:

sb.Flash ();



 

转载于:https://www.cnblogs.com/lin1270/archive/2012/01/09/2317232.html

JFM7VX690T型SRAM型现场可编程门阵列技术手册主要介绍的是上海复旦微电子集团股份有限公司(简称复旦微电子)生产的高性能FPGA产品JFM7VX690T。该产品属于JFM7系列,具有现场可编程特性,集成了功能强大且可以灵活配置组合的可编程资源,适用于实现多种功能,如输入输出接口、通用数字逻辑、存储器、数字信号处理和时钟管理等。JFM7VX690T型FPGA适用于复杂、高速的数字逻辑电路,广泛应用于通讯、信息处理、工业控制、数据中心、仪表测量、医疗仪器、人工智能、自动驾驶等领域。 产品特点包括: 1. 可配置逻辑资源(CLB),使用LUT6结构。 2. 包含CLB模块,可用于实现常规数字逻辑和分布式RAM。 3. 含有I/O、BlockRAM、DSP、MMCM、GTH等可编程模块。 4. 提供不同的封装规格和工作温度范围的产品,便于满足不同的使用环境。 JFM7VX690T产品系列中,有多种型号可供选择。例如: - JFM7VX690T80采用FCBGA1927封装,尺寸为45x45mm,使用锡银焊球,工作温度范围为-40°C到+100°C。 - JFM7VX690T80-AS同样采用FCBGA1927封装,但工作温度范围更广,为-55°C到+125°C,同样使用锡银焊球。 - JFM7VX690T80-N采用FCBGA1927封装和铅锡焊球,工作温度范围与JFM7VX690T80-AS相同。 - JFM7VX690T36的封装规格为FCBGA1761,尺寸为42.5x42.5mm,使用锡银焊球,工作温度范围为-40°C到+100°C。 - JFM7VX690T36-AS使用锡银焊球,工作温度范围为-55°C到+125°C。 - JFM7VX690T36-N使用铅锡焊球,工作温度范围与JFM7VX690T36-AS相同。 技术手册中还包含了一系列详细的技术参数,包括极限参数、推荐工作条件、电特性参数、ESD等级、MSL等级、重量等。在产品参数章节中,还特别强调了封装类型,包括外形图和尺寸、引出端定义等。引出端定义是指对FPGA芯片上的各个引脚的功能和接线规则进行说明,这对于FPGA的正确应用和电路设计至关重要。 应用指南章节涉及了FPGA在不同应用场景下的推荐使用方法。其中差异说明部分可能涉及产品之间的性能差异;关键性能对比可能包括功耗与速度对比、上电浪涌电流测试情况说明、GTH Channel Loss性能差异说明、GTH电源性能差异说明等。此外,手册可能还提供了其他推荐应用方案,例如不使用的BANK接法推荐、CCLK信号PCB布线推荐、JTAG级联PCB布线推荐、系统工作的复位方案推荐等,这些内容对于提高系统性能和稳定性有着重要作用。 焊接及注意事项章节则针对产品的焊接过程提供了指导,强调焊接过程中的注意事项,以确保产品在组装过程中的稳定性和可靠性。手册还明确指出,未经复旦微电子的许可,不得翻印或者复制全部或部分本资料的内容,且不承担采购方选择与使用本文描述的产品和服务的责任。 上海复旦微电子集团股份有限公司拥有相关的商标和知识产权。该公司在中国发布的技术手册,版权为上海复旦微电子集团股份有限公司所有,未经许可不得进行复制或传播。 技术手册提供了上海复旦微电子集团股份有限公司销售及服务网点的信息,方便用户在需要时能够联系到相应的服务机构,获取最新信息和必要的支持。同时,用户可以访问复旦微电子的官方网站(***以获取更多产品信息和公司动态。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值