http://hsp.tv/play/pforum.php?mode=pastwch&num=66783
内のNO.66885のYTT氏のソースコードが非常に良くできていたので、スクロール時や特定キーの操作時の挙動を加えたコードを考えました。
割とスマートに実現できたので、自己満足ですがコードだけ貼っておきますので、ご参考になればと思います。
#include "llmod3/llmod3.hsp" #include "llmod3/listview.hsp" #include "llmod3/img.hsp" #undef charupper #undef charlower #include "user32.as" #define SW_HIDE $00000000 #define SW_SHOW $00000005 #define WM_COMMAND $00000111 #define WS_CLIPCHILDREN $02000000 #define LVM_SUBITEMHITTEST $00001039 #define LVM_GETSUBITEMRECT $00001038 #define LVIR_LABEL $00000002 #define LVIF_TEXT $00000001 #define LVM_GETITEM $00001005 #define LVM_SETITEM $00001006 #define LVM_GETNEXTITEM $0000100C #define LVNI_FOCUSED $00000001 #define LVN_BEGINSCROLL $FFFFFF4C #define LVN_ITEMCHANGING $FFFFFF9C #define NM_CLICK $FFFFFFFE #define NM_KILLFOCUS $FFFFFFF8 #define EN_KILLFOCUS $00000200 #define WM_SETTEXT $0000000C #define WM_GETTEXT $0000000D listview 400, 200, $310009 | WS_CLIPCHILDREN hList = objinfo_hwnd(stat) listaddcl 0, "test1", 100, 2 listaddcl 1, "test2", 100 listaddcl 2, "test3", 100 repeat 10 listadd 0, "あいうえお", 0 listadd 1, "かきくけこ", 0 listadd 0, "さしすせそ", 1 listadd 1, "たちつてと", 1 listadd 0, "なにぬねの", 2 listadd 1, "はひふへほ", 2 loop dim point, 2 dim rect, 4 dim lvHitTestInfo, 6 dim lvitem, 9 cFocus = -1 sdim text, 1000 input text, 0, 0 obj = stat hEdit = objinfo_hwnd(stat) SetParent hEdit, hList ShowWindow hEdit, SW_HIDE oncmd gosub *WM_NOTIFY, 0x4E oncmd gosub *ON_COMMAND, WM_COMMAND onkey gosub *KeyDown stop ;------------------------------------------------------------------------------- *WM_NOTIFY dupptr NMHDR, lParam, 12 if (NMHDR(0) == hList) { if (NMHDR(2) == NM_CLICK) { sendmsg hList, LVM_GETNEXTITEM, -1, LVNI_FOCUSED if (stat < 0) : return if (stat == cFocus) { GetCursorPos varptr(point) ScreenToClient hList, varptr(point) lvHitTestInfo = point(0), point(1) sendmsg hList, LVM_SUBITEMHITTEST, 0, varptr(lvHitTestInfo) rect = LVIR_LABEL, lvHitTestInfo(4), 0, 0 sendmsg hList, LVM_GETSUBITEMRECT, lvHitTestInfo(3), varptr(rect) lvItem = LVIF_TEXT, lvHitTestInfo(3), lvHitTestInfo(4), 0, 0, varptr(text), 1000 sendmsg hList, LVM_GETITEM, 0, varptr(lvItem) MoveWindow hEdit, rect(0), rect(1), rect(2) - rect(0), rect(3) - rect(1), 1 ShowWindow hEdit, SW_SHOW objprm obj, text objsel obj } return } if (NMHDR(2) == LVN_BEGINSCROLL) { ; リストビュースクロール時の処理 ShowWindow hEdit, SW_HIDE cFocus = -1 return } if (NMHDR(2) == LVN_ITEMCHANGING) { sendmsg hList, LVM_GETNEXTITEM, -1, LVNI_FOCUSED if (stat >= 0) : cFocus = stat return 0 } } return *ON_COMMAND if (lParam == hEdit) { IsWindowVisible hEdit if ((wParam >> 16 & 0xffff) == EN_KILLFOCUS && stat != 0) { ; 入力ボックスからフォーカスが外れたときの処理 sendmsg hEdit, WM_GETTEXT, 1000, varptr(text) lvItem = LVIF_TEXT, lvHitTestInfo(3), lvHitTestInfo(4), 0, 0, varptr(text), 1000 sendmsg hList, LVM_SETITEM, 0, varptr(lvItem) ShowWindow hEdit, SW_HIDE cFocus = -1 } } return *KeyDown IsWindowVisible hEdit if (wParam == 13 && stat != 0) { ; 入力ボックスでEnterキーが押された時の処理 sendmsg hEdit, WM_GETTEXT, 1000, varptr(text) lvItem = LVIF_TEXT, lvHitTestInfo(3), lvHitTestInfo(4), 0, 0, varptr(text), 1000 sendmsg hList, LVM_SETITEM, 0, varptr(lvItem) ShowWindow hEdit, SW_HIDE cFocus = -1 } if (wParam == 27 && stat != 0) { ; 入力ボックスでEscキーが押された時の処理 ShowWindow hEdit, SW_HIDE cFocus = -1 } return