修改ListCtrl控制項列標題文字居左顯示

2022-09-19 14:39:11 字數 715 閱讀 5853

修改listctrl控制項標題文字居左顯示

原來的列標題文字是居中顯示:

現在要把列表文字居中改為居左顯示

其方法如下:

獲得標題控制項控制代碼

g_listctrl.m_hwnd為listctrl控制項的控制代碼

hwnd hhead =(hwnd)::sendmessage(g_listctrl.m_hwnd, lvm_getheader, 0, 0);

在listctrl控制項插入列後面,獲得列的總數

int ncol = sendmessage(hhead, hdm_getitemcount, 0, 0);

迴圈設定列的文字居左顯示

要填充乙個hditem結構體

for (int i = 0; i < ncol; i++)

hditem ht = ;

ht.mask = hdi_format /*| hdi_width | hdi_text*/;//設定下面的fmt資料有效的掩碼

ht.fmt = hdf_left | hdf_string; //主要是這句,設定為居左,顯示字串

int n = sendmessage(hhead, hdm_setitem, i, lparam(&ht));    

這樣就成功修改列標題文字顯示的位置了.

08 列表控制項 ListCtrl

1.拖入list ctrol 2.屬性 view report 3.新增變數 類別 control 變數名 m list 1 新增預設值 cstring str 設定表頭 引數1 索引 2.內容 3.對齊方式 4.列寬度 for iny i 0 i 3 i m list.insertcolumn i...

ListCtrl控制項學習筆記

1 怎樣讓在listctrl控制項中每次單擊都是選中一行?答 這是list control的乙個擴充套件樣式,在初始化時進行設定即可。新增如下 m listctrl.setextendedstyle m listctrl.getextendedstyle lvs ex fullrowselect 2...

ListCtrl控制項的使用

list contrl控制項的使用 1.建立基於對話方塊的應用程式,布置介面,設定屬性。注意新增的是listctrl控制項,不是listbox控制項,在控制項工具箱的倒數第五行list control控制項。屬性中設定styles標籤中的檢視屬性為report,是乙個多列列表顯示。2.設定控制項變數...