📄 listctrlstyled.cpp
字号:
{ // We must implement this method ourselve because we can't access directly to the lParam member
// When LVFI_PARAM is used, all other flag are ignored
//
int nItems = this->GetItemCount();
for(int nItem = nStart + 1; nItem < nItems; nItem++)
{ // Get lParam value for this item
//
LVITEM pItem;
InitLVITEM(nItem,0,&pItem);
LS_item * lpLS_item = NULL;
lpLS_item = (LS_item *)pItem.lParam;
if(lpLS_item->lParam == pFindInfo->lParam)
return nItem;
}
return -1;
}
else
{ // We can call the base class method
//
return CListCtrl::FindItem(pFindInfo,nStart);
}
}
// ********************************
// ** New STYLE Methods on Items **
// ********************************
void CListCtrlStyled::SetItemTxtColor(int nItem,int nSubItem,COLORREF txtColor,bool redraw)
{ // We must retrieve the Style info structure of this item
//
LVITEM pItem;
InitLVITEM(nItem,0,&pItem);
LS_item * lpLS_item = NULL;
lpLS_item = (LS_item*) pItem.lParam;
if(nSubItem > 0)
lpLS_item = lpLS_item->subitems[nSubItem - 1];
// no we can update the style
//
lpLS_item->txtColor = txtColor;
// Redraw it
if(redraw) CListCtrl::Update(nItem);
}
void CListCtrlStyled::SetItemBgColor(int nItem,int nSubItem,COLORREF txtBgColor,bool redraw)
{ // We must retrieve the Style info structure of this item
//
LVITEM pItem;
InitLVITEM(nItem,0,&pItem);
LS_item * lpLS_item = NULL;
lpLS_item = (LS_item*) pItem.lParam;
if(nSubItem > 0)
lpLS_item = lpLS_item->subitems[nSubItem - 1];
// no we can update the style
//
lpLS_item->bgColor = txtBgColor;
// Redraw it
if(redraw) CListCtrl::Update(nItem);
}
void CListCtrlStyled::SetItemStyle(int nItem,int nSubItem,DWORD Style,bool redraw)
{
// We must retrieve the Style info structure of this item
//
LVITEM pItem;
InitLVITEM(nItem,0,&pItem);
LS_item * lpLS_item = NULL;
lpLS_item = (LS_item*) pItem.lParam;
if(nSubItem > 0)
lpLS_item = lpLS_item->subitems[ nSubItem - 1];
// no we can update the style
//
lpLS_item->StyleFlag = Style;
DWORD mask = LIS_BOLD | LIS_ITALIC | LIS_UNDERLINE| LIS_STROKE ;
lpLS_item->in_use = (Style & mask) > 0;
// if any font exist for this item then delete it
//
this->Free_LS_font(lpLS_item);
// Redraw it
if(redraw) CListCtrl::Update(nItem);
}
void CListCtrlStyled::SetItemFont(int nItem,int nSubItem,CFont * pFont,bool redraw)
{
// We must retrieve the Style info structure of this item
//
LVITEM pItem;
InitLVITEM(nItem,0,&pItem);
LS_item * lpLS_item = NULL;
lpLS_item = (LS_item*) pItem.lParam;
if(nSubItem > 0)
lpLS_item = lpLS_item->subitems[ nSubItem - 1];
// if any internal font exist for this item then delete it
//
Free_LS_font(lpLS_item);
lpLS_item->cfont = pFont;
lpLS_item->ifont = false;
lpLS_item->in_use = true;
// Redraw it
if(redraw) CListCtrl::Update(nItem);
}
// *****************************************
// ** New STYLE Methods on SELECTED Items **
// *****************************************
void CListCtrlStyled::SetItemSelectedStyle(int nItem,int nSubItem,DWORD Style,bool redraw)
{ // We must retrieve the Style info structure of this item
//
LVITEM pItem;
InitLVITEM(nItem,0,&pItem);
LS_item * lpLS_item = NULL;
lpLS_item = (LS_item*) pItem.lParam;
if(nSubItem > 0)
lpLS_item = lpLS_item->subitems[ nSubItem - 1];
// Take the selected style structure
//
if(lpLS_item->selected_style == NULL)
{ // Create a structure style
//
lpLS_item->selected_style = new LS_item;
this->Init_LS_item( lpLS_item->selected_style );
}
lpLS_item = lpLS_item->selected_style;
// no we can update the style
//
lpLS_item->StyleFlag = Style;
DWORD mask = LIS_BOLD | LIS_ITALIC | LIS_UNDERLINE| LIS_STROKE ;
lpLS_item->in_use = (Style & mask) > 0;
// if any font exist for this item then delete it
//
this->Free_LS_font(lpLS_item);
// Redraw it
if(redraw) CListCtrl::Update(nItem);
}
void CListCtrlStyled::SetItemSelectedTxtColor(int nItem,int nSubItem,COLORREF txtColor,bool redraw)
{ // We must retrieve the Style info structure of this item
//
LVITEM pItem;
InitLVITEM(nItem,0,&pItem);
LS_item * lpLS_item = NULL;
lpLS_item = (LS_item*) pItem.lParam;
if(nSubItem > 0)
lpLS_item = lpLS_item->subitems[nSubItem - 1];
// Take the selected style structure
//
if(lpLS_item->selected_style == NULL)
{ // Create a structure style
//
lpLS_item->selected_style = new LS_item;
this->Init_LS_item( lpLS_item->selected_style );
}
lpLS_item = lpLS_item->selected_style;
// no we can update the style
//
lpLS_item->txtColor = txtColor;
// Redraw it
if(redraw) CListCtrl::Update(nItem);
}
void CListCtrlStyled::SetItemSelectedBgColor(int nItem,int nSubItem,COLORREF txtBgColor,bool redraw)
{ // We must retrieve the Style info structure of this item
//
LVITEM pItem;
InitLVITEM(nItem,0,&pItem);
LS_item * lpLS_item = NULL;
lpLS_item = (LS_item*) pItem.lParam;
if(nSubItem > 0)
lpLS_item = lpLS_item->subitems[nSubItem - 1];
// Take the selected style structure
//
if(lpLS_item->selected_style == NULL)
{ // Create a structure style
//
lpLS_item->selected_style = new LS_item;
this->Init_LS_item( lpLS_item->selected_style );
}
lpLS_item = lpLS_item->selected_style;
// no we can update the style
//
lpLS_item->bgColor = txtBgColor;
// Redraw it
if(redraw) CListCtrl::Update(nItem);
}
void CListCtrlStyled::SetItemSelectedFont(int nItem,int nSubItem,CFont * pFont,bool redraw)
{
// We must retrieve the Style info structure of this item
//
LVITEM pItem;
InitLVITEM(nItem,0,&pItem);
LS_item * lpLS_item = NULL;
lpLS_item = (LS_item*) pItem.lParam;
if(nSubItem > 0)
lpLS_item = lpLS_item->subitems[ nSubItem - 1];
// Take the selected style structure
//
if(lpLS_item->selected_style == NULL)
{ // Create a structure style
//
lpLS_item->selected_style = new LS_item;
this->Init_LS_item( lpLS_item->selected_style );
}
lpLS_item = lpLS_item->selected_style;
// if any internal font exist for this item then delete it
//
Free_LS_font(lpLS_item);
lpLS_item->cfont = pFont;
lpLS_item->ifont = false;
lpLS_item->in_use = true;
// Redraw it
if(redraw) CListCtrl::Update(nItem);
}
// *******************************
// ** New STYLE Methods on Rows **
// *******************************
void CListCtrlStyled::SetRowStyle(int nRow,DWORD Style,bool redraw)
{ // We must retrieve the Style info structure of this item
//
LVITEM pItem;
InitLVITEM(nRow,0,&pItem);
LS_item * lpLS_item = NULL;
lpLS_item = (LS_item*) pItem.lParam;
// Verify if a style for this Row already exist or not
//
LS_item * lpLS_row = NULL;
lpLS_row = lpLS_item->row_style;
if(lpLS_row == NULL)
{ // We must create one
//
lpLS_row = new LS_item;
this->Init_LS_item(lpLS_row,false);
// attach to the item
//
lpLS_item->row_style = lpLS_row;
}
// no we can update the style
//
lpLS_row->StyleFlag = Style;
DWORD mask = LIS_BOLD | LIS_ITALIC | LIS_UNDERLINE| LIS_STROKE ;
lpLS_row->in_use = (Style & mask) > 0;
// if any font exist for this item then delete it
//
this->Free_LS_font(lpLS_row);
// Redraw it
if(redraw) CListCtrl::Update(nRow);
}
void CListCtrlStyled::SetRowTxtColor(int nRow,COLORREF txtColor,bool redraw)
{ // We must retrieve the Style info structure of this item
//
LVITEM pItem;
InitLVITEM(nRow,0,&pItem);
LS_item * lpLS_item = NULL;
lpLS_item = (LS_item*) pItem.lParam;
// Verify if a style for this Row already exist or not
//
LS_item * lpLS_row = NULL;
lpLS_row = lpLS_item->row_style;
if(lpLS_row == NULL)
{ // We must create one
//
lpLS_row = new LS_item;
this->Init_LS_item(lpLS_row,false);
// attach to the item
//
lpLS_item->row_style = lpLS_row;
}
// no we can update the style
//
lpLS_row->txtColor = txtColor;
// Redraw it
if(redraw) CListCtrl::Update(nRow);
}
void CListCtrlStyled::SetRowBgColor(int nRow,COLORREF txtBgColor,bool redraw)
{ // We must retrieve the Style info structure of this item
//
LVITEM pItem;
InitLVITEM(nRow,0,&pItem);
LS_item * lpLS_item = NULL;
lpLS_item = (LS_item*) pItem.lParam;
// Verify if a style for this Row already exist or not
//
LS_item * lpLS_row = NULL;
lpLS_row = lpLS_item->row_style;
if(lpLS_row == NULL)
{ // We must create one
//
lpLS_row = new LS_item;
this->Init_LS_item(lpLS_row,false);
// attach to the item
//
lpLS_item->row_style = lpLS_row;
}
// no we can update the style
//
lpLS_row->bgColor = txtBgColor;
// Redraw it
if(redraw) CListCtrl::Update(nRow);
}
void CListCtrlStyled::SetRowFont(int nRow,CFont * pFont,bool redraw)
{ // We must retrieve the Style info structure of this item
//
LVITEM pItem;
InitLVITEM(nRow,0,&pItem);
LS_item * lpLS_item = NULL;
lpLS_item = (LS_item*) pItem.lParam;
// Verify if a style for this Row already exist or not
//
LS_item * lpLS_row = NULL;
lpLS_row = lpLS_item->row_style;
if(lpLS_row == NULL)
{ // We must create one
//
lpLS_row = new LS_item;
this->Init_LS_item(lpLS_row,false);
// attach to the item
//
lpLS_item->row_style = lpLS_row;
}
// if any internal font exist for this item then delete it
//
this->Free_LS_font(lpLS_row);
// no we can update the style
//
lpLS_row->cfont = pFont;
lpLS_row->ifont = false;
lpLS_row->in_use = true;
// Redraw it
if(redraw) CListCtrl::Update(nRow);
}
// ****************************************
// ** New STYLE Methods on SELECTED Rows **
// ****************************************
void CListCtrlStyled::SetRowSelectedStyle(int nRow,DWORD Style,bool redraw)
{ // We must retrieve the Style info structure of this item
//
LVITEM pItem;
InitLVITEM(nRow,0,&pItem);
LS_item * lpLS_item = NULL;
lpLS_item = (LS_item*) pItem.lParam;
// Verify if a style for this Row already exist or not
//
LS_item * lpLS_row = NULL;
lpLS_row = lpLS_item->row_style;
if(lpLS_row == NULL)
{ // We must create one
//
lpLS_row = new LS_item;
this->Init_LS_item(lpLS_row,false);
// attach to the item
//
lpLS_item->row_style = lpLS_row;
}
// Take the selected style structure
//
if(lpLS_row->selected_style == NULL)
{ // Create a structure style
//
lpLS_row->selected_style = new LS_item;
this->Init_LS_item( lpLS_row->selected_style );
}
lpLS_row = lpLS_row->selected_style;
// no we can update the style
//
lpLS_row->StyleFlag = Style;
DWORD mask = LIS_BOLD | LIS_ITALIC | LIS_UNDERLINE| LIS_STROKE ;
lpLS_row->in_use = (Style & mask) > 0;
// if any font exist for this item then delete it
//
this->Free_LS_font(lpLS_row);
// Redraw it
if(redraw) CListCtrl::Update(nRow);
}
void CListCtrlStyled::SetRowSelectedTxtColor(int nRow,COLORREF txtColor,bool redraw)
{ // We must retrieve the Style info structure of this item
//
LVITEM pItem;
InitLVITEM(nRow,0,&pItem);
LS_item * lpLS_item = NULL;
lpLS_item = (LS_item*) pItem.lParam;
// Verify if a style for this Row already exist or not
//
LS_item * lpLS_row = NULL;
lpLS_row = lpLS_item->row_style;
if(lpLS_row == NULL)
{ // We must create one
//
lpLS_row = new LS_item;
this->Init_LS_item(lpLS_row,false);
// attach to the item
//
lpLS_item->row_style = lpLS_row;
}
// Take the selected style structure
//
if(lpLS_row->selected_style == NULL)
{ // Create a structure style
//
lpLS_row->selected_style = new LS_item;
this->Init_LS_item( lpLS_row->selected_style );
}
lpLS_row = lpLS_row->selected_style;
// no we can update the style
//
lpLS_row->txtColor = txtColor;
// Redraw it
if(redraw) CListCtrl::Update(nRow);
}
void CListCtrlStyled::SetRowSelectedBgColor(int nRow,COLORREF txtBgColor,bool redraw)
{ // We must retrieve the Style info structure of this item
//
LVITEM pItem;
InitLVITEM(nRow,0,&pItem);
LS_item * lpLS_item = NULL;
lpLS_item = (LS_item*) pItem.lParam;
// Verify if a style for this Row already exist or not
//
LS_item * lpLS_row = NULL;
lpLS_row = lpLS_item->row_style;
if(lpLS_row == NULL)
{ // We must create one
//
lpLS_row = new LS_item;
this->Init_LS_item(lpLS_row,false);
// attach to the item
//
lpLS_item->row_style = lpLS_row;
}
// Take the selected style structure
//
if(lpLS_row->selected_style == NULL)
{ // Create a structure style
//
lpLS_row->selected_style = new LS_item;
this->Init_LS_item( lpLS_row->selected_style );
}
lpLS_row = lpLS_row->selected_style;
// no we can update the style
//
lpLS_row->bgColor = txtBgColor;
// Redraw it
if(redraw) CListCtrl::Update(nRow);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -