dllname USER cdeclare int SendMessage(HWND, int, int, long); const LB_INSERTSTRING = &h0181 const LB_DELETESTRING = &h0182 const LB_RESETCONTENT = &h0184 const LB_SETCURSEL = &h0186 const LB_GETTEXT = &h0189 const LB_SETTABSTOPS = &h0192 const EM_LIMITTEXT = &h00C5 dim tmp_grepout$ dim tmp_fileout$ sub AutoStart dim tmp$ tmp$ = Environ$("TMP") if right$(tmp$,1) <> "\" then tmp$ = tmp$ + "\" end if tmp_grepout$ = tmp$ + "~qxtmp1.tmp" tmp_fileout$ = tmp$ + "~qxtmp2.tmp" end sub sub ListBoxInsertString(index, text$) SendMessage(@@hwndToolListL, LB_INSERTSTRING, index, varptr(text$)) end sub sub ListBoxDeleteString(index) ListBoxSetCurSel -1 SendMessage(@@hwndToolListL, LB_DELETESTRING, index, 0) ListBoxSetCurSel index end sub sub ListBoxSetCurSel(index) if index = -1 then SendMessage(@@hwndToolListL, LB_SETCURSEL, index, 0) else if SendMessage(@@hwndToolListL, LB_SETCURSEL, index, 0) < 0 then SendMessage(@@hwndToolListL, LB_SETCURSEL, index-1, 0) end if end if end sub function ListBoxGetText$(index) dim x$ as string[10000] SendMessage(@@hwndToolListL, LB_GETTEXT, index, varptr(x$)) ListBoxGetText$ = x$ end function proc main umain command$(1) end proc 'QGREP を起動して、検索結果を常駐リストに登録する proc umain(index$) dim search$ dim file$ @@ToolListUserDef macrofilename$ + ",RClick", macrofilename$ + ",DblClick" @@PrintToolList = 1 dim tab[2] dim index dim k dim x$ dim ptr if index$ = "" then file$ = "" else file$ = tmp_fileout$ index = val(index$) k = 1 open file$ for output as #1 do while 1 x$ = ListBoxGetText$(index + k) k++ if x$ = "" or left$(x$, 1) = "●" then exit do ptr = instr(x$, chr$(9)) if ptr<>0 then x$ = mid$(x$, ptr+1) ptr = instr(x$, chr$(9)) if ptr<>0 then x$ = left$(x$, ptr-1) print #1, x$ end if end if loop close #1 file$ = "@" + file$ end if kill tmp_grepout$ search$ = Qgrep$(file$) if search$ = "" then exit proc if dir$(tmp_grepout$) = "" then exit proc 'SendMessage(@@hwndToolListL, LB_RESETCONTENT, 0, 0) tab[0] = 0 tab[1] = 4*20 SendMessage(@@hwndToolListL, LB_SETTABSTOPS, 2, varptr(tab)) dim s$ dim cnt cnt = 1 open tmp_grepout$ for input as #1 if eof(1) then exit proc lineinput #1, s$ 'skip filename if eof(1) then exit proc lineinput #1, s$ s$ = "●" + s$ ListBoxInsertString 0, s$ do until eof(1) lineinput #1, s$ ptr = instr(s$, chr$(9)) if ptr<>0 then dim f$ f$ = left$(s$, ptr-1) ptr = inrstr(s$, "\") if ptr<>0 then f$ = mid$(f$, ptr+1) end if s$ = f$ + chr$(9) + s$ ListBoxInsertString cnt, s$ cnt++ end if loop close #1 end proc 'ダブルクリックされたとき '@@command$(1) には リストボックス項目の文字列 '@@command$(2) には index(0〜 proc DblClick if left$(@@command$(1), 1) = "●" then umain @@command$(2) else openfile end if end proc '右クリックされたとき '@@command$(1) には リストボックス項目の文字列 '@@command$(2) には index(0〜 選択していないときは -1 proc RClick dim sel dim item$[15] dim ptr dim s$ dim n$ dim x$ dim index index = val(@@command$(2)) if left$(@@command$(1), 1) = "●" or index<0 then item$[1] = "しぼり込み検索" item$[2] = "一覧から削除" item$[3] = "-" item$[4] = "新規検索" item$[5] = "-" item$[6] = "編集中の文書一覧" item$[7] = "最近編集した文書一覧" item$[8] = "ファイル一覧" item$[9] = "その他の一覧" item$[10] = "バインダ一覧" item$[11] = chr$(1)+"ユーザー定義一覧" if index < 0 then item$[1] = chr$(1) + item$[1] item$[2] = chr$(1) + item$[2] end if sel = popupmenu(item$) if sel = 1 then umain @@command$(2) elseif sel = 2 then ListBoxSetCurSel -1 ListBoxDeleteString index do while 1 x$ = ListBoxGetText$(index) if x$ = "" or left$(x$, 1) = "●" then exit do ListBoxDeleteString index loop ListBoxSetCurSel index elseif sel = 4 then umain "" elseif 5 < sel and sel < 12 then @@ToolListType=sel-5 end if exit proc end if item$[1] = "開く" item$[2] = "一覧から削除" sel = popupmenu(item$) if sel = 1 then openfile elseif sel = 2 then ListBoxSetCurSel -1 ListBoxDeleteString val(@@command$(2)) ListBoxSetCurSel index end if end proc sub openfile dim s$ dim ptr dim n$ 'ファイルを開いて、ヒットした行にマークをつける s$ = @@command$(1) 'filefullpathline1 line2 ... ' [s$ ] [n$ ] ptr = instr(s$, chr$(9)) if ptr = 0 then exit proc s$ = mid$(s$, ptr+1) ptr = instr(s$, chr$(9)) if ptr = 0 then exit proc n$ = mid$(s$, ptr + 1) s$ = left$(s$, ptr - 1) 'if @@ActiveFile(s$) <>0 then exit proc if @@openfile(s$) = 0 then exit proc @redraw = 0 @MarkResetAll n$ = trim$(n$) do while n$<>"" ptr = instr(n$, " ") if ptr = 0 then s$ = n$ else s$ = left$(n$, ptr - 1) end if @Line = @crlinetoscrline(val(s$)) @MarkSet if ptr = 0 then exit do n$ = mid$(n$, ptr + 1) loop @redraw = 1 end sub function Qgrep$(file$) 'QGREPの起動 dim directory$ dim qgrep$ dim search$ dim option$ Qgrep$ = "" 'カレントディレクトリから検索する directory$ = curdir$() 'ファイルのあるディレクトリ '↑ここを 適当に変更してください 'directory$ = "C:\DOCUMENT" 'というように変更すれば、C:\DOCUMENT から検索するようになります 'QGREP のプログラム名 qgrep$ = "qgrep32.exe" 'QXがインストールされている場所以外にあるときは 'qgrep$ = "c:\qgrep\qgrep32.exe" のようにディレクトリも含めて指定してください DIALOG "QGREP", 0, 0, 265, 100, 0, "MS Pゴシック", 105 CONTROL "", 200, "STATIC", SS_LEFTNOWORDWRAP | WS_GROUP, 4, 4, 256, 8 CONTROL "検索文字列(&S):", -1, "STATIC", SS_LEFT | WS_GROUP, 12, 18, 68, 8 CONTROL "", 100, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP, 82, 17, 175, 12 CONTROL "検索ファイル(&F):", -1, "STATIC", SS_LEFT | WS_GROUP, 12, 34, 68, 8 CONTROL "", 101, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP, 82, 32, 175, 12 CONTROL "オプション(&O):", -1, "STATIC", SS_LEFT | WS_GROUP, 12, 49, 68, 8 CONTROL "", 102, "EDIT", ES_LEFT | ES_AUTOHSCROLL | WS_BORDER | WS_TABSTOP, 82, 47, 175, 12 CONTROL "検索しない(起動のみ)", 103, "BUTTON", BS_AUTOCHECKBOX | WS_GROUP | WS_TABSTOP, 12, 66, 95, 12 CONTROL "検索開始", IDOK, "BUTTON", BS_DEFPUSHBUTTON | WS_GROUP | WS_TABSTOP, 11, 80, 50, 14 CONTROL "キャンセル", IDCANCEL, "BUTTON", BS_PUSHBUTTON | WS_TABSTOP, 76, 80, 50, 14 dlgtext$ 200, "カレント = " + directory$ dim s$ if @hwnd then s$ = @GetCursorWord3$("_") dlgtext$ 100, s$ '@@Global$("qgrepstr") '検索する文字列 if file$ = "" then dlgtext$ 101, @@Global$("qgrepfile") '検索するファイル名 else dlgtext$ 101, file$ if left$(file$, 1) = "@" then dlgenable 101, 0 end if dlgtext$ 102, @@Global$("qgrepoption") call dlgitemcmd(100, EM_LIMITTEXT, 80, 0) call dlgitemcmd(101, EM_LIMITTEXT, 80, 0) call dlgitemcmd(102, EM_LIMITTEXT, 80, 0) do while 1 if dialog(1) = IDCANCEL then exit function end if if dlgtext$(100) <> "" then search$ = dlgtext$(100) @@Global$("qgrepstr") = search$ search$ = " """ + search$ + """ " file$ = dlgtext$(101) if left$(file$, 1) <> "@" then @@Global$("qgrepfile") = file$ end if if file$ = "" then file$ = "*.*" exit do end if beep loop option$ = " -!f2 -!w -e " if dlgvalue(103) then option$ = option$ + " -!s" end if option$ = option$ + " " + dlgtext$(102) @@Global$("qgrepoption") = dlgtext$(102) call dialog(0) if shell(qgrep$ + option$ + " -O" + tmp_grepout$ + " ""-d" + directory$ + """" + search$ + file$, -1) = 0 then call msgbox("QGREP を起動できません", MB_OK) else Qgrep$ = search$ end if end function