⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_20994.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:20994 发表者:foolish 发表日期:2002-11-12 20:12:18
<br>主题:关于List Congtrol
<br>内容:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;在List Congtrol如何,使鼠标每次选中是,响应的是一行中的一项而不是整个一行。
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:树爱兵 回复日期:2002-11-12 20:30:25
<br>内容:给个东西你看看!<BR><BR>编辑列表控件子条目<BR>一 初始化列表控件头条目:<BR>方法一:<BR>采用int InsertColumn( int nCol, LPCTSTR lpszColumnHeading, int nFormat = LVCFMT_LEFT, int nWidth = -1, int nSubItem = -1 );<BR>在BOOL CListCtrlDlg::OnInitDialog()加入如下代码:<BR>m_List.InsertColumn(0, "Name", LVCFMT_LEFT, 150, 0);<BR>&nbsp;&nbsp;&nbsp;&nbsp; m_List.InsertColumn(1, "In Folder", LVCFMT_LEFT, 200, 1);<BR>&nbsp;&nbsp;&nbsp;&nbsp; m_List.InsertColumn(2, "Size", LVCFMT_LEFT, 60, 2);<BR>&nbsp;&nbsp;&nbsp;&nbsp; m_List.InsertColumn(3, "Modified", LVCFMT_LEFT, 120, 3);<BR>方法二:<BR>&nbsp;&nbsp;&nbsp;&nbsp;在initDialog函数中设置列表控件格式;<BR>ListView_SetExtendedListViewStyle(::GetDlgItem(m_hWnd,IDC_LIST1),LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);<BR>然后假如编写自定义函数:<BR>void CListctrlDialogDlg::InsertItems()<BR>{ <BR>&nbsp;&nbsp;&nbsp;&nbsp;HWND&nbsp;&nbsp;hWnd=::GetDlgItem(m_hWnd,IDC_LIST1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;LVCOLUMN&nbsp;&nbsp; list;<BR>&nbsp;&nbsp;&nbsp;&nbsp;list.mask=LVCF_TEXT|LVCF_WIDTH|LVCF_FMT|LVCF_SUBITEM;<BR>&nbsp;&nbsp;&nbsp;&nbsp;list.fmt=LVCFMT_LEFT;<BR>&nbsp;&nbsp;&nbsp;&nbsp;list.cx=50;<BR>&nbsp;&nbsp;&nbsp;&nbsp;list.pszText="S.NO";<BR>&nbsp;&nbsp;&nbsp;&nbsp;list.iSubItem=0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;::SendMessage(hWnd,LVM_INSERTCOLUMN,(WPARAM)0,(WPARAM)&list);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;list.cx = 100;<BR>&nbsp;&nbsp;&nbsp;&nbsp;list.pszText&nbsp;&nbsp; = "Name";<BR>&nbsp;&nbsp;&nbsp;&nbsp;list.iSubItem = 1;<BR>&nbsp;&nbsp;&nbsp;&nbsp;::SendMessage(hWnd&nbsp;&nbsp;,LVM_INSERTCOLUMN, (WPARAM)1,(WPARAM)&list);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;list.cx = 100;<BR>&nbsp;&nbsp;&nbsp;&nbsp;list.pszText&nbsp;&nbsp; = "Address";<BR>&nbsp;&nbsp;&nbsp;&nbsp;list.iSubItem = 2;<BR>&nbsp;&nbsp;&nbsp;&nbsp;::SendMessage(hWnd&nbsp;&nbsp;,LVM_INSERTCOLUMN, (WPARAM)1,(WPARAM)&list);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;list.cx = 100;<BR>&nbsp;&nbsp;&nbsp;&nbsp;list.pszText&nbsp;&nbsp; = "Country";<BR>&nbsp;&nbsp;&nbsp;&nbsp;list.iSubItem = 2;<BR>&nbsp;&nbsp;&nbsp;&nbsp;::SendMessage(hWnd&nbsp;&nbsp;,LVM_INSERTCOLUMN, (WPARAM)1,(WPARAM)&list);<BR><BR><BR>至于加入item可参见msdn<BR>HOWTO: Use Masks to Set/Get Item States in CListCtrl<BR>Article ID: Q173242<BR><BR><BR>HOWTO: Use Masks to Set/Get Item States in CListCtrlLast reviewed: September 3, 1997Article ID: Q173242 <BR>The information in this article applies to: ·&nbsp;&nbsp;&nbsp;&nbsp;The Microsoft Foundation Classes (MFC) included with: - Microsoft Visual C++, 32-bit Editions, versions 4.2, 5.0 SUMMARYWith the CListCtrl class there are no explicit (清晰的)function calls to set or retrieve (返回)the states of the list items. This functionality is handled with flags or masks. This article explains how to use these masks to get list items and change their states. MORE INFORMATIONThe CListCtrl class supports the GetItemState, SetItemState and GetNextItem functions. If you use GetNextItem with the appropriate mask, you should be able to locate the desired list item by its order or its state. To change the state you would call GetItemState on the item you have located to obtain the current desired state flag(s), make modifications to the flag(s) and call SetItemState. GetNextItemint GetNextItem( int nItem, int nFlags ) const;The GetNextItem function takes two parameters. The first indicates which item (0 based) in the list after which you should begin your search. The current item is excluded from the search. To search the entire list, supply a -1 for this parameter. The second parameter indicates the state that identifies the item for which you are searching. For the CListCtrl, the flags all begin with LVNI_. (see the documentation on CListCtrl::GetNextItem for a complete list). GetItemState, SetItemStateBOOL SetItemState( int nItem, LVITEM* pItem );BOOL SetItemState( int nItem, UINT nState, UINT nMask );UINT GetItemState( int nItem, UINT nMask ) const;The GetItemState function will returns a UINT indicating current state flag(s) of the indicated list item. SetItemState accepts a UINT to set the state flag(s) of the indicated list item. Both of these functions take a UINT mask that indicates which of the state flags should be affected. REFERENCESSample CodeThe following code demonstrates how to select all items in the CListCtrl that begin with the letter "A" and deselect all others. Note that m_listCtrl is a ClassWizard added control data member declared as CListCtrl.&nbsp;&nbsp;&nbsp;&nbsp;void CMyView::OnInitialUpdate()&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CFormView::OnInitialUpdate();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_listCtrl.SetBkColor (RGB(120,160,220));//设置表格控件背景色;&nbsp;&nbsp;&nbsp;&nbsp;ListView_SetExtendedListViewStyle(::GetDlgItem(m_hWnd,IDC_LIST1),LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);//设置表格控件风格;&nbsp;&nbsp;&nbsp;&nbsp; //插入表头;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_listCtrl.InsertColumn(0, "Western States", LVCFMT_LEFT, 150,0);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_listCtrl.InsertColumn(1, "In Folder", LVCFMT_LEFT, 200, 1);&nbsp;&nbsp;&nbsp;&nbsp;m_listCtrl.InsertColumn(2, "Size", LVCFMT_LEFT, 60, 2);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LV_ITEM lvItem;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ZeroMemory(&lvItem, s izeof(lvItem));// The ZeroMemory function fills a block of //memory with zeros.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvItem.mask = LVIF_TEXT | LVIF_STATE;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvItem.iItem = 0;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvItem.state = LVIS_CUT | LVIS_SELECTED;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvItem.pszText = "Washington";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_listCtrl.InsertItem(&lvItem); // initially selected&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lvItem.iItem = 1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvItem.state = LVIS_CUT | LVIS_SELECTED;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvItem.pszText = "Arizona";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_listCtrl.InsertItem(&lvItem); // initially selected&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvItem.iItem = 2;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvItem.state = LVIS_CUT;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvItem.pszText = "Alaska";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_listCtrl.InsertItem(&lvItem);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvItem.iItem = 3;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvItem.state = LVIS_CUT;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvItem.pszText = "California";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_listCtrl.InsertItem(&lvItem);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvItem.iItem = 4;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvItem.state = LVIS_CUT;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lvItem.pszText = "Nevada";&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_listCtrl.InsertItem(&lvItem);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UINT nState;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CString strText;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int iItem = -1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// as long as GetNextItem found an item...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while ((iItem = m_listCtrl.GetNextItem(iItem, LVNI_ALL)) &gt; -1 )&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // get item string&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strText = m_listCtrl.GetItemText(iItem, 0);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // show initial state of flags&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nState = m_listCtrl.GetItemState(iItem, LVIS_SELECTED | LVIS_CUT);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TRACE("%s state flag is %0x\n", strText, nState);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Get only LVIS_SELECTED flag&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // note that LVIS_CUT is not returned in nState&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nState = m_listCtrl.GetItemState(iItem, LVIS_SELECTED);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // select states beginning with 'A'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (strText[0] == 'A' && !nState) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TRACE("%s needed to be selected\n", strText);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_listCtrl.SetItemState(iItem,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LVIS_SELECTED,&nbsp;&nbsp;// nState&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LVIS_SELECTED); // nMask&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // deselect states that don't begin with 'A'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else if (strText[0] != 'A' && nState) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TRACE("%s needed to be deselected\n", strText);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_listCtrl.SetItemState(iItem,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// nState&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LVIS_SELECTED); // nMask&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // show new flags if modified, note that LVIS_CUT wasn't affected&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nState = m_listCtrl.GetItemState(iItem, LVIS_SELECTED | LVIS_CUT);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TRACE("%s state flag is now %0x\n", strText, nState);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp; }Keywords&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: MfcMiscTechnology&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: kbMfcVersion&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : WINDOWS NT:4.2,5.0Platform&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;: NT WINDOWS<BR> ================================================================================THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Last reviewed:<BR><BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:foolish 回复日期:2002-11-13 19:55:33
<br>内容:&nbsp;&nbsp; 方法一无效,二我还要试一下。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:foolish 回复日期:2002-11-13 21:13:19
<br>内容:&nbsp;&nbsp;&nbsp;&nbsp;可能是没有看懂我的意思,我是说例如:<BR><BR>NO。&nbsp;&nbsp;&nbsp;&nbsp; NAME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ADDRESS<BR>1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 统一体<BR>鼠标点到“4”时,不是一整行都变蓝,而只是“4”变蓝。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:树爱兵 回复日期:2002-11-14 15:20:47
<br>内容:http://www.codeproject.com/listctrl/editing_subitems_in_listcontrol.asp
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:foolish 回复日期:2002-11-14 20:20:58
<br>内容:&nbsp;&nbsp; 我们这边网坏了,暂时连不上那个网站等我看了以后,再说。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:树爱兵 回复日期:2002-11-14 20:52:30
<br>内容:你看看,有不懂得再问好了<BR>!大家互相学习!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:foolish 回复日期:2002-11-14 21:20:51
<br>内容:&nbsp;&nbsp;还有你的附件我打不开。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:树爱兵 回复日期:2002-11-15 09:42:09
<br>内容:上面这个网页能打开嘛?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:foolish 回复日期:2002-11-15 17:11:19
<br>内容:网页可以打开,但是下载有问题,不知怎么会事。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -