我说的是用API!!!!!不要告诉我List.List(n) = "aaa"也不要说先List1.RemoveItem,再List1.AddItem呵呵,俺说的是用Sendmessage或CopyMemory设置ListBox指定位置的值.我找了一天,只有LB_GETTEXT和LB_GETTEXTLEN,可是没有像LB_SETTEXT这样的常数..现在我已经可以获取当前位置条目(选中条目)的Index要替换ListBox中的第N个条目中的内容....!!!!用Sendmessage或CopyMemory!!!!那位大侠做过?
解决方案 »
- VB6.EXE中的0x034d207d处未处理的异常:0xC0000005:读取位置0x00143000时发生访问冲突
- 利用正则表达式从字符串中提取数据?
- 问高手 ,Byte的变量如何接起来的呀?
- VB怎么样对 SQL 2000的 Binary 字段进行读写操作?
- 如何让VB写的程序自动适应显示器的分辩率?
- 帮想想,如何在VB里设置Word文档的页眉页脚?
- VB无法加载现存窗体
- 为什么win98任务栏有很多没有字的任务?
- 我用API函數 ReportEvent 向系統日誌寫入數據的問題
- 我想用VB来实面一个虚拟目录的创建,来执行ASP文件!请问应该如何来实现。那位好心人有这方面的资料,请留下你的大名,分数一定奉上!
- 用VB生成OCX文件提示:Permission denied:“d:/toexecel/excel.ocx”,如何解决?
- 请julysixth(嘿呀)来接分.谢谢他在http://expert.csdn.net/Expert/topic/2868/2868560.xml?temp=.6964838给我的帮助
if ((lIndex >= 0) && (lIndex < lTotal))
{
/* Find what the current selection is */
lCurSel = SendMessage (hControl, LB_GETCURSEL,
(WPARAM)0,0L);
/* Insert new string at List(i) */
SendMessage (hControl, LB_INSERTSTRING,
(WPARAM)(lIndex), (LPARAM)szItem);
/* Delete string at List(i+1) */
SendMessage (hControl, LB_DELETESTRING,
(WPARAM)(lIndex+1), 0L);
/* Restore the current selection */
SendMessage (hControl, LB_SETCURSEL,
(WPARAM)lCurSel, 0L);
}
'---------------------
不要说先List1.RemoveItem,再List1.AddItem
'---------------------
lTotal = SendMessage (hControl,LB_GETCOUNT,0,0L);
if ((lIndex >= 0) && (lIndex < lTotal))
{
/* Find what the current selection is */
lCurSel = SendMessage (hControl, LB_GETCURSEL,
(WPARAM)0,0L);
/* Insert new string at List(i) */
SendMessage (hControl, LB_INSERTSTRING,
(WPARAM)(lIndex), (LPARAM)szItem);
/* Delete string at List(i+1) */
SendMessage (hControl, LB_DELETESTRING,
(WPARAM)(lIndex+1), 0L);
/* Restore the current selection */
SendMessage (hControl, LB_SETCURSEL,
(WPARAM)lCurSel, 0L);
}
'-------------------------------
两者有区别吗?要是这样,我就不会提这个问题了!我想知道可不可以找到ListBox保存字符串的地址,用Copymemory写进去...这样应该会比较快...如果先 移除,再添加,太慢了,也太麻烦....
rainstormmaster(暴风雨 v2.0)
你做过吗? 如何获得ListBox那个数组的地址?应该从那里下手?VB是怎么做到的?可以追踪到VB赋值的过程吗?
'===================================================
自已刨坑,自已埋....... :|
我kao…最近火氣大,不氣不氣,反正就不答你就成了。我可不說假話
'-----------------------------------------------
主 题: 送分题!修改ListBox中的第n个位置的值!
作 者: boyzhang (张郎)
'-----------------------------------------------
嘻嘻,這代碼偶有,而且保証是你想要的,但是!!!!偏偏就不給你'##############################################
1.rainstormmaster(暴风雨 v2.0)版主都搞不定,你?
我不相信你能写出来!(上网找的不算)
2.我学API也有年头了,提的问题均是自己先用很多种方
法搞不定(包括上网找)才在CSDN上提的..
3.我相信我在网上找东西还是有一套的,
家里4M ADSL单位10M光纤学校上网不要钱
我上网除了搜索资料也没有别的嗜好了..
我也知道你说的是什么,我见过一个可以拖的
ListBox控件(API处理),不过,我想知道的是我说的
用CopyMemory可不可以实现(效率会比较高)....
我的目的是做一个和Winamp列表一样的方便而强大的
列表钩子,自动处理ListBox的消息(自画,和ZYL910做的可以换肤的按钮一样)
现在已经可以实现单行/多行拖动了,不过是用的VB的
List.List(X)= 这样的方法,觉得不太妥,也看了书
搜了Google,MSDN,却没找到能我想要的那条消息...
4.书也看了好几十本,不过API的都不太全,刚刚买了
本O'REILLY的VB Win32API,搞定了
http://expert.csdn.net/Expert/topic/2739/2739860.xml?temp=.7045404
关于在VB中如何DLL注入 的问题
有兴趣可以看看..我有那本书的光盘
5.我没有别的意思,只是真搞不懂了才在CSDN上发贴,
真想把一个问题搞懂,如此而已...
//
// CMyListBox windowclass CMyListBox : public CListBox
{
// Construction
public:
CMyListBox(); // Attributes
private:
BOOL m_LButtonDownFlag;
BOOL m_MouseMoveFlag;
int m_OldPosition;
int m_NewPosition;
CString m_DragString;
DWORD m_ItemData;
public: // Operations
public: // Overrides
// ClassWizard generated virtual function overrides
file://{{AFX_VIRTUAL(CMyListBox)
file://}}AFX_VIRTUAL // Implementation
public:
virtual ~CMyListBox(); // Generated message map functions
protected:
file://{{AFX_MSG(CMyListBox)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
// NOTE - the ClassWizard will add and remove member functions here.
file://}}AFX_MSG DECLARE_MESSAGE_MAP()
};file://{{AFX_INSERT_LOCATION}} #endif // !defined(AFX_MYLISTBOX_H__CF3EDAA5_BBD7_43CD_80CB_A86B65D9A607__INCLUDED_)
// MyListBox.cpp : implementation file
file:// #include "stdafx.h"
#include "sditest.h"
#include "MyListBox.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif // CMyListBox CMyListBox::CMyListBox()
{
m_LButtonDownFlag = FALSE;
m_MouseMoveFlag = FALSE;
} CMyListBox::~CMyListBox()
{
}
BEGIN_MESSAGE_MAP(CMyListBox, CListBox)
file://{{AFX_MSG_MAP(CMyListBox)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
// NOTE - the ClassWizard will add and remove mapping macros here.
file://}}AFX_MSG_MAP
END_MESSAGE_MAP() // CMyListBox message handlers
void CMyListBox::OnLButtonDown(UINT nFlags, CPoint point)
{
CListBox::OnLButtonDown(nFlags, point);
file://如果选中一个条目,此时进行处理,否则会出错。
if(GetCurSel() != -1)
m_LButtonDownFlag = TRUE;
} void CMyListBox::OnLButtonUp(UINT nFlags, CPoint point)
{
CListBox::OnLButtonUp(nFlags, point);
m_LButtonDownFlag = FALSE;
if(m_MouseMoveFlag)
{
m_MouseMoveFlag = FALSE;
POINT pt;
::GetCursorPos(&pt);
CRect iRect;
this->GetWindowRect(iRect);
if(iRect.PtInRect(pt))//确定鼠标移动到了合适的位置
{
m_NewPosition = GetCurSel();
if(m_NewPosition < m_OldPosition)
{
InsertString(m_NewPosition,m_DragString);
DeleteString(m_OldPosition+1);
this->SetCurSel(m_NewPosition);
file://设置移动条目的副值,如果删除或者添加一条记录,副值会随字符串一起移动
SetItemData(m_NewPosition,m_ItemData);
TRACE("%d%d%d%d%d%d%d%d",GetItemData(0),GetItemData(1),_
GetItemData(2),GetItemData(3),GetItemData(4),_
GetItemData(5),GetItemData(6),GetItemData(7));
}
else
{
InsertString(m_NewPosition+1,m_DragString);
DeleteString(m_OldPosition);
this->SetCurSel(m_NewPosition);
SetItemData(m_NewPosition,m_ItemData);
TRACE("%d%d%d%d%d%d%d%d",GetItemData(0),GetItemData(1),_
GetItemData(2),GetItemData(3),GetItemData(4),_
GetItemData(5),GetItemData(6),GetItemData(7));
}
}
} } void CMyListBox::OnMouseMove(UINT nFlags, CPoint point)
{
CListBox::OnMouseMove(nFlags, point);
if(m_LButtonDownFlag)
{
m_MouseMoveFlag = TRUE;
m_OldPosition = GetCurSel();
GetText(m_OldPosition,m_DragString);
try{
m_ItemData = GetItemData(m_OldPosition);
}
catch(...)
{
AfxMessageBox("Wrong!");
} m_LButtonDownFlag = FALSE;
SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR1));
}
}