動態建立的list control新增訊息響應

2021-06-08 10:35:42 字數 1336 閱讀 8601

動態建立的控制項的訊息響應只能手工來新增,以list control為例,如果你想雙擊list control的item項時得到乙個響應可以用如下做法:

首先在標頭檔案中新增 afx_msg void onnmdblclklist(nmhdr *pnmhdr, lresult *presult);

然後在cpp檔案中新增 on_notify(nm_dblclk, 1, &cpytestdlg::onnmdblclklist)這個要房子begin_message_map和end_message_map中間

之後在void onnmdblcklist()函式實現中做判斷,例程如下:

void cpytestdlg::onnmdblclklist(nmhdr *pnmhdr, lresult *presult){	

nm_listview* pnmlistview = (nm_listview*)pnmhdr;

int nitem = pnmlistview -> iitem;

int nsubitem = pnmlistview ->isubitem;

if(nitem >= 0)

{ cstring str_nm, str_bh;

"%d", nitem);

//::afxmessagebox(str1);

dword_ptr pstr = m_listctrl1->getitemdata(nitem);

m_listctrl1->setitemdata(nitem, 1);

position pos=m_listctrl1->getfirstselecteditemposition();

int nid=(int)m_listctrl1->getnextselecteditem(pos);

str_nm = m_listctrl1->getitemtext(nid, 0);

str_bh = m_listctrl1->getitemtext(nid, 1);

m_xsbh = str_bh;

m_xsxm = str_nm;

updatedata(false);

for(int i=0; igetfirstselecteditemposition();

int nid=(int)m_listctrl1->getnextselecteditem(pos);

str_nm = m_listctrl1->getitemtext(nid, 0);

str_bh = m_listctrl1->getitemtext(nid, 1);

可以把你雙擊選擇的item存到cstring型別的變數中,我這裡是將選出的值放入了cedit變數中顯示出來了

動態選單 動態建立選單

動態建立選單 windows應用程式的介面,不僅僅是乙個簡單的窗體,每個窗體中都包含具體實現功 能的控制項,包括能夠顯示基本資訊的label控制項,能夠在其中輸入內容的文字框控制項,能 夠設定選項的選擇按鈕控制項等。net提供了很多使用簡單 功能強大的控制項,幫助程式設 計者快速有效地開發應用軟體。...

動態建立icon

前一陣找了好久也沒有找到有關動態建立icon的文章,後來偶然發現一片寫的,確實c 的。不能新增到vc6的mfc工程裡裡去。哎。還是自食其力,看文件寫個了。這裡是建立乙個帶字串的hicon,想一下某些日曆軟體在系統托盤上的日期顯示。看了這個,相信看客可以舉一反三了。hicon createstrico...

動態建立Table

定義表頭 tablerow trhead new tablerow 定義列 tablecell tchead new tablecell 設定列名 tchead.text 列名1 追加乙個列 trhead.cells.add tchead tchead new tablecell 設定列名 tche...