;============================================================ ; 2007/xx/xx ; S.Programs HHX ; 汎用ライブラリ (HSP 3.0) ; http://sprocket.babyblue.jp/ ;============================================================ ;============================================================ ; Windows Timer #module ; winapi #uselib "user32" #func SetTimer "SetTimer" int, int, int, int #func KillTimer "KillTimer" int, int ;-------------------------------------------------- #define global timer_setlabel(%1) oncmd gosub %1, 0x113 ;-------------------------------------------------- #deffunc timer_start SetTimer hwnd, 333, 33, 0 return ;-------------------------------------------------- #deffunc timer_stop KillTimer hwnd, 333 return #global ;============================================================ ; wstrlen ; ダブルバイト対応 文字数カウント ;#uselib "kernel32" ;#cfunc wstrlen "lstrlenW" wptr #module ; winapi #uselib "kernel32" #cfunc MultiByteToWideChar "MultiByteToWideChar" int, int, var, int, int, int ;-------------------------------------------------- #defcfunc wstrlen var v return (MultiByteToWideChar(0, 0, v, -1, 0, 0) - 1) #global ;============================================================ ; BENCH macro #uselib "winmm" #cfunc global d3timer "timeGetTime" #define global B_ST(%1="test") bench_ot = d3timer() : bench_titl = %1 #define global B_EN dialog bench_titl + " - " + (d3timer() - bench_ot) + "ms" #define global B_I1 bench_i = 0 #define global B_I2 bench_iot = d3timer() #define global B_I3 bench_i += d3timer() - bench_iot #define global B_I4 dialog "B_I - " + bench_i + "ms" ;============================================================ ; プロセス間 メモリ共有 モジュール ; 仕様 ; ・保護モード 読み書き可 ; ・最大サイズ 4KB #module ; winapi #uselib "kernel32" #cfunc CreateFileMapping "CreateFileMappingA" int, int, int, int, int, str #cfunc GetLastError "GetLastError" #cfunc MapViewOfFile "MapViewOfFile" int, int, int, int, int #func UnmapViewOfFile "UnmapViewOfFile" sptr #func CloseHandle "CloseHandle" int ;-------------------------------------------------- #deffunc filemap_create str inp hMapobj = CreateFileMapping(-1, 0, 4, 0,4096, inp) lasterr = GetLastError() mapptr = MapViewOfFile(hMapobj, 2, 0, 0, 0) return ;-------------------------------------------------- #deffunc filemap_close UnmapViewOfFile mapptr CloseHandle hMapobj return ;-------------------------------------------------- #defcfunc filemap_viewptr return mapptr ;-------------------------------------------------- #defcfunc filemap_already_exists ; ERROR_ALREADY_EXISTS 183 return (lasterr = 183) #global ;============================================================ ; ステータスバー モジュール #module ; winapi #uselib "comctl32" #func InitCommonControlsEx "InitCommonControlsEx" var #uselib "user32" #func GetWindowRect "GetWindowRect" int, var #func DestroyIcon "DestroyIcon" int #uselib "shell32" #func ExtractIconEx "ExtractIconExA" sptr, sptr, sptr, sptr, sptr ; const #define ctype objhwnd(%1) objinfo(%1, 2) #define STAT_INITED 0xAA55 #const WS_CHILD 0x40000000 #const WS_VISIBLE 0x10000000 #define RECT_LEFT 0 #define RECT_TOP 1 #define RECT_RIGHT 2 #define RECT_BOTTOM 3 ;-------------------------------------------------- #deffunc status_mes int i, str inp if inited = STAT_INITED { a = inp sendmsg objhwnd(id_status), 0x0401, i, varptr(a) ; SB_SETTEXT ; アイコン消去 if icon.i { sendmsg objhwnd(id_status), 0x040F, i, 0 ; SB_SETICON DestroyIcon icon.i icon.i = 0 } } return ;-------------------------------------------------- #deffunc status_icon int i, str fn, int id if inited = STAT_INITED { ; アイコン設定 if icon.i : DestroyIcon icon.i : icon.i = 0 ExtractIconEx fn, id, 0, varptr(icon.i), 1 if icon.i : sendmsg objhwnd(id_status), 0x040F, i, icon.i ; SB_SETICON } return ;-------------------------------------------------- #deffunc status_resize if inited = STAT_INITED { a = ginfo_winx*60/100, ginfo_winx*80/100, -1 ; パーツ位置 (60%, 80%, 100% 固定) sendmsg objhwnd(id_status), 0x0404, 3, varptr(a) ; SB_SETPARTS sendmsg objhwnd(id_status), 0x0005, 0, 0 ; WM_SIZE } return ;-------------------------------------------------- #defcfunc status_height dim a, 4 ; RECT if inited = STAT_INITED { GetWindowRect objhwnd(id_status), a } return (a.RECT_BOTTOM - a.RECT_TOP) ;-------------------------------------------------- #deffunc status_create ; init (4.70 以上の comctl32.dll が必要) a = 8, 0x00000004 ; ICC_BAR_CLASSES InitCommonControlsEx a winobj "msctls_statusbar32", "", 0, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0 id_status = stat dim icon, 3 ; 各パーツのアイコンハンドル格納 inited = STAT_INITED ; 初期化されフラグ status_resize ; パーツ初期化 return #global ; icon sample ; status_icon 0, "explorer.exe", 7 ; (i) ; status_icon 0, "explorer.exe", 8 ; ; status_icon 0, "explorer.exe", 9 ; (X) ; status_icon 0, "shell32.dll", 22 ; ○━ ; status_icon 0, "shell32.dll", 23 ; (?) ;============================================================ ; 文字列キャッシュモジュール (str)key, (str)value ; 参照の古いラインから上書き #module ; config #define CACHE_LINES 16 ;-------------------------------------------------- #deffunc cache_reset sdim slot_key, 64, CACHE_LINES ; キー文字列 sdim slot_val, 64, CACHE_LINES ; データ dim slot_ref, CACHE_LINES ; 参照カウンタ dim hits, 2 ; パフォーマンスカウンタ return ;-------------------------------------------------- #deffunc cache_write str key, var v ; 参照カウンタが最小のライン a を求める m = slot_ref.0 a = 0 repeat CACHE_LINES if slot_ref.cnt < m { m = slot_ref.cnt a = cnt } loop ; ライン a にデータ書き込み slot_key.a = key slot_val.a = v slot_ref.a = pc : pc++ ; 参照カウンタ設定 return ;-------------------------------------------------- #deffunc cache_read str key, var v a = -1 repeat CACHE_LINES if slot_key.cnt = key { a = cnt break } loop if a >= 0 { ; ライン a からデータ読み込み v = slot_val.a slot_ref.a = pc : pc++ ; 参照カウンタ設定 } else { v = "" dialog "無効なキーを参照 : " + key } return ;-------------------------------------------------- #defcfunc cache_exist str key ret = 0 repeat CACHE_LINES if slot_key.cnt = key { ret = 1 break } loop hits.ret++ ; performance counter return ret ;-------------------------------------------------- #defcfunc cache_hitrate if (hits.0 + hits.1) = 0 { return "-" } else { return "hitrate=" + (hits.1 * 100 / (hits.0 + hits.1)) + "%, hit=" + hits.1 + ", miss=" + hits.0 } #global cache_reset ;============================================================ ; HTML 用 文字列関連モジュール ; HTML/URL Enc/Dec (shift-jis) ; Single quotation Escape ; URL auto-link #module ;-------------------------------------------------- #defcfunc URLEnc str inp src = inp dest = "" memexpand dest, strlen(src) * 3 + 1 ; sdim p = 0 repeat strlen(src) c = peek(src, cnt) if (c>='a' & c<='z') { poke dest, p, c : p++ } else:if (c>='A' & c<='Z') { poke dest, p, c : p++ } else:if (c>='0' & c<='9') | c='_' { poke dest, p, c : p++ } else:if c = ' ' { poke dest, p, '+' : p++ } else { a = c >> 4 b = c & 15 if a >= 10 : a += 55 : else : a += '0' if b >= 10 : b += 55 : else : b += '0' poke dest, p, '%' : p++ poke dest, p, a : p++ poke dest, p, b : p++ } loop poke dest, p return dest ;-------------------------------------------------- #defcfunc URLDec str inp src = inp sdim dest, strlen(src) + 1 p = 0 repeat c = peek(src, p) : p++ if c = 0 : break if c = '+' { c = ' ' } else:if c = '%' { a = peek(src, p) : p++ b = peek(src, p) : p++ if a >= 'A' : a -= 55 : else : a -= '0' if b >= 'A' : b -= 55 : else : b -= '0' c = a << 4 | b } poke dest, cnt, c loop return dest ;-------------------------------------------------- #defcfunc HTMLEnc str inp, int sw dest = inp ; speedup patch (99%) if sw = 0 { if instr(dest,0,"&")<0 & instr(dest,0,"<")<0 & instr(dest,0,">")<0 { return dest } } ; HTMLEnc init if he_inited = 0 { sdim he_ssrc, 16, 6 sdim he_sdst, 16, 6 he_ssrc = "&", "<", ">", "\"", " ", "\n" he_sdst = "&", "<", ">", """, " ", "
" he_inited = 1 } ; find and destroy repeat 3 + sw ssrc = he_ssrc(cnt) sdst = he_sdst(cnt) src = dest ; 汎用文字列置換ルーチン (src, dest, ssrc, sdst) p = 0 dest = "" repeat a = instr(src, p, ssrc) if a = -1 { dest += strmid(src, p, strlen(src)) break } dest += strmid(src, p, a) + sdst p += a + strlen(ssrc) loop loop return dest ;-------------------------------------------------- #define global ctype ExHTMLEnc(%1) HTMLEnc(%1, 3) ;-------------------------------------------------- #defcfunc QuoteEsc str inp src = inp sdim dest, strlen(src) * 2 + 1 p = 0 repeat strlen(src) c = peek(src, cnt) if c = 39 { ; ' dest += "\\\'" p += 2 } else:if c = 92 { ; \\ dest += "\\\\" p += 2 } else:if c = 13 { ; \n dest += "\\n" p += 2 } else:if c = 10 { } else:if (c>=0x81 & c<=0x9F) | (c>=0xE0 & c<=0xFC) { ; SJIS patch wpoke dest, p, wpeek(src, cnt) p += 2 continue cnt + 2 } else { poke dest, p, c : p++ } loop return dest /* ;-------------------------------------------------- #defcfunc HTMLALink str inp src = inp dest = "" p = 0 repeat a = instr(src, p, "http://") if a = -1 { dest += strmid(src, p, strlen(src)) break } dest += strmid(src, p, a) p += a getstr buf, src, p, '<' ; URL 区切り文字 if instr(buf,0," ") > 0 : buf = strmid(buf, 0, instr(buf,0," ")) if instr(buf,0,"&") > 0 : buf = strmid(buf, 0, instr(buf,0,"&")) p += strlen(buf) dest += "" + buf + "" loop return dest */ #global ;============================================================ ; HTML 中のアクティブスクリプトに関するキーワードを禁止 #module ; winapi #uselib "user32" #func CharLower "CharLowerA" var ;-------------------------------------------------- #deffunc DoubtAngel var astr sdim dtable, 16, 99 dtable = " 0 { ; load cfg dim savearr, LEN_SAVE bload p1, savearr, LEN_SAVE * 4 ; calc checksum sum = CFGVER repeat LEN_SAVE - 1 sum = sum * 137 + savearr(cnt) loop ; set wp if savearr(POS_CHK) = sum { repeat LEN_ARR v1(cnt) = savearr(cnt + LEN_WP) loop SetWindowPlacement hwnd, savearr ; savearr の前半 0〜(LEN_WP-1) は struct WINDOWPLACEMENT データ Window_top return } } ; set default wp wp = 44, 0, 1, -1, -1, -1, -1, ginfo_dispx*10/100, ginfo_dispy*20/100, ginfo_dispx*80/100, ginfo_dispy*90/100 SetWindowPlacement hwnd, wp return ;-------------------------------------------------- #deffunc Window_save str p1, array v1 ; 設定ファイル名, 設定変数 (int(20)) dim savearr, LEN_SAVE ; Window data savearr = 44 ; WINDOWPLACEMENT.length GetWindowPlacement hwnd, savearr ; savearr の前半 0〜(LEN_WP-1) は struct WINDOWPLACEMENT データ ; Config data repeat LEN_ARR savearr(cnt + LEN_WP) = v1(cnt) loop ; calc checksum sum = CFGVER repeat LEN_SAVE - 1 sum = sum * 137 + savearr(cnt) loop savearr(POS_CHK) = sum ; save cfg bsave p1, savearr, LEN_SAVE * 4 return #global /* ;============================================================ ; const hoge #const GWL_STYLE -16 ; ウインドウスタイル #const GWL_EXSTYLE -20 ; EX ウインドウスタイル #const GCL_HBRBACKGROUND -10 ; 背景ブラシのハンドル #const WS_OVERLAPPED 0x00000000 ; オーバーラップウィン #const WS_TILED 0x00000000 ; // #const WS_POPUP 0x80000000 ; ポップアップウィンド #const WS_CHILD 0x40000000 ; 子ウィンドウを作成し #const WS_CHILDWINDOW 0x40000000 ; // #const WS_MINIMIZE 0x20000000 ; ウィンドウを最小化の #const WS_ICONIC 0x20000000 ; // #const WS_VISIBLE 0x10000000 ; 可視状態のウィンドウ #const WS_DISABLED 0x08000000 ; 無効 (使用不能) なウ #const WS_CLIPSIBLINGS 0x04000000 ; 兄弟関係にある子ウィ #const WS_CLIPCHILDREN 0x02000000 ; 親ウィンドウ内部を描 #const WS_CAPTION 0x00C00000 ; タイトルバーを持つウ #const WS_BORDER 0x00800000 ; 境界線を持つウィンド #const WS_DLGFRAME 0x00400000 ; ダイアログボックスで #const WS_VSCROLL 0x00200000 ; 垂直スクロールバーを #const WS_HSCROLL 0x00100000 ; 水平スクロールバーを #const WS_SYSMENU 0x00080000 ; タイトルバー上にウィ #const WS_THICKFRAME 0x00040000 ; サイズ変更境界を持つ #const WS_SIZEBOX 0x00040000 ; // #const WS_GROUP 0x00020000 ; コントロールグループ #const WS_TABSTOP 0x00010000 ; ユーザーが[Tab]キー #const WS_MINIMIZEBOX 0x00020000 ; 最小化ボタンを持つウ #const WS_MAXIMIZEBOX 0x00010000 ; 最大化ボタンを持つウ #const WS_OVERLAPPEDWINDOW 0x00CF0000 ; WS_OVERLAPPED | WS_C #const WS_POPUPWINDOW 0x80880000 ; WS_POPUP | WS_BORDER #const WS_EX_DLGMODALFRAME 0x00000001 ; 二重の境界線を持つウ #const WS_EX_NOPARENTNOTIFY 0x00000004 ; このスタイルで作成さ #const WS_EX_TOPMOST 0x00000008 ; 最前面ウィンドウを作 #const WS_EX_ACCEPTFILES 0x00000010 ; ドラッグアンドドロッ #const WS_EX_TRANSPARENT 0x00000020 ; 透過ウィンドウを作成 #const WS_EX_MDICHILD 0x00000040 ; MDI 子ウィンドウを作 #const WS_EX_TOOLWINDOW 0x00000080 ; ツールウィンドウを作 #const WS_EX_WINDOWEDGE 0x00000100 ; ウィンドウが盛り上が #const WS_EX_CLIENTEDGE 0x00000200 ; 縁が沈んで見える境界 #const WS_EX_CONTEXTHELP 0x00000400 ; ダイアログボックスの #const WS_EX_RIGHT 0x00001000 ; 右揃えされたプロパテ #const WS_EX_LEFT 0x00000000 ; 左揃えされたプロパテ #const WS_EX_RTLREADING 0x00002000 ; 右から左への読み取り #const WS_EX_LTRREADING 0x00000000 ; 左から右への読み取り #const WS_EX_LEFTSCROLLBAR 0x00004000 ; 垂直スクロールバーが #const WS_EX_RIGHTSCROLLBAR 0x00000000 ; 垂直スクロールバーが #const WS_EX_CONTROLPARENT 0x00010000 ; ユーザーが[Tab]キー #const WS_EX_STATICEDGE 0x00020000 ; ユーザーの入力を受け #const WS_EX_APPWINDOW 0x00040000 ; ウィンドウが最小化さ #const WS_EX_OVERLAPPEDWINDOW 0x00000300 ; WS_EX_WINDOWEDGE と #const WS_EX_PALETTEWINDOW 0x00000188 ; WS_EX_WINDOWEDGE と */