TC官方合作论坛

 找回密码
 立即注册
查看: 123|回复: 5

[源码分享] 上一篇分享列表框实现树型框源码,这篇直接dll实现树型框

[复制链接]
发表于 2019-10-8 17:22:28 | 显示全部楼层 |阅读模式
本帖最后由 zxczxc1968531 于 2019-10-8 17:24 编辑

TC8.0树型框正在开发中,先发个简单实现树型框源码给新手朋友们参考下,代码还有很多需要完善的功能和优化空间,源码内附注释实现思路:
//简单实现树型框例子
//先用CreateWindowExW创建树型框体,成功返回框控件句柄
//然后用控件句柄加入项:会用到TV_INSERTSTRUCT结构体和TV_ITEM结构体,结构体成员及相关意义查询win32文档
//最后用SendMessage发送TVM_INSERTITEM消息,wParam = 0,lParam=TV_INSERTSTRUCT结构体指针,这里可以直接用TC的"窗口发送消息()"
//以下是对用到的结构体及TVM_INSERTITEM消息的说明

//————————————————————TV_INSERTSTRUCT结构体————————————————————
//typedef struct _TV_INSERTSTRUCT {  tvins
//    HTREEITEM hParent;
//    HTREEITEM hInsertAfter;
//    TV_ITEM   item;
//} TV_INSERTSTRUCT, FAR *LPTV_INSERTSTRUCT;
//
//The TV_INSERTSTRUCT structure contains information used to add a new item to a tree-view control.
//Members
//hParent
//Handle to the parent item. If this member is the TVI_ROOT value or NULL, the item is inserted at the root of the tree-view control.
//hInsertAfter
//Handle to the item after which the new item is to be inserted or one of the following values:
//Value        Meaning
//TVI_FIRST        Inserts the item at the beginning of the list.
//TVI_LAST        Inserts the item at the end of the list.
//TVI_SORT        Inserts the item into the list in alphabetical order.
//item
//Information about the item to add.
//Remarks
//This structure is used with the TVM_INSERTITEM message.
//——————————————————TV_ITEM结构体————————————————
//typedef struct _TV_ITEM {  tvi
//    UINT       mask;
//    HTREEITEM  hItem;
//    UINT       state;
//    UINT       stateMask;
//    LPSTR      pszText;
//    int        cchTextMax;
//    int        iImage;
//    int        iSelectedImage;
//    int        cChildren;
//    LPARAM     lParam;
//} TV_ITEM, FAR *LPTV_ITEM;
//
//The TV_ITEM structure specifies or receives attributes of a tree-view item.
//Members
//mask
//Array of flags that indicate which of the other structure members contain valid data or which are to be filled in. This member can be a combination of the following values:
//Value        Meaning
//TVIF_CHILDREN        The cChildren member is valid.
//TVIF_IMAGE        The iImage member is valid.
//TVIF_PARAM        The lParam member is valid.
//TVIF_SELECTEDIMAGE        The iSelectedImage member is valid.
//TVIF_STATE        The state and stateMask members are valid.
//TVIF_TEXT        The pszText and cchTextMax members are valid.
//hItem
//Item to which this structure refers.
//state and stateMask
//Variables specifying the current state of the item and the valid states of the item. This member can be any valid combination of state values. For a list of item states, see Tree-View Control C**tants.
//pszText
//Pointer to a null-terminated string that contains the item text if the structure specifies item attributes. If this member is the LPSTR_TEXTCALLBACK value, the parent window is resp**ible for storing the name. In this case, the tree-view control sends the parent window a TVN_GETDISPINFO notification message when it needs the item text for displaying, sorting, or editing and a TVN_SETDISPINFO notification message when the item text changes.
//If the structure is receiving item attributes, this member is the pointer to the buffer that receives the item text.
//cchTextMax
//Size of the buffer pointed to by the pszText member if the structure is receiving item attributes. If the structure specifies item attributes, this member is ignored.
//iImage and iSelectedImage
//Indices of the icon image and the selected icon image within the image list. If either member is the I_IMAGECALLBACK value, the parent window is resp**ible for storing the corresponding images. In this case, the tree-view control sends the parent a TVN_GETDISPINFO notification message when it needs to display the images and a TVN_SETDISPINFO notification message when the images change.
//cChildren
//Flag indicating whether the item has associated child items. It is one if the item has one or more child items; otherwise, it is zero. If this member is the I_CHILDRENCALLBACK value, the parent window is resp**ible for drawing the child items. In this case, the tree-view control sends the parent a TVN_GETDISPINFO notification message when it needs to display the child items and a TVN_SETDISPINFO notification message when the attributes of a child item change.
//lParam
//32-bit value to associate with the item.
//Remarks
//This structure is used with the TVM_GETITEM, TVM_SETITEM, and TVM_INSERTITEM messages. It is also included with many of the notification messages. When the structure is used to retrieve item information, only the structure members indicated by mask contain valid data. All other members are invalid.
//——————————————————TVM_INSERTITEM消息——————————————————
//TVM_INSERTITEM
//wParam = 0;
//lParam = (LPARAM) (LPTV_INSERTSTRUCT) lpis;
//
//// Corresponding macro
//HTREEITEM TreeView_InsertItem(hwnd, lpis);
//
//The TVM_INSERTITEM message inserts a new item in a tree-view control. You can send this message explicitly or by using the TreeView_InsertItem macro.
//Parameters
//hwnd
//Handle to the tree-view control.
//lpis
//Pointer to a TV_INSERTSTRUCT structure that specifies the attributes of the tree-view item.
//If the item label is being edited, the edit operation is canceled and the parent window receives the TVN_ENDLABELEDIT notification message.
//Return Value
//Returns the handle to the new item if successful or NULL otherwise

源码在下面,回复可下载:
游客,如果您要查看本帖隐藏内容请回复


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

评分

参与人数 2威望 +20 金币 +10 收起 理由
sxw005 + 10 感谢分享!
cjxdn + 10 + 10 很给力!

查看全部评分

回复

使用道具 举报

发表于 2019-10-8 20:38:42 | 显示全部楼层
看看
回复

使用道具 举报

发表于 2019-10-8 21:00:47 | 显示全部楼层
你的dll实现TC窗口可调大小最大化按钮可用
按钮怎么进行开启关闭
开启:窗体边框可以自由调节大小
关闭:关闭自由调节大小功能
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-10-8 23:16:39 | 显示全部楼层
本帖最后由 zxczxc1968531 于 2019-10-8 23:19 编辑
cjxdn 发表于 2019-10-8 21:00
你的dll实现TC窗口可调大小最大化按钮可用
按钮怎么进行开启关闭
开启:窗体边框可以自由调节大小

用消息路由拦截吧,用按钮控制自行添加
//消息路由功能
功能 实现窗口可调大小_消息路由(句柄, 消息, w参数, l参数, 时间, x坐标, y坐标)
    如果(消息 == 161 && (w参数 == 9 || w参数 == 10 || w参数 == 11 || w参数 == 12 || w参数 == 15))
        返回 真
    结束
    返回 假
结束
回复 支持 反对

使用道具 举报

发表于 2019-10-8 23:51:47 | 显示全部楼层
chen1882729,如果您要查看本帖隐藏内容请回复
回复 支持 反对

使用道具 举报

发表于 昨天 18:53 | 显示全部楼层
感谢分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /2 下一条

关闭

小黑屋|TC官方合作论坛 (苏ICP备18045623号)

GMT+8, 2019-10-19 04:03 , Processed in 0.038001 second(s), 24 queries .

Powered by 海安简单软件服务部

© 2008-2019 版权所有 保留所有权利

快速回复 返回顶部 返回列表