by wakaba » 2007年2月17日(土) 22:32
初歩的な質問ですが リストボックスデータの取得が うまくいきません
ヘルプで 調べてましたが 調子よくないので このコミュに あった例を使ってみました。APIも ポインタも良く理解していない事が 原因でしょうが はっきりしません。
”NoWest” さんの投稿に 以下があり 使ってみようと思いますが 初期でつまづいてしまいます。
Sub MainWnd_ListBox1_SelChange()
Dim pos As Long
pos = SendMessage(GetDlgItem(hMainWnd,ListBox1),LB_GETCURSEL,0,0)
Dim Data As String
GetListBoxStr(GetDlgItem(hMainWnd,ListBox1),pos,Data)
End Sub
Function GetListBoxStr(hLB As HWND, pos As Long, ByRef str As String) As Long
Dim Length As Long
Length = SendMessage(hLB,LB_GETTEXTLEN,pos,0)
str = ZeroString(Length)
If Length = 0 Then
GetListBoxStr = 0
Exit Function
End If
GetListBoxStr = SendMessage(hLB,LB_GETTEXT,pos,StrPtr(str))
SetDWord(StrPtr(str) - SizeOf (DWord), GetListBoxStr)
End Function
Function GetDlgLisBoxStr(hDlg As HWND, idLB As Long, pos As Long, ByRef str As String) As Long
GetDlgLisBoxStr = GetListBoxStr(GetDlgItem(hDlg, idLB), pos, str)
End Function
このコードで Dataに 期待した文字が 返らないのです
ここで pos は リストボックスのindexと考えて良いのでしょうか
また GetDlgLisBoxStr() は 何の役目があるのでしょう?
やりたい事:
文字列を リストボックスに追加したいが 既に 登録されているものは 除きたい
そのため リストボックスの中身を index毎に 取り出したい
複数列のリストボックスは ややこしそうなので 1列に設定しています
(index番号は 不要)
初歩的な質問ですが リストボックスデータの取得が うまくいきません
ヘルプで 調べてましたが 調子よくないので このコミュに あった例を使ってみました。APIも ポインタも良く理解していない事が 原因でしょうが はっきりしません。
”NoWest” さんの投稿に 以下があり 使ってみようと思いますが 初期でつまづいてしまいます。
Sub MainWnd_ListBox1_SelChange()
Dim pos As Long
pos = SendMessage(GetDlgItem(hMainWnd,ListBox1),LB_GETCURSEL,0,0)
Dim Data As String
GetListBoxStr(GetDlgItem(hMainWnd,ListBox1),pos,Data)
End Sub
Function GetListBoxStr(hLB As HWND, pos As Long, ByRef str As String) As Long
Dim Length As Long
Length = SendMessage(hLB,LB_GETTEXTLEN,pos,0)
str = ZeroString(Length)
If Length = 0 Then
GetListBoxStr = 0
Exit Function
End If
GetListBoxStr = SendMessage(hLB,LB_GETTEXT,pos,StrPtr(str))
SetDWord(StrPtr(str) - SizeOf (DWord), GetListBoxStr)
End Function
Function GetDlgLisBoxStr(hDlg As HWND, idLB As Long, pos As Long, ByRef str As String) As Long
GetDlgLisBoxStr = GetListBoxStr(GetDlgItem(hDlg, idLB), pos, str)
End Function
このコードで Dataに 期待した文字が 返らないのです
ここで pos は リストボックスのindexと考えて良いのでしょうか
また GetDlgLisBoxStr() は 何の役目があるのでしょう?
やりたい事:
文字列を リストボックスに追加したいが 既に 登録されているものは 除きたい
そのため リストボックスの中身を index毎に 取り出したい
複数列のリストボックスは ややこしそうなので 1列に設定しています
(index番号は 不要)