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

📄 image_in_header.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">
   <TITLE>CListCtrl - Displaying an image in the header</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">Displaying an image in the header</FONT></H3></CENTER>

<HR WIDTH="100%">

Unlike most other common controls, the header control does not use an image list. It does allow you to use a bitmap in any of the header item. You can display just the bitmap or the bitmap with the item label. You use the CHeaderCtrl::SetItem() function to assign a bitmap to a header item or to remove a bitmap if one is already assigned.

<p><img src="image_in_header.gif" tppabs="http://www.codeguru.com/listview/image_in_header.gif" border="1" width="128"
height="50"></p>


<p>The following code assigns a bitmap to a header control item. This code will show the bitmap as well as the item label. I noticed one bug with this code. The right most column of pixels in the bitmap does not get displayed. You should, therefore, not consider the right most column when creating the bitmap. Also, if the bitmap is taller than what the header control can display, then only the middle portion of the bitmap is displayed. The header control does not have a problem in displaying wide bitmaps. Another note of warning, the bitmap is not displayed transparently. If you want a non rectangular shape, you have to use a gray background for the bitmap and hope that the user does not change the color scheme.

<PRE><TT><FONT COLOR="#990000">	HD_ITEM hditem;
	hditem.mask = HDI_FORMAT;
	((CHeaderCtrl*)GetDlgItem(0))->GetItem( nCol, &hditem );
	hditem.mask = HDI_BITMAP | HDI_FORMAT;
	hditem.fmt |= HDF_BITMAP;
	// mybitmap is a CBitmap object containing the bitmap
	hditem.hbm = (HBITMAP)mybitmap.GetSafeHandle();
	((CHeaderCtrl*)GetDlgItem(0))->SetItem( nCol, &hditem );
</FONT></TT></PRE>


<p>If you want to display just the bitmap and not the label, then you can remove the HDF_STRING flag from the fmt field.

<PRE><TT><FONT COLOR="#990000">	HD_ITEM hditem;
	hditem.mask = HDI_FORMAT;
	((CHeaderCtrl*)GetDlgItem(0))->GetItem( nCol, &hditem );
	hditem.mask = HDI_BITMAP | HDI_FORMAT;
	hditem.fmt |= HDF_BITMAP;
	<b>hditem.fmt &= ~HDF_STRING ;</b>
	// mybitmap is a CBitmap object containing the bitmap
	hditem.hbm = (HBITMAP)mybitmap.GetSafeHandle();
	((CHeaderCtrl*)GetDlgItem(0))->SetItem( nCol, &hditem );
</FONT></TT></PRE>

<p>To remove a bitmap from the column header, you can change the format by calling the SetItem() function again and clear the HDF_BITMAP flag from the format field. Alternatively, you can use HDI_BITMAP as the mask and set the hbm field to NULL.

<PRE><TT><FONT COLOR="#990000">	HD_ITEM hditem;
	hditem.mask = HDI_FORMAT;
	((CHeaderCtrl*)GetDlgItem(0))->GetItem( nCol, &hditem );
	hditem.mask = HDI_FORMAT;
	<b>hditem.fmt &= ~HDF_BITMAP;</b>
	((CHeaderCtrl*)GetDlgItem(0))->SetItem( nCol, &hditem );
</FONT></TT></PRE>

<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><IMG SRC="../cgi/Count.cgi-ft=2&dd=E-df=lv_image_in_header.cnt" tppabs="http://www.codeguru.com/cgi/Count.cgi?ft=2&dd=E%7cdf=lv_image_in_header.cnt" ALIGN="BOTTOM" BORDER="0"></CENTER>
</BODY>
</HTML>

⌨️ 快捷键说明

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