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

📄 ch03.htm

📁 VC使用大全。里面集合了VC使用的各种使用技巧。非常有用。
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<pre><font color="#008000">BeginDrag()</font></pre>

<TD>

<P>Starts an image-dragging operation</P>

<TR>

<TD>

<pre><font color="#008000">Create()</font></pre>

<TD>

<P>Creates an image list control</P>

<TR>

<TD>

<pre><font color="#008000">DeleteImageList()</font></pre>

<TD>

<P>Deletes an image list</P>

<TR>

<TD>

<pre><font color="#008000">Detach()</font></pre>

<TD>

<P>Detaches an image list from an object of the <font color="#008000">CImageList</font> class</P>

<TR>

<TD>

<pre><font color="#008000">DragEnter()</font></pre>

<TD>

<P>Locks a window for updates and shows the drag image</P>

<TR>

<TD>

<pre><font color="#008000">DragLeave()</font></pre>

<TD>

<P>Unlocks a window for updates</P>

<TR>

<TD>

<pre><font color="#008000">DragMove()</font></pre>

<TD>

<P>Moves the drag image</P>

<TR>

<TD>

<pre><font color="#008000">DragShowNolock()</font></pre>

<TD>

<P>Handles the drag image without locking the window</P>

<TR>

<TD>

<pre><font color="#008000">Draw()</font></pre>

<TD>

<P>Draws an image that's being dragged</P>

<TR>

<TD>

<pre><font color="#008000">EndDrag()</font></pre>

<TD>

<P>Ends an image-dragging operation</P>

<TR>

<TD>

<pre><font color="#008000">ExtractIcon()</font></pre>

<TD>

<P>Creates an icon from an image</P>

<TR>

<TD>

<pre><font color="#008000">GetBkColor()</font></pre>

<TD>

<P>Gets an image list's background color</P>

<TR>

<TD>

<pre><font color="#008000">GetDragImage()</font></pre>

<TD>

<P>Gets the image for drag operations</P>

<TR>

<TD>

<pre><font color="#008000">GetImageCount()</font></pre>

<TD>

<P>Gets the number of images in the control</P>

<TR>

<TD>

<pre><font color="#008000">GetImageInfo()</font></pre>

<TD>

<P>Gets image information</P>

<TR>

<TD>

<pre><font color="#008000">GetSafeHandle()</font></pre>

<TD>

<P>Gets an image list's handle</P>

<TR>

<TD>

<pre><font color="#008000">Read()</font></pre>

<TD>

<P>Gets an image list from the given archive</P>

<TR>

<TD>

<pre><font color="#008000">Remove()</font></pre>

<TD>

<P>Removes an image from the image list</P>

<TR>

<TD>

<pre><font color="#008000">Replace()</font></pre>

<TD>

<P>Replaces one image with another</P>

<TR>

<TD>

<pre><font color="#008000">SetBkColor()</font></pre>

<TD>

<P>Sets an image list's background color</P>

<TR>

<TD>

<pre><font color="#008000">SetDragCursorImage()</font></pre>

<TD>

<P>Creates an image for drag operations</P>

<TR>

<TD>

<pre><font color="#008000">SetOverlayImage()</font></pre>

<TD>

<P>Sets the index of an overlay mask</P>

<TR>

<TD>

<pre><font color="#008000">Write()</font></pre>

<TD>

<P>Writes an image list to the given archive</P></TABLE>

<H3><A ID="I8" NAME="I8"><B>The List View Control</B></A></H3>

<P>A list view control simplifies the job of building an application that works with lists of objects and organizes those objects in such a way that the program's user can easily determine each object's attributes. For example, consider a group of files 
on a disk. Each file is a separate object that is associated with a number of attributes including the file's name, size, and the most recent modification date. Windows 95 shows files either as icons in a window or as a table of entries, each entry showing 
the attributes associated with the files. The user has full control over the way that the file objects are displayed, including which attributes are shown and which are not listed. The Windows 95 common controls include something called a list view 
control, which enables Windows 95 programmers to organize lists exactly the same way that Windows 95 does with files and other objects.</P>

<P>If you'd like to see an example of a full-fledged list view control, just open the Windows 95 Explorer (see Figure 3.3). The right side of the window shows how the list view control can organize objects in a window. (The left side of the window 
contains a tree view control, which you learn about later in this chapter, in the section titled &quot;The Tree View Control.&quot;) In the figure, the list view is currently set to the report view, in which each object in the list receives its own line 
showing not only the object's name but also the attributes associated with that object.</P>

<A HREF="Dfigs03.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch03/Dfigs03.gif"><b>Fig. 3.3</b></A>

<P><I>Windows 95 Explorer uses a list view control to organize file information.</I></P>

<P>The user can change the way objects are organized in a list view control. Figure 3.4, for example, shows the list view portion of the Explorer set to the large-icon setting, whereas Figure 3.5 shows the small-icon setting, which enables the user to see 
more objects (in this case, files) in the window. With a list view control, the user can edit the names of objects in the list, and in the report view can sort objects based on data displayed in a particular column.</P>

<A HREF="Dfigs04.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch03/Dfigs04.gif"><b>Fig. 3.4</b></A>

<P><I>Here's Explorer's list view control set to large icons.</I></P>

<A HREF="Dfigs05.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch03/Dfigs05.gif"><b>Fig. 3.5</b></A>

<P><I>Here's Explorer's list view control set to small icons.</I></P>

<P>The Win95 Controls App application also sports a list view control, although it's not as fancy as Explorer's. To switch between the small-icon, large-icon, list, and report views, click the appropriate button to the right of the control. Figure 3.1 
already showed you the report view for this list view. Figure 3.6 shows the application's list view control displaying small icons, whereas Figure 3.7 shows the large icons.</P>

<A HREF="Dfigs06.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch03/Dfigs06.gif"><b>Fig. 3.6</b></A>

<P><I>Here's the example application's list view control set to small icons.</I></P>

<A HREF="Dfigs07.gif" tppabs="http://www.mcp.com/814147200/0-7897/0-7897-1145-1/figs/ch03/Dfigs07.gif"><b>Fig. 3.7</b></A>

<P><I>Here's the sample application's list view control set to large icons.</I></P>

<P><B><I>Creating the List View</I></B></P>

<P>How does all of this happen? Well, it does require more work than the progress bar, trackbar, or up-down control (it could hardly take less.) In the Win95 Controls App application, the list view control is created in the <font 
color="#008000">CreateListView()</font> local member function, as shown in Listing 3.6, which the program calls from the view class's <font color="#008000">OnCreate()</font> function. CreateListView() performs the following tasks:</P>

<ol> 

<li><P> Creates the image list controls</P>

<li><P> Creates the list view  control itself</P>

<li><P> Associates the image lists with the list view</P>

<li><P> Creates the columns</P>

<li><P> Sets up the columns</P>

<li><P> Creates the items</P>

<li><P> Sets up the items</P>

<li><P> Creates the buttons</P>

</ol>

<P><I>Listing </I><I>3.6&#151;Win95View.cpp&#151;</I>CWin95View::CreateListView()</P>

<pre><font color="#008000">void CWin95View::CreateListView()</font></pre>

<pre><font color="#008000">{</font></pre>

<pre><font color="#008000">    // Create the Image List controls.</font></pre>

<pre><font color="#008000">    m_smallImageList.Create(16, 16, FALSE, 1, 0);</font></pre>

<pre><font color="#008000">    m_largeImageList.Create(32, 32, FALSE, 1, 0);</font></pre>

<pre><font color="#008000">    HICON hIcon = ::LoadIcon (AfxGetResourceHandle(),</font></pre>

<pre><font color="#008000">        MAKEINTRESOURCE(IDI_ICON1));</font></pre>

<pre><font color="#008000">    m_smallImageList.Add(hIcon);</font></pre>

<pre><font color="#008000">    hIcon = ::LoadIcon (AfxGetResourceHandle(),</font></pre>

<pre><font color="#008000">        MAKEINTRESOURCE(IDI_ICON2));</font></pre>

<pre><font color="#008000">    m_largeImageList.Add(hIcon);</font></pre>

<pre><font color="#008000">    // Create the List View control.</font></pre>

<pre><font color="#008000">    m_listView.Create(WS_VISIBLE | WS_CHILD | WS_BORDER |</font></pre>

<pre><font color="#008000">        LVS_REPORT | LVS_NOSORTHEADER | LVS_EDITLABELS,</font></pre>

<pre><font color="#008000">        CRect(160, 120, 394, 220), this, IDC_LISTVIEW);</font></pre>

<pre><font color="#008000">    m_listView.SetImageList(&amp;m_smallImageList, LVSIL_SMALL);</font></pre>

<pre><font color="#008000">    m_listView.SetImageList(&amp;m_largeImageList, LVSIL_NORMAL);</font></pre>

<pre><font color="#008000">    // Create the columns.</font></pre>

<pre><font color="#008000">    LV_COLUMN lvColumn;</font></pre>

<pre><font color="#008000">    lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;</font></pre>

<pre><font color="#008000">    lvColumn.fmt = LVCFMT_CENTER;</font></pre>

<pre><font color="#008000">    lvColumn.cx = 75;</font></pre>

<pre><font color="#008000">    lvColumn.iSubItem = 0;</font></pre>

<pre><font color="#008000">    lvColumn.pszText = &quot;Column 0&quot;;</font></pre>

<pre><font color="#008000">    m_listView.InsertColumn(0, &amp;lvColumn);</font></pre>

<pre><font color="#008000">    lvColumn.iSubItem = 1;</font></pre>

<pre><font color="#008000">    lvColumn.pszText = &quot;Column 1&quot;;</font></pre>

<pre><font color="#008000">    m_listView.InsertColumn(1, &amp;lvColumn);</font></pre>

<pre><font color="#008000">    lvColumn.iSubItem = 2;</font></pre>

<pre><font color="#008000">    lvColumn.pszText = &quot;Column 2&quot;;</font></pre>

<pre><font color="#008000">    m_listView.InsertColumn(1, &amp;lvColumn);</font></pre>

<pre><font color="#008000">    // Create the items.</font></pre>

<pre><font color="#008000">    LV_ITEM lvItem;</font></pre>

<pre><font color="#008000">    lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;</font></pre>

<pre><font color="#008000">    lvItem.state = 0;     </font></pre>

<pre><font color="#008000">    lvItem.stateMask = 0; </font></pre>

<pre><font color="#008000">    lvItem.iImage = 0;</font></pre>

<pre><font color="#008000">    lvItem.iItem = 0;</font></pre>

<pre><font color="#008000">    lvItem.iSubItem = 0;</font></pre>

<pre><font color="#008000">    lvItem.pszText = &quot;Item 0&quot;;</font></pre>

<pre><font color="#008000">    m_listView.InsertItem(&amp;lvItem);</font></pre>

<pre><font color="#008000">    m_listView.SetItemText(0, 1, &quot;Sub Item 0.1&quot;);</font></pre>

<pre><font color="#008000">    m_listView.SetItemText(0, 2, &quot;Sub Item 0.2&quot;);</font></pre>

<pre><font color="#008000">    lvItem.iItem = 1;</font></pre>

<pre><font color="#008000">    lvItem.iSubItem = 0;</font></pre>

<pre><font color="#008000">    lvItem.pszText = &quot;Item 1&quot;;</font></pre>

<pre><font color="#008000">    m_listView.InsertItem(&amp;lvItem);</font></pre>

⌨️ 快捷键说明

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