【HSP3】Windows版 日蒙簡易辞書

Windows 2000以降

Windows 2000以降

  • タグ:
  • タグはありません
#include "user32.as"
#module
#uselib "msvcrt"
#cfunc strstr "strstr" int, sptr
#uselib "kernel32"
#func MultiByteToWideChar "MultiByteToWideChar" int, int, sptr, int, sptr, int
#func WideCharToMultiByte "WideCharToMultiByte" int, int, sptr, int, sptr, int, int, int
#deffunc UTF8ToUnicode var in, var out
	MultiByteToWideChar 65001/*CP_UTF8*/, 0, varptr(in), -1, 0, 0
	len = stat
	sdim out, len * 2 + 2
	MultiByteToWideChar 65001/*CP_UTF8*/, 0, varptr(in), -1, varptr(out), len
return len
#deffunc UnicodeToUTF8 var in, var out
 	// Unicode → UTF-8
	WideCharToMultiByte 65001/*CP_UTF8*/, 0, varptr(in), -1, 0, 0, 0, 0
	len = stat
	sdim out, len + 1
	WideCharToMultiByte 65001/*CP_UTF8*/, 0, varptr(in), -1, varptr(out), len, 0, 0
return len
#deffunc ShiftJISToUTF8 str _in_sjis, var out_utf8
	in_sjis = _in_sjis
	// SHIFT_JIS → Unicode
	len = strlen(_in_sjis) * 2
    sdim uni, len + 2
 	cnvstow uni, _in_sjis
 	// Unicode → UTF-8
	WideCharToMultiByte 65001/*CP_UTF8*/, 0, varptr(uni), -1, 0, 0, 0, 0
	len = stat
	sdim out_utf8, len + 1
	WideCharToMultiByte 65001/*CP_UTF8*/, 0, varptr(uni), -1, varptr(out_utf8), len, 0, 0
return len
#deffunc BOMDelete var in_utf8
	// EF BB BF(BOM) 手抜き~
	if (0xBFBBEF == (lpeek(in_utf8, 0) & 0xFFFFFF)){
		len = strlen(in_utf8)
		sdim copybuf, len*2 + 1
		copybuf = in_utf8
		sdim in_utf8, len*2 + 1
		memcpy in_utf8, copybuf, len, 0, 3
		return 1
	}
return 0
// instr(UTF8対応版)
#defcfunc instr_utf8 var in_buf, int p, str _key
	key = _key
	inbuf_ptr = varptr(in_buf) + p
	s_pos = strstr(inbuf_ptr, key)
	if s_pos == 0 : return -1
return (s_pos - inbuf_ptr)
#global

	tt = "日蒙簡易辞書 Ver 1.00(Unicode対応版)"
*main
	exist "jmdic.txt"
	if strsize == -1 : dialog "jmdic.txt が見つかりません" : end
	// ファイルロード
	notesel buf
	noteload "jmdic.txt"
	// BOMを検出した場合は削除
	BOMDelete buf
	
	gosub *DrawGUI
	
stop

*DrawGUI
	title tt
	sdim dummy
	font "メイリオ", 18, 16
	objmode 2, 1
	pos 0, 0
	input dummy, 500, 34 : objid_input = stat : hobj_input = objinfo(objid_input, 2)
	pos 500, 0 : objsize 140, 34
	button gosub "検索", *btn_search
	pos 0, 34
	mesbox dummy, 640, 480 - 34, 0, 0 : objid_msg = stat : hobj_msg = objinfo(objid_msg, 2)
	onkey gosub *key
return
*key
	objsel -1
	if wparam == 13 && stat == objid_input : gosub *btn_search
return
*btn_search
	
	sdim uni_keyword, 1024*2 + 2
	GetWindowTextW hobj_input, varptr(uni_keyword), 1024
	UnicodeToUTF8 uni_keyword, keyword
	
	sdim out, 1024*100 : num = 0
	SetWindowTextW hobj_msg, varptr(out)
	notesel buf
	repeat notemax
		noteget tmp, cnt
		if keyword == "" || instr_utf8(tmp, 0, keyword) != -1{
			out += tmp + "\n"
			num++
		}
	loop
	if num == 0{
		ShiftJISToUTF8 "検索ヒント:\n別の言い回しで検索すると出る場合があります。\n漢字をひらがなにしたり単漢字で検索しても出る可能性があります。", out
	}
	
	UTF8ToUnicode out, out2
	SetWindowTextW hobj_msg, varptr(out2)
	title tt+" "+num+"件見つけました!"
return