黄色网页视频 I 影音先锋日日狠狠久久 I 秋霞午夜毛片 I 秋霞一二三区 I 国产成人片无码视频 I 国产 精品 自在自线 I av免费观看网站 I 日本精品久久久久中文字幕5 I 91看视频 I 看全色黄大色黄女片18 I 精品不卡一区 I 亚洲最新精品 I 欧美 激情 在线 I 人妻少妇精品久久 I 国产99视频精品免费专区 I 欧美影院 I 欧美精品在欧美一区二区少妇 I av大片网站 I 国产精品黄色片 I 888久久 I 狠狠干最新 I 看看黄色一级片 I 黄色精品久久 I 三级av在线 I 69色综合 I 国产日韩欧美91 I 亚洲精品偷拍 I 激情小说亚洲图片 I 久久国产视频精品 I 国产综合精品一区二区三区 I 色婷婷国产 I 最新成人av在线 I 国产私拍精品 I 日韩成人影音 I 日日夜夜天天综合

clistctrl +號(hào)按鈕繪制

系統(tǒng) 2249 0

網(wǎng)上有關(guān)clistctrl舉不勝舉,包括按鈕控件的繪制也很多,但我用的時(shí)候找了好久沒(méi)發(fā)現(xiàn)適合我用的。在這里我想介紹一種很簡(jiǎn)潔的+、-號(hào)按鈕繪制的方法,實(shí)現(xiàn)后類似于tree中的+、-號(hào)收縮功能。以便同行以后有需要可以直接搬走使用。

依附點(diǎn):clistctrl用的最多的setitemdata,setitemtext,可以記錄一些信息,但這里通過(guò)setitemstate來(lái)記錄與修改圖標(biāo)的狀態(tài),從而實(shí)現(xiàn)+、-號(hào)的按鈕。

問(wèn)題:你可能說(shuō)為什么不繪制一個(gè)+號(hào)按鈕呢?紅色部分代碼是繪制了一個(gè)+號(hào)按鈕,但很難看,另外你單擊時(shí)候還要改變成-號(hào),這可能也許能實(shí)現(xiàn),但我想其中你做的這些工作的時(shí)間足夠你用這種方法做了好幾遍了。

1.說(shuō)是按鈕,其實(shí)這里采用了圖標(biāo)的方式,你可以用vc自帶的工具,也可以用ARTICONS工具,首先繪制兩個(gè)圖標(biāo),+、-號(hào).INDEXTOSTATEIMAGEMASK這個(gè)宏來(lái)把你圖標(biāo)的索引號(hào) 進(jìn)行轉(zhuǎn)變。

2.在inidlg函數(shù)中創(chuàng)建圖表,并保存+、-號(hào)圖標(biāo)。貼代碼

BOOL CTest_listcheckDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE);??? // Set big icon
SetIcon(m_hIcon, FALSE);?? // Set small icon
CWinApp *pApp = AfxGetApp();
m_pImageLarge = new CImageList();
ASSERT(m_pImageLarge != NULL);??? // serious allocation failure checking
m_pImageLarge->Create(24, 24, TRUE, 100, 4);
//m_pImageLarge->Create(32, 32, TRUE, 100, 4);
//+圖標(biāo)
m_pImageLarge->Add(pApp->LoadIcon(IDI_ICON5));//+號(hào)
m_pImageLarge->Add(pApp->LoadIcon(IDI_ICON4));//-號(hào)

m_list.SetImageList(m_pImageLarge, LVSIL_SMALL);

// TODO: Add extra initialization here
m_list.SetExtendedStyle(m_list.GetExtendedStyle()|LVS_SORTASCENDING|LVS_TYPEMASK);
m_list.InsertColumn(0,"關(guān)注類型",LVCFMT_CENTER, 90);
m_list.InsertColumn(1,"名稱",LVCFMT_CENTER, 90);

int i=0;
int index=m_list.InsertItem(i++,"1",0);
// int index=m_list.InsertItem(LVIF_TEXT|LVIF_IMAGE,i++, "1",0, 0, i,NULL);
m_list.SetItemData(index,i);
m_list.SetItemState(index,INDEXTOSTATEIMAGEMASK(0),TVIS_STATEIMAGEMASK);

// CRect rect;
// m_list.GetSubItemRect( index, 0, LVIR_ICON, rect );
// m_btn.Create("+", BS_LEFTTEXT|WS_CHILD , rect, FromHandle(m_list.m_hWnd), 1);
// m_btn.MoveWindow(rect,1);
// m_btn.ShowWindow(TRUE);

index=m_list.InsertItem(i++,"2",0);
m_list.SetItemData(index,i);
m_list.SetItemState(index,INDEXTOSTATEIMAGEMASK(0),TVIS_STATEIMAGEMASK);

index=m_list.InsertItem(i++,"3",0);
m_list.SetItemData(index,i);
m_list.SetItemState(index,INDEXTOSTATEIMAGEMASK(0),TVIS_STATEIMAGEMASK);

index=m_list.InsertItem(i++,"4",0);
m_list.SetItemData(index,i);
m_list.SetItemState(index,INDEXTOSTATEIMAGEMASK(0),TVIS_STATEIMAGEMASK);

index=m_list.InsertItem(i++,"5",-1);
m_list.SetItemData(index,i);
m_list.SetItemState(index,INDEXTOSTATEIMAGEMASK(-1),TVIS_STATEIMAGEMASK);

?

return TRUE; // return TRUE unless you set the focus to a control
}

3.單擊+、-號(hào)的分別處理消息,單擊+號(hào)則插入你需要的記錄,單擊-號(hào)則刪除下面的記錄,貼代碼:

void CTest_listcheckDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
UINT flags(0);
CPoint?? pt;
GetCursorPos(&pt);
m_list.ScreenToClient(&pt);
int index=m_list.HitTest(pt,&flags);
if (-1!=index)
{
?? CRect rect;
?? m_list.GetSubItemRect(index,0,LVIR_ICON,rect);
?? if(rect.PtInRect(pt))
?? {
??? //if 是+號(hào),1.更換圖標(biāo)為-號(hào)。2.根據(jù)index的data查詢數(shù)據(jù)庫(kù),在本index下面插入查詢結(jié)果。
??? //if 是-號(hào),1.更換圖標(biāo)為+號(hào)。2.判斷下一行是否有圖表,將無(wú)圖標(biāo)的都刪除掉。直到有圖表的列為止。
??? //AfxMessageBox("您點(diǎn)擊了圖標(biāo),請(qǐng)更換");
??? int result= m_list.GetItemState(index,TVIS_STATEIMAGEMASK);
??? int stateindex=result>>12;
??? if (0==stateindex)//是+號(hào)
??? {
???? stateindex=1;
???? m_list.SetItem( index,?? 0,?? LVIF_IMAGE,?? NULL, stateindex,?? 0,?? 0,?? 0?? );
???? m_list.SetItemState(index,INDEXTOSTATEIMAGEMASK(stateindex),TVIS_STATEIMAGEMASK);
???? for (int i=0;i<3;i++)
???? {
????? CString str;
????? str.Format("test %d",i);
????? int dd=m_list.InsertItem(index+1,str,-1);
????? m_list.SetItemData(dd,-1);
????? m_list.SetItemState(dd,INDEXTOSTATEIMAGEMASK(-1),TVIS_STATEIMAGEMASK);
???? }
??? }
??? else if (1==stateindex)//是-號(hào).
??? {
???? stateindex=0;
???? m_list.SetItem( index,?? 0,?? LVIF_IMAGE,?? NULL, stateindex, 0, 0,0);
???? m_list.SetItemState(index,INDEXTOSTATEIMAGEMASK(stateindex),TVIS_STATEIMAGEMASK);
???? int dd=m_list.GetNextItem(index,LVNI_BELOW );
???? while (-1!=dd)
???? {
????? int result= m_list.GetItemState(dd,TVIS_STATEIMAGEMASK);
????? int mask=result>>12;
????? if ((mask!=0 )&&(mask!=1))
?????? m_list.DeleteItem(dd);
????? else
?????? break;
???? }
??? }
??? //狀態(tài)的改變以及圖標(biāo)索引的設(shè)置.
???
?? }
}
*pResult = 0;
}

希望對(duì)項(xiàng)目緊又沒(méi)時(shí)間研究的人給予 一定的幫助。

clistctrl +號(hào)按鈕繪制


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論