HSPポータル
サイトマップ お問い合わせ


HSPTV!掲示板


未解決 解決 停止 削除要請

2016
1026
ぺろリストビューのサブアイテムの中にcomboxを入れる5解決


ぺろ

リンク

2016/10/26(Wed) 12:05:14|NO.77242

リストビューの中にcomboxを入れたいのですが、色々調べてみた所
DataGridViewというものを使うと海外のサイトに書いてありました。

ですが、実装方法が分からなくて困っております。
分かる方、教えて下さい。



この記事に返信する


InoueSoftware

リンク

2016/10/26(Wed) 18:46:40|NO.77244

DataGridViewはHSPでは使えないので、一からリストビューに組み込まないといけません。

↓サンプル(入力選択編集が可能になった)

#uselib "comctl32.dll" #func InitCommonControls "InitCommonControls" #include "hscallbk.as" #uselib "" #func LvWndProc "" int,int,int,int setcallbk ListviewWndProc,LvWndProc,*MyListviewWndProc//コールバック関数の登録 #include "user32.as" #define ctype HIWORD(%1) ((%1 >>16) & 0xFFFF) InitCommonControls //コモンコントロール初期化 //リストビュー作成 winobj "SysListView32","",0x280,0x50000001|0x04,400,400 hListview = objinfo(stat, 2) SetWindowLong hListview,-4,varptr(ListviewWndProc)//サブクラス化 ListviewOldWndProc=stat sendmsg hListview, 0x1036, , 0x80|0x20|0x10 szText = "項目" LVCOLUMN = 0xF, 0 ,150, varptr(szText), 0 , 0 sendmsg hListview, 0x101B, 0, varptr(LVCOLUMN) szText = "内容" LVCOLUMN = 0xF, 0 ,150, varptr(szText), 0 , 0 sendmsg hListview, 0x101B, 1, varptr(LVCOLUMN) repeat 4 if cnt=0:pszText="製品名" if cnt=1:pszText="型番" if cnt=2:pszText="管理ID" if cnt=3:pszText="検査" LVITEM = 1 , cnt , 0 , 0 , 0 , varptr(pszText) sendmsg hListview, 0x1007, 0 , varptr(LVITEM)//追加 if cnt=0:pszText="インクジェットプリンタ" if cnt=1:pszText="IJP1800" if cnt=2:pszText="008599545" if cnt=3:pszText="OK" LVITEM = 1, cnt , 1 , 0 , 0 , varptr(pszText) sendmsg hListview, 0x1006, 0 , varptr(LVITEM)//追加 loop //入力関係ののコントロール作成 InputType=1,0,0,1//入力ボックスのタイプの設定(0が入力タイプ/1が選択(コンボボックス)タイプ) InputString="インクジェットプリンタ\nレーザープリンタ\nドットインパクトプリンタ","","","OK\nNG"//コンボボックスの内容の設定 //コンボボックス combox sComboBox,,"" iListviewComboBox=stat hListviewComboBox=objinfo(iListviewComboBox,2) SetParent hListviewComboBox,hListview //入力ボックス sListviewInput="" input ListviewInput iListviewInput=stat hListviewInput=objinfo(iListviewInput,2) SetParent hListviewInput,hListview oncmd gosub *OnCommand,0x0111 oncmd gosub *OnNotify,0x004E stop *MyListviewWndProc//リストビューのプロシージャ if callbkarg(1)==0x0114 | callbkarg(1)==0x0115{//WM_HSCROLL | WM_VSCROLL gosub *MoveInput CallWindowProc ListviewOldWndProc,callbkarg(0),callbkarg(1),callbkarg(2),callbkarg(3) }else{ CallWindowProc ListviewOldWndProc,callbkarg(0),callbkarg(1),callbkarg(2),callbkarg(3) } return *OnCommand if (HIWORD(wparam) == 0x0300/*EN_CHANGE*/) | (HIWORD(wparam) == 1/*CBN_SELCHANGE*/){//入力関係の内容に変更があった sendmsg hListview,0x100C,-1,0x0002 index=stat if index>=0{ //リストビュー項目に内容を反映 if InputType(index)=0{ sdim pszText sendmsg hListviewInput,0x000D, 0xFF , varptr(pszText) LVITEM = 1 , index , 1 , 0 , 0 , varptr(pszText) , 0xFF sendmsg hListview,0x1006,0,varptr(LVITEM) }else:if InputType(index)=1{ sdim pszText sendmsg hListviewComboBox,0x000D, 0xFF , varptr(pszText) LVITEM = 1 , index , 1 , 0 , 0 , varptr(pszText) , 0xFF sendmsg hListview,0x1006,0,varptr(LVITEM) } } } return *OnNotify dupptr nmhdr, lparam, 12 if nmhdr(0) == hListview & nmhdr(2) = -2{ sendmsg hListview,0x100C,-1,0x0002 index=stat if index>=0{ //入力関係のコントロールの内容にリストビュー項目の文字列を反映 if InputType(index)=0{//入力ボックス ShowWindow hListviewComboBox,0 ShowWindow hListviewInput,5 sdim pszText LVITEM = 1 , index , 1 , 0 , 0 , varptr(pszText) , 0xFF sendmsg hListview,0x1005,0,varptr(LVITEM) objprm iListviewInput,pszText }else:if InputType(index)=1{//選択ボックス ShowWindow hListviewComboBox,5 ShowWindow hListviewInput,0 objprm iListviewComboBox,InputString(index) sdim pszText LVITEM = 1 , index , 1 , 0 , 0 , varptr(pszText) , 0xFF sendmsg hListview,0x1005,0,varptr(LVITEM) sendmsg hListviewComboBox,0x0158,-1,pszText objprm iListviewComboBox,stat } gosub *MoveInput } } return *MoveInput//項目の位置から入力関係のコントロールの位置を計算し移動する sendmsg hListview,0x101F:hHeader=stat sendmsg hHeader,0x1207,1,varptr(Rect) Rect1=0,0,0,0:Rect2=0,0,0,0:Rect3=0,0,0,0 GetWindowRect hHeader,varptr(Rect1) GetWindowRect hListView,varptr(Rect2) sendmsg hListview,0x100C,-1,0x0002 index=stat sendmsg hListview,0x100E,index,varptr(Rect3) //GetClientRect hListview,varptr(Rect3) i=Rect2(0)-Rect1(0) Rect=Rect(0)-(i),Rect3(1),Rect3(2),Rect3(3) MoveWindow hListviewComboBox,Rect(0),Rect(1),Rect(2)-Rect(0),Rect(3)-Rect(1),1 MoveWindow hListviewInput,Rect(0),Rect(1),Rect(2)-Rect(0),Rect(3)-Rect(1),1 return

いつかモジュールを作ろうと思います



InoueSoftware

リンク

2016/10/26(Wed) 19:36:44|NO.77245

モジュールを急いで作りました。自由に使って大丈夫です。
ホームページにもそのうちアップしときます。
不明な点は質問してください。
Hscallbk必須 DL→http://chokuto.ifdef.jp/download/index.html#hscallbk

※以前作ったソフトの一部を流用。
※不具合なし。(恐らく...)
※サンプル付き




//命令・関数説明 //Init_ListViewEx モジュール初期化 //Create_ListViewEx リストビューを作成 //引数 : Style,ExStyle,PosX,PosY,SizeX,SizeY //戻り値 : 管理ID //SetEditMode_ListViewEx リストビューの編集ボックスの種類 //引数 : 管理ID,種類を示す文字列(0=編集不可/1=入力ボックス/2=選択ボックス) //SetComboBoxList_ListViewEx リストビューの選択ボックスの項目設定 //引数 : 管理ID,項目ID,リスト(複数の場合は\nで区切る) //GetHwnd_ListViewEx リストビューのウィンドウハンドル取得 //引数 : 管理ID //戻り値 : ウィンドウハンドル //▼▼▼モジュールここから▼▼▼ #module #uselib "comctl32.dll" #func InitCommonControls "InitCommonControls" #include "hscallbk.as" #uselib "" #func LvWndProc "" int,int,int,int #include "user32.as" #define ctype HIWORD(%1) ((%1 >>16) & 0xFFFF) #deffunc Init_ListViewEx InitCommonControls //コモンコントロール初期化 MaxListView=0 sdim EditMode,0 sdim ComboBoxStr,0,500 setcallbk ListviewWndProc,LvWndProc,*MyListviewWndProc//コールバック関数の登録 oncmd gosub *OnCommand,0x0111 oncmd gosub *OnNotify,0x004E return #deffunc Create_ListViewEx int style,int exstyle,int posx,int posy,int sizex,int sizey //リストビュー作成 pos posx,posy:winobj "SysListView32","",exstyle,style,sizex,sizey hListview(MaxListView) = objinfo(stat, 2) SetWindowLong hListview(MaxListView),-4,varptr(ListviewWndProc)//サブクラス化 ListviewOldWndProc(MaxListView)=stat SetWindowLong hListview(MaxListView),-21,MaxListView //入力関係ののコントロール作成 //コンボボックス combox sComboBox,,"" iListviewComboBox(MaxListView)=stat hListviewComboBox(MaxListView)=objinfo(iListviewComboBox(MaxListView),2) SetParent hListviewComboBox(MaxListView),hListview(MaxListView) SetWindowLong hListviewComboBox(MaxListView),-21,MaxListView //入力ボックス sListviewInput="" input ListviewInput iListviewInput(MaxListView)=stat hListviewInput(MaxListView)=objinfo(iListviewInput(MaxListView),2) SetParent hListviewInput(MaxListView),hListview(MaxListView) SetWindowLong hListviewInput(MaxListView),-21,MaxListView EditMode(MaxListView)="" MaxListView++ return MaxListView-1 #deffunc SetEditMode_ListViewEx int id,str Mode EditMode(id)=Mode return #deffunc SetComboBoxList_ListViewEx int id,int index,str s ComboBoxStr(id,index)=s return #defcfunc GetHwnd_ListViewEx int id return hListview(id) #deffunc MoveInput_ListViewEx int id//項目の位置から入力関係のコントロールの位置を計算し移動する sendmsg hListview(id),0x101F:hHeader=stat sendmsg hHeader,0x1207,1,varptr(Rect) Rect1=0,0,0,0:Rect2=0,0,0,0:Rect3=0,0,0,0 GetWindowRect hHeader,varptr(Rect1) GetWindowRect hListView(id),varptr(Rect2) sendmsg hListview(id),0x100C,-1,0x0002 index=stat sendmsg hListview(id),0x100E,index,varptr(Rect3) //GetClientRect hListview,varptr(Rect3) i=Rect2(0)-Rect1(0) Rect=Rect(0)-(i),Rect3(1),Rect3(2),Rect3(3) MoveWindow hListviewComboBox(id),Rect(0),Rect(1),Rect(2)-Rect(0),Rect(3)-Rect(1),1 MoveWindow hListviewInput(id),Rect(0),Rect(1),Rect(2)-Rect(0),Rect(3)-Rect(1),1 return *MyListviewWndProc//リストビューのプロシージャ GetWindowLong callbkarg(0),-21:cid=stat if callbkarg(1)==0x0114 | callbkarg(1)==0x0115{//WM_HSCROLL | WM_VSCROLL MoveInput_ListViewEx cid CallWindowProc ListviewOldWndProc(cid),callbkarg(0),callbkarg(1),callbkarg(2),callbkarg(3) }else{ CallWindowProc ListviewOldWndProc(cid),callbkarg(0),callbkarg(1),callbkarg(2),callbkarg(3) } return *OnCommand if (HIWORD(wparam) == 0x0300/*EN_CHANGE*/) | (HIWORD(wparam) == 1/*CBN_SELCHANGE*/){//入力関係の内容に変更があった GetWindowLong lparam,-21:cid=stat sendmsg hListview(cid),0x100C,-1,0x0002 index=stat if index>=0{ //リストビュー項目に内容を反映 if strmid(EditMode(cid),index,1)="1"{ sdim pszText sendmsg hListviewInput(cid),0x000D, 0xFF , varptr(pszText) LVITEM = 1 , index , 1 , 0 , 0 , varptr(pszText) , 0xFF sendmsg hListview(cid),0x1006,0,varptr(LVITEM) }else:if strmid(EditMode(cid),index,1)="2"{ sdim pszText sendmsg hListviewComboBox(cid),0x000D, 0xFF , varptr(pszText) LVITEM = 1 , index , 1 , 0 , 0 , varptr(pszText) , 0xFF sendmsg hListview(cid),0x1006,0,varptr(LVITEM) } } } return *OnNotify dupptr nmhdr, lparam, 12 GetWindowLong nmhdr(0),-21:cid=stat if nmhdr(0) == hListview(cid) & nmhdr(2) = -2{ sendmsg hListview(cid),0x100C,-1,0x0002 index=stat if index>=0{ //入力関係のコントロールの内容にリストビュー項目の文字列を反映 if strmid(EditMode(cid),index,1)="1"{//入力ボックス ShowWindow hListviewComboBox(cid),0 ShowWindow hListviewInput(cid),5 sdim pszText LVITEM = 1 , index , 1 , 0 , 0 , varptr(pszText) , 0xFF sendmsg hListview(cid),0x1005,0,varptr(LVITEM) objprm iListviewInput(cid),pszText }else:if strmid(EditMode(cid),index,1)="2"{//選択ボックス ShowWindow hListviewComboBox(cid),5 ShowWindow hListviewInput(cid),0 objprm iListviewComboBox(cid),ComboBoxStr(cid,index) sdim pszText LVITEM = 1 , index , 1 , 0 , 0 , varptr(pszText) , 0xFF sendmsg hListview(cid),0x1005,0,varptr(LVITEM) sendmsg hListviewComboBox(cid),0x0158,-1,pszText objprm iListviewComboBox(cid),stat }else{ ShowWindow hListviewComboBox(cid),0 ShowWindow hListviewInput(cid),0 } MoveInput_ListViewEx cid } } return #global //▲▲▲モジュールここまで▲▲▲ //サンプル▼ Init_ListViewEx Create_ListViewEx 0x50000001|0x04,0x280,0,0,400,400:iListViewEx=stat SetEditMode_ListViewEx iListViewEx,"2112" SetComboBoxList_ListViewEx iListViewEx,0,"インクジェットプリンタ\nレーザープリンタ\nドットインパクトプリンタ" SetComboBoxList_ListViewEx iListViewEx,3,"OK\nNG" hListview=GetHwnd_ListViewEx(iListViewEx) sendmsg hListview, 0x1036, , 0x80|0x20|0x10 szText = "項目" LVCOLUMN = 0xF, 0 ,150, varptr(szText), 0 , 0 sendmsg hListview, 0x101B, 0, varptr(LVCOLUMN) szText = "内容" LVCOLUMN = 0xF, 0 ,150, varptr(szText), 0 , 0 sendmsg hListview, 0x101B, 1, varptr(LVCOLUMN) repeat 4 if cnt=0:pszText="製品名" if cnt=1:pszText="型番" if cnt=2:pszText="管理ID" if cnt=3:pszText="検査" LVITEM = 1 , cnt , 0 , 0 , 0 , varptr(pszText) sendmsg hListview, 0x1007, 0 , varptr(LVITEM)//追加 if cnt=0:pszText="インクジェットプリンタ" if cnt=1:pszText="IJP1800" if cnt=2:pszText="008599545" if cnt=3:pszText="OK" LVITEM = 1, cnt , 1 , 0 , 0 , varptr(pszText) sendmsg hListview, 0x1006, 0 , varptr(LVITEM)//追加 loop Create_ListViewEx 0x50000001|0x04,0x280,400,0,200,400:iListViewEx2=stat SetEditMode_ListViewEx iListViewEx2,"011" hListview2=GetHwnd_ListViewEx(iListViewEx2) sendmsg hListview2, 0x1036, , 0x80|0x20|0x10 szText = "項目" LVCOLUMN = 0xF, 0 ,100, varptr(szText), 0 , 0 sendmsg hListview2, 0x101B, 0, varptr(LVCOLUMN) szText = "内容" LVCOLUMN = 0xF, 0 ,150, varptr(szText), 0 , 0 sendmsg hListview2, 0x101B, 1, varptr(LVCOLUMN) repeat 3 if cnt=0:pszText="使用者種" if cnt=1:pszText="使用者名" if cnt=2:pszText="使用者ID" LVITEM = 1 , cnt , 0 , 0 , 0 , varptr(pszText) sendmsg hListview2, 0x1007, 0 , varptr(LVITEM)//追加 if cnt=0:pszText="検査員" if cnt=1:pszText="名無し" if cnt=2:pszText="2146120" LVITEM = 1, cnt , 1 , 0 , 0 , varptr(pszText) sendmsg hListview2, 0x1006, 0 , varptr(LVITEM)//追加 loop



ぺろ

リンク

2016/10/27(Thu) 13:38:15|NO.77256

おぉ・・・
これはcombox以外にも対応してるんですね
こんなに長いソースありがとうございます!

私のパソコンのOSはWindows7とWindows8.1ですがちゃんと動作しました。
このプログラムはWindowsXP以降で完全動作するのでしょうか?(Windows10など)



InoueSoftware

リンク

2016/10/27(Thu) 21:30:18|NO.77257

このモジュールは、HSPとリストビューとコンボボックスが使用できるOSで使えますので、
WindowsXP以降対応となります。
私は、Win XPと7のマシンしかないので、確信できませんが...



ぺろ

リンク

2016/10/27(Thu) 23:20:16|NO.77259

ありがとうございます。
他のOSでも動くか検証してみます!
comboxの挙動をWindows標準の物と似させたく色々と弄ってみました。
comboxの文字をセンタリングする事ができればもうちょっと綺麗な感じに動きそうですね
(comboxの文字センタリングは調べて見ましたができそうにないですね(・_・;)


#include "llmod3/llmod3.hsp" #include "llmod3/listview.hsp" #include "llmod3/img.hsp" #include "llmod3/obj.hsp" #uselib "comctl32.dll" #func InitCommonControls "InitCommonControls" #include "hscallbk.as" #uselib "" #func LvWndProc "" int,int,int,int setcallbk ListviewWndProc,LvWndProc,*MyListviewWndProc//コールバック関数の登録 #uselib "user32.dll" #func SetWindowLong "SetWindowLongA" sptr, sptr, sptr #func SetParent "SetParent" int,int #func CallWindowProc "CallWindowProcA" var, int, int, int, int #func ShowWindow "ShowWindow" int,int #func GetWindowRect "GetWindowRect" int, int #func MoveWindow "MoveWindow" int, int , int , int , int , int , int , #func GetCursorPos "GetCursorPos" int #func ScreenToClient2 "ScreenToClient" int,int #func GetWindowLongX "GetWindowLongA" sptr, sptr #func SetWindowLongX "SetWindowLongA" sptr, sptr, sptr #const LVS_EDITLABELS 0x0200 #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_ITEMCHANGING $FFFFFF9C #define NM_CLICK $FFFFFFFE #define NM_KILLFOCUS $FFFFFFF8 #define EN_KILLFOCUS $00000200 #define WM_SETTEXT $0000000C #const HDN_FIRST -300 #const HDN_DIVIDERDBLCLICKW -300 #const HDN_ITEMCLICK -302 #const HDN_DIVIDERDBLCLICK -305 #const HDN_BEGINTRACK -306 #const HDN_ENDTRACK -307 #const HDN_TRACK -308 #const HDN_GETDISPINFO -309 #const HDN_BEGINDRAG -310 #const HDN_ENDDRAG -311 #define ctype MAKELONG(%1,%2) (%1) & $FFFF | (%2) << 16 #define ctype HIWORD(%1) ((%1 >>16) & 0xFFFF) #define CB_SHOWDROPDOWN $14F InitCommonControls //コモンコントロール初期化 //リストビュー作成 winobj "SysListView32","",0x280,0x50000001|0x04|$10000,400,400 hListview = objinfo(stat, 2) ListviewOldWndProc=stat sendmsg hListview, 0x1036, , 0x80|0x20|0x10 szText = "項目" LVCOLUMN = 0xF, 0 ,150, varptr(szText), 0 , 0 sendmsg hListview, 0x101B, 0, varptr(LVCOLUMN) szText = "内容" LVCOLUMN = 0xF, 0 ,150, varptr(szText), 0 , 0 sendmsg hListview, 0x101B, 1, varptr(LVCOLUMN) kazu = 5 repeat kazu pszText="製品名" LVITEM = 1 , cnt, 0 , 0 , 0 , varptr(pszText) sendmsg hListview, 0x1007, 0 , varptr(LVITEM)//追加 pszText="インクジェットプリンタ" LVITEM = 1, cnt, 1 , 0 , 0 , varptr(pszText) sendmsg hListview, 0x1006, 0 , varptr(LVITEM)//追加 loop //入力関係ののコントロール作成 InputType=1,1;,0,1//入力ボックスのタイプの設定(0が入力タイプ/1が選択(コンボボックス)タイプ) dim InputType,kazu+1 repeat kazu : InputType(cnt) = 1 : loop InputString="インクジェットプリンタ\nレーザープリンタ\nドットインパクトプリンタ","","","OK\nNG"//コンボボックスの内容の設定 //コンボボックス combox sComboBox,,"" iListviewComboBox=stat hListviewComboBox=objinfo(iListviewComboBox,2) SetParent hListviewComboBox,hListview oncmd gosub *OnCommand,0x0111 oncmd gosub *OnNotify,0x004E stop *MyListviewWndProc//リストビューのプロシージャ if callbkarg(1)==0x0114 | callbkarg(1)==0x0115{//WM_HSCROLL | WM_VSCROLL gosub *MoveInput CallWindowProc ListviewOldWndProc,callbkarg(0),callbkarg(1),callbkarg(2),callbkarg(3) }else{ CallWindowProc ListviewOldWndProc,callbkarg(0),callbkarg(1),callbkarg(2),callbkarg(3) } return *OnCommand if (HIWORD(wparam) == 0x0300/*EN_CHANGE*/) | (HIWORD(wparam) == 1/*CBN_SELCHANGE*/){//入力関係の内容に変更があった sendmsg hListview,0x100C,-1,0x0002 index=stat if index>=0{ if InputType(index)=1{ ;dialog "1" sdim pszText sendmsg hListviewComboBox,0x000D, 0xFF , varptr(pszText) LVITEM = 1 , index , 1 , 0 , 0 , varptr(pszText) , 0xFF sendmsg hListview,0x1006,0,varptr(LVITEM) ShowWindow hListviewComboBox,0 ; 変更があった場合すぐ閉じる } } } return *OnNotify dupptr nmhdr, lparam, 12 if nmhdr(0) == hListview & nmhdr(2) = -2{ sendmsg hListview,0x100C,-1,0x0002 index=stat if index>=0{ if InputType(index)=1{//選択ボックス dim point,2 dim rect,4 dim lvhittestinfo ,6 dim lvitem,9 cfocus=-1 sdim text,1000 // マウス下の情報を取得 GetCursorPos varptr(point) ScreenToClient2 hListview, varptr(point) lvhittestinfo=point(0),point(1) sendmsg hListview,LVM_SUBITEMHITTEST,0,varptr(lvhittestinfo) if lvhittestinfo(4) ! 1 : return // カラム 【内容】以外のクリックの場合は弾く objprm iListviewComboBox,InputString(0) sdim pszText LVITEM = 1 , index , 1 , 0 , 0 , varptr(pszText) , 0xFF sendmsg hListview,0x1005,0,varptr(LVITEM) sendmsg hListviewComboBox,0x0158,-1,pszText objprm iListviewComboBox,stat gosub *MoveInput } } } return *MoveInput // マウス下の情報を元に・・・色々取得して・・・comboxの幅をカラムと同じにする (カラムの大きさ変更に対応させる為) objprm iListviewComboBox,0 ; 初期選択IDに戻す rect=LVIR_LABEL,lvhittestinfo(4),0,0 sendmsg hListview,LVM_GETSUBITEMRECT,lvhittestinfo(3),varptr(rect) lvitem=LVIF_TEXT,lvhittestinfo(3),lvhittestinfo(4),0,0,varptr(text),1000 sendmsg hListview,LVM_GETITEM,0,varptr(lvitem) MoveWindow hListviewComboBox,rect,rect(1),rect(2)-rect,rect(3)-rect(1),1 ShowWindow hListviewComboBox,5 ; MoveWindowの前にShowWindowでオブジェクトを表示すると前回の座標のまま出現する為、点滅に見えてしまう sendmsg hListviewComboBox, CB_SHOWDROPDOWN, 1 ; combox ドロップダウンメッセージ return



ONION software Copyright 1997-2023(c) All rights reserved.