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

📄 sel_item_click_not_col1.shtml.htm

📁 mfc资料集合5
💻 HTM
字号:
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="Zafir Anjum">
   <META NAME="GENERATOR" CONTENT="Mozilla/4.0 [en] (WinNT; I) [Netscape]">
   <TITLE>Select an item even if click is not on left most column</TITLE>
</HEAD>
<body background="../fancyhome/back.gif" tppabs="http://www.codeguru.com/fancyhome/back.gif" bgcolor="#FFFFFF" link="#B50029" vlink="#8E2323" alink="#FF0000" bgproperties="fixed">
<table WIDTH="100%">
<tr WIDTH="100%">
<td><td>
</tr>
</table>


<CENTER>
<H3>
<FONT COLOR="#AOAO99">Select an item even if click is not on left most
column</FONT></H3></CENTER>

<HR WIDTH="100%">
<OL>
<LI>
Add a WM_LBUTTONDOWN handler in the CListCtrl derived class.</LI>

<LI>
Code for OnLButtonDown() is given below.</LI>

<LI>
Before calling HitTest(), the x coordinate is changed to 2. This forces
the point being tested to fall on the first column. A value of x below
2 fails (it is presumably occupied by the border ).</LI>

<LI>
Note that the call to the base class OnLButtonDown() precedes the call
to SetItemState.</LI>

<LI>
This method fails if the first column is not visible. We can use the function
<A HREF="col_index.shtml.htm" tppabs="http://www.codeguru.com/listview/col_index.shtml">HitTestEx()</A> described in an earlier section
to cover for the situation when the first column is not visible.</LI>
</OL>

<UL>
<PRE><TT><FONT COLOR="#990000">void CMyListCtrl::OnLButtonDown(UINT nFlags, CPoint point)&nbsp;
{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CListCtrl::OnLButtonDown(nFlags, point);

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int index;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; point.x = 2;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( ( index = HitTest( point, NULL )) != -1 )
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetItemState( index, LVIS_SELECTED | LVIS_FOCUSED ,&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LVIS_SELECTED | LVIS_FOCUSED);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
}</FONT></TT></PRE>
</UL>


<P>
<HR>
<TABLE BORDER=0 WIDTH="100%" >
<TR>
<TD WIDTH="33%"><FONT SIZE=-1><A HREF="../index.htm" tppabs="http://www.codeguru.com/">Goto HomePage</A></FONT></TD>

<TD WIDTH="33%">
<CENTER><FONT SIZE=-2>&copy; 1997 Zafir Anjum</FONT>&nbsp;</CENTER>
</TD>

<TD WIDTH="34%">
<DIV ALIGN=right><FONT SIZE=-1>Contact me: <A HREF="mailto:zafir@home.com">zafir@home.com</A>&nbsp;</FONT></DIV>
</TD>
</TR>
</TABLE>
<CENTER>&nbsp;<IMG SRC="../cgi/Count.cgi-ft=2&dd=E-df=lv_sel_item_click_not_col1.cnt" tppabs="http://www.codeguru.com/cgi/Count.cgi?ft=2&dd=E%7cdf=lv_sel_item_click_not_col1.cnt" ALIGN="BOTTOM" BORDER="0"></CENTER>
</BODY>
</HTML>

⌨️ 快捷键说明

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