SendMessage,LB_setitemdata [英] SendMessage, LB_setitemdata

查看:85
本文介绍了SendMessage,LB_setitemdata的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 
Private Const LB_ADDSTRING As Integer = &H180
Private Const LB_SETITEMDATA As Integer = &H19A
pblic Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Public Declare Function SendMessageStr Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
Public Sub LoadPlanes(ByVal Handle As Integer)strFeatureName = oFeature.Name 'Get from Soldiworks
'add plane to listbox using api call 
 lngRet = SendMessageStr(Handle, LB_ADDSTRING, 0&, strFeatureName)
  Dim t As Integer = SendMessage(Handle, LB_SETITEMDATA, lngRet, 0)
End sub

我用它来以vb.net形式将项目添加到列表框中。字符串显示在列表框中,但listbox1.item.count = 0,表示我无法获取所选项目文本。

I use this to add items to listbox in vb.net form. String are show up in the listbox, but listbox1.item.count=0, that mean i could not get the selected item text.

我也试过使用SendmessageStr(句柄,LB_SETITEMDATA,LngRet,strFeatureName)

I also tried to use SendmessageStr(handle, LB_SETITEMDATA,LngRet,strFeatureName)

仍然有相同的东西。任何人都可以帮助我。

still got samething. anyone can help me with this.

谢谢。

推荐答案

listbox1 似乎是插入到表单中的 ListBox 控件,然后您可以使用
listbox1.Items.Add(strFeatureName)

Since listbox1 seems to be a ListBox control inserted into your form, then you can use listbox1.Items.Add(strFeatureName).

如果您想将某些自定义数据与每个项目相关联,那么您可以添加自己的类,而不是添加字符串,该类包含特定数据并覆盖
ToString ToString 返回的字符串将显示在列表框中。

If you want to associate some custom data with each item, then instead of adding strings you can add your own class, which contains specific data and also overrides ToString. The strings returned by ToString will be displayed in the listbox.


这篇关于SendMessage,LB_setitemdata的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆