线程中如何给CViewABC类下的CListCtrl控件发消息?

snakebite2008 2005-09-13 01:37:58
如何给CViewABC类下的CListCtrl控件发消息?
CViewABC是我自己定义的类,这个View里面有个ClistCtrl控件.
我想将线程中获得的信息发给CListCtrl控件,让它执行插入操作。如何做呢?
给个例子吧!

这方面我太熟悉,向大家学习!
...全文
226 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
snakebite2008 2005-09-23
  • 打赏
  • 举报
回复
再请问大家,如何做才能让CListCtrl的效率比较好呢?比如插入?刷新?
phoenix96_2000 2005-09-19
  • 打赏
  • 举报
回复
补充一点就是:
你传入CListCtrl指针来使用InsertItem和传入句柄来用发送LVM_INSERTITEM没区别的,
因为CListCtrl::InsertItem本身实现就是发送这个消息
phoenix96_2000 2005-09-19
  • 打赏
  • 举报
回复
LVM_INSERTITEM Message

--------------------------------------------------------------------------------

Inserts a new item in a list-view control. You can send this message explicitly or by using the ListView_InsertItem macro.

Syntax


To send this message, call the SendMessage function as follows.
lResult = SendMessage( // returns LRESULT in lResult (HWND) hWndControl, // handle to destination control (UINT) LVM_INSERTITEM, // message ID (WPARAM) wParam, // = 0; not used, must be zero (LPARAM) lParam // = const (LPARAM) (LPLVITEM) pitem; );
Parameters

wParam
Must be zero.
pitem
Pointer to an LVITEM structure that specifies the attributes of the list-view item. Use the iItem member to specify the zero-based index at which the new item should be inserted. If this value is greater than the number of items currently contained by the listview, the new item will be appended to the end of the list and assigned the correct index. Examine the message's return value to determine the actual index assigned to the item.
Return Value

Returns the index of the new item if successful, or -1 otherwise.
-----------------------------------
example:

LVITEM item;
memset(&item,0,sizeof(LVITEM));
item.mask = LVIF_TEXT;
item.iItem = nIndex;
item.pszText = lpszText;
::SendMessage(hWndListCtrl,LVM_INSERTITEM,0,(LPARAM)(&item));
蒋晟 2005-09-19
  • 打赏
  • 举报
回复
1 可以将hwnd通过线程参数传递
2 SendMessage/PostMessage都可以。没有SendPostMessage这个API。
3 API不会用的话搜MSDN,可以找到大把的文档和示例
4 去看MFC的源代码里面怎么实现CListCtrl的。
snakebite2008 2005-09-18
  • 打赏
  • 举报
回复
大家来帮忙...
snakebite2008 2005-09-13
  • 打赏
  • 举报
回复
==

几个细节问题:
1. 如何获得hwnd?
2. 用哪个发送消息的命令?SendDlgItemMessage?SendMessage?SendPostMessage?或者其他?
3. 这些命令的参数格式和含义是怎样的?怎样设置?
4. 让CListCtrl响应“插入”或者其他的操作的消息内容是什么?

谢谢。。。。。
DentistryDoctor 2005-09-13
  • 打赏
  • 举报
回复
将这个ListCtrl的HWND作为参数传递给线程?
snakebite2008 2005-09-13
  • 打赏
  • 举报
回复
是“不太熟悉........”

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧