CComboBox::SetItemData,以及自绘我们的CComBox
来源:互联网 发布:手机淘宝加入购物车 编辑:程序博客网 时间:2024/06/05 08:39
1.这个函数有什么用呢?
我们如果自己绘制 控件的时候呢,我们可能会比如一个CComboBox中,一个文字和一个图像的索引号保存起来,在我们需要使用的时候使用,这个的功能有点类似于
Android中我们SetTag的属性!我们建立一个结构体就可以把两样东西保存起来了,这样就可以收获一个简单的模式,非常的棒,获得自己想要的图片图片列表的索引!
我们可以修改他的AddString(text,UINT image)//这样我们继承修改的类,在外部使用起来非常的方便,随意的增加图像以及文字,在自绘显示出来就好了!
{
int I=CComboxBox::AddString(szText);
SData* p=new SData;
p->nImage=nImage;
p->szText=text;
SetItemData(i,(DWORD)p);
}
Sets the 32-bit value associated with the specified item in a combo box.
int SetItemData( int nIndex, DWORD_PTR dwItemData );
Parameters
- nIndex
Contains a zero-based index to the item to set.
- dwItemData
Contains the new value to associate with the item.
但是一定要注意,保存在我们的Data,一定要使用堆空间创造,最后的时候要记得销毁我们的资源
3.我们在DrawItem中获取图像的序号那么就简单了瑟
如: SData* pdata=(SData*)GetItemData(intdex);
ASSERT(pdata);
return pData->nImage;图像的序号,在结构体中的~
4.我么如何自绘图标呢?
直接::DrawICon(dc.GetSaftHdc(0,rc.rect,rect.top.m_hIcon,16,16,0,0,DI_NOMAL);?
还是使用:CImaglist中的Draw或DrawEx?->Draw(&dc,nImage(序号),rc.topleft(),属性)
Draws an image list item in the specified device context.
BOOL DrawEx( CDC* pDC, int nImage, POINT pt, SIZE sz, COLORREF clrBk, COLORREF clrFg, UINT nStyle );
Parameters
- pDC
Pointer to the destination device context.
- nImage
Zero-based index of the image to draw.
- pt
Location at which to draw within the specified device context.
- sz
Size of the portion of the image to draw relative to the upper-left corner of the image. Seedx anddy in ImageList_DrawEx in the Platform SDK.
- clrBk
Background color of the image. See rgbBk in ImageList_DrawEx in the Platform SDK.
- clrFg
Foreground color of the image. See rgbFg in ImageList_DrawEx in the Platform SDK.
- nStyle
Flag specifying the drawing style. See fStyle in ImageList_DrawEx in thePlatform SDK.
Return Value
Nonzero if successful; otherwise 0.
Remarks
The function uses the specified drawing style and blends the image with the specified color.
ImageList_DrawEx Function
Draws an image list item in the specified device context. The function uses the specified drawing style and blends the image with the specified color.
Syntax
BOOL ImageList_DrawEx( HIMAGELIST himl, int i, HDC hdcDst, int x, int y, int dx, int dy, COLORREF rgbBk, COLORREF rgbFg, UINT fStyle);
Parameters
- himl
- A handle to the image list
- i
- The index of the image to draw.
- hdcDst
- A handle to the destination device context.
- x
- The x-coordinate at which to draw within the specified device context.
- y
- The y-coordinate at which to draw within the specified device context.
- dx
- The width of the portion of the image to draw relative to the upper-left corner of the image. Ifdx anddy are zero, the function draws the entire image. The function does not ensure that the parameters are valid.
- dy
- The height of the portion of the image to draw, relative to the upper-left corner of the image. Ifdx anddy are zero, the function draws the entire image. The function does not ensure that the parameters are valid.
- rgbBk
- The background color of the image. This parameter can be an application-defined RGB value or one of the following values:
- CLR_NONE
- No background color. The image is drawn transparently.
- CLR_DEFAULT
- The default background color. The image is drawn using the background color of the image list.
- rgbFg
- The foreground color of the image. This parameter can be an application-defined RGB value or one of the following values:
- CLR_NONE
- No blend color. The image is blended with the color of the destination device context.
- CLR_DEFAULT
- The default foreground color. The image is drawn using the system highlight color as the foreground color.
- fStyle
- The drawing style and, optionally, the overlay image. For information about specifying an overlay image index, see the comments section at the end of this topic. This parameter can be a combination of an overlay image index and one or more of the following values:
- ILD_BLEND25,
- ILD_FOCUS
- Draws the image, blending 25 percent with the blend color specified by rgbFg. This value has no effect if the image list does not contain a mask.
- ILD_BLEND50,
- ILD_SELECTED,
- ILD_BLEND
- Draws the image, blending 50 percent with the blend color specified by rgbFg. This value has no effect if the image list does not contain a mask.
- ILD_MASK
- Draws the mask.
- ILD_NORMAL
- Draws the image using the background color for the image list. If the background color is the CLR_NONE value, the image is drawn transparently using the mask.
- ILD_TRANSPARENT
- Draws the image transparently using the mask, regardless of the background color. This value has no effect if the image list does not contain a mask.
- ILD_IMAGE
- If the overlay does not require a mask to be drawn set the ILD_IMAGE flag. This causesImageList_DrawEx to just draw the image, ignoring the mask.
- 我们根据下拉表的索引,绘制我们的每一项。 我们还可以修改每一项的高度值!可以通过重载虚函数,MeasureItem(),这样可以设置我们的每一项的高度之内的事情了!
The MEASUREITEMSTRUCT structure informs Windows of the dimensions of an owner-drawn control or menu item.
typedef struct tagMEASUREITEMSTRUCT { UINT CtlType; UINT CtlID; UINT itemID; UINT itemWidth; UINT itemHeight; DWORD itemData} MEASUREITEMSTRUCT;Parameters
- CtlType
Contains the control type. The values for control types are as follows:
ODT_COMBOBOX Owner-draw combo box
ODT_LISTBOX Owner-draw list box
ODT_MENU Owner-draw menu
- CtlID
Contains the control ID for a combo box, list box, or button. This member is not used for a menu.
- itemID
Contains the menu-item ID for a menu or the list-box-item ID for a variable-height combo box or list box. This member is not used for a fixed-height combo box or list box, or for a button.
- itemWidth
Specifies the width of a menu item. The owner of the owner-draw menu item must fill this member before it returns from the message.
- itemHeight
Specifies the height of an individual item in a list box or a menu. Before it returns from the message, the owner of the owner-draw combo box, list box, or menu item must fill out this member. The maximum height of a list box item is 255.
- itemData
For a combo box or list box, this member contains the value that was passed to the list box by one of the following:
- CComboBox::SetItemData,以及自绘我们的CComBox
- 关于CComboBox的自绘
- 自绘WTL的CComboBox控件
- 自绘CComboBox控件的使用
- CComboBox自绘
- 自绘CComboBox
- CComboBox自绘
- MFC-自绘控件(CComBox篇)
- 二,MFC Ccombox的使用
- 自画 CComboBox 控件注意事项
- CListCtrl中SetItemData和GetItemData的用法
- MFC中CCOMBOX组合框的使用
- 如何修改CCombox控件的高度
- MFC重绘控件篇---按钮CCombox
- CComboBox的学习...
- CComboBox类的成员
- 更换CComboBox的属性
- CComboBox控件的使用
- GeoHash精度
- Android开发环境搭建
- android 制作.9.png图片
- 块级元素及内联元素
- codejam 2016 Round A APAC Test
- CComboBox::SetItemData,以及自绘我们的CComBox
- 在jQuery中使用el表达式来设置默认选中值
- windows系统下搭建svn服务器
- worldwind参考博客
- unity5+Vuforia SDK5实现高通AR在unity下的环境构建
- Linux 菜鸟笔记(一)
- 高光BRDF化简公式
- leetcode系列(31)Longest Substring Without Repeating Characters 最长不重复子串
- lucene4.4与IKAnalyzer的冲突