mfc列表控制項改變字串中一部分字元顏色

2021-06-29 08:11:40 字數 2414 閱讀 6027

由於很少用介面對mfc不太熟,所在也引數了一下網路完成了乙個自繪clistctrl類,不正確的請指出來。

#pragma once

#include "afxcmn.h"

class cmylistctrl :

public clistctrl

;#include "stdafx.h"

#include "mylistctrl.h"

#include

#include

cmylistctrl::cmylistctrl(void)

cmylistctrl::~cmylistctrl(void)

void cmylistctrl::presubclasswindow()

//獲得要顯示的字串

void cmylistctrl::getkeystrinfo(cstring str)

void cmylistctrl::drawitem(lpdrawitemstruct lpdrawitemstruct)

if ( lpdrawitemstruct->itemstate & ods_selected )

colorref oltextcl = pdc->gettextcolor();//以前字的顏色

cstring strt = lpbuffer;

std::vectorvi;

int oldinext=0;

if (strt!=l""&&m_keystr!=l"")

std::vector::iterator iter=vi.begin();

for (;iter!=vi.end();++iter)

else

}else

}cstring stt1 = strt.mid(0,oldinext);

csize tt= pdc->gettextextent(stt1);

rcitem.left+=tt.cx;

drawtext(lpdrawitemstruct->hdc, strt.getbuffer()+oldinext,strt.getlength()-oldinext,&rcitem, dt_left) ;

}else

drawtext(lpdrawitemstruct->hdc, lpbuffer, _tcslen(lpbuffer),&rcitem, dt_left) ;}}

//呼叫

//在初始化函式裡

long lstyle;

lstyle = getwindowlong(m_listdata.m_hwnd, gwl_style);// 獲取當前視窗style 

lstyle &= ~lvs_typemask; // 清除顯示方式位 

lstyle |= lvs_report|lvs_showselalways|lvs_singlesel; // 設定style 

setwindowlong(m_listdata.m_hwnd, gwl_style, lstyle);// 設定style  

setwindowlong(m_listdata.m_hwnd, gwl_style, lstyle);// 設定style  

//lvs_ex_doublebuffer 雙緩衝

m_listdata.setextendedstyle(lvs_ex_gridlines |lvs_ex_fullrowselect|lvs_ex_headerdragdrop|lvs_ex_doublebuffer); // 設定擴充套件風格

m_listdata.insertcolumn( 0, l"456456465465", lvcfmt_left/*lvcfmt_center*/, 150);//插入列

m_listdata.insertcolumn( 1, l"564564654", lvcfmt_left/*lvcfmt_center*/, 100);//插入列

m_listdata.insertcolumn( 2, l"dfasdfsafsadf", lvcfmt_left/*lvcfmt_center*/, 100);//插入列

m_listdata.insertcolumn( 3, l"afdsfsdfsfa", lvcfmt_left/*lvcfmt_center*/, 115);//插入列

m_listdata.getkeystrinfo(l"5");

m_listdata.insertitem(0,l"張三456465");

m_listdata.setitemtext(0,1,l"551755855cm");

m_listdata.setitemtext(0,2,l"57505kg");

m_listdata.setitemtext(0,3,l"52023年1月15日23時40分");

結果:如圖

ORACLE 字串操作 B字串時A的一部分

select from a where instr a,b 0 用於實現b欄位是a欄位中的某一部分的時候,要論順序或者要相鄰的字元。如果想要不論順序或者不相鄰的字元時,定義函式可以實現 select from a where instr a,b 0 這個只能實現b欄位是a欄位中的某一部分的時候。如果...

字串一部分習題訓練

1.在字串中指定開始位置插入字串 include include include int main for i 0 i lenth2 i printf s n str1 return 0 2.幾個字串求出最小串 include include include int main printf how ...

列印字串的任意一部分

使用printf 函式列印字串的任意部分,請看下例 include include include int main 輸出結果為 first 11 characters this is the last 13 characters source string 在上例中,第一次呼叫printf 函式時...