外部変形から座標ファイルを読込むと図形を仮表示しながら配置する
ことができます。
@rem 座標ファイル
@echo off
REM #jw
REM #cd
REM #goto %1
REM #hm【座標ファイル】 |丸|四角|
REM #hc【座標ファイル】メニューを選択して下さい。
REM #:1
REM #:2
REM #e
:1
:2
copy jwc_temp.txt jwc_temp.bak
ruby -Ks -x %~f0 %1
start ruby -Ks -x %~f0 zread
REM pause
goto END
#! ruby -Ks
require 'win32ole'
require 'dl/win32'
User32 = DL.dlopen("user32")
def ztemp
wsh = WIN32OLE.new('WScript.Shell')
zfile='HKEY_CURRENT_USER\Software\Jw_cad\jw_win\Folder\ZFILE'
ztemp = wsh.RegRead zfile
ztemp=ztemp+"\\" unless /\\$/=~ ztemp
open(ztemp+"ZTEMP.txt","w"){|f|
if ARGV.include?("1") # 丸
f.puts "ci 0 0 10"
else # 四角
f.puts ["0 0 20 0","20 0 20 20",
"20 20 0 20","0 20 0 0"]
end}
end
def zread
shell = WIN32OLE.new("WScript.Shell")
shell.AppActivate("jw_win");sleep(0.2)
hw=Win32API.new("user32","GetForegroundWindow",[],"L").call
# 座標ファイルコマンド呼び出し
shell.Sendkeys("%AF");sleep(0.2)
# ボタン探し
fw=Win32API.new('user32','FindWindowEx','LLPP','L')
hw=fw.call(hw,0,"AfxControlBar42s","メイン")
hw=fw.call(hw,0,"ToolbarWindow32","条件設定")
hw=fw.call(hw,0,"#32770",0)
hw=fw.call(hw,0,"Button","ファイル読込")
# 左クリックを送る
sm= Win32API.new("user32", "SendMessage",['L']*4,'L')
sleep 0.2
sm.call(hw,0x201,0,0) #0x201:WM_LBUTTONDOWN
sleep 0.2
sm.call(hw,0x202,0,0) #0x202:WM_LBUTTONUP
end
if ARGV.include?("zread")
zread
else
ztemp
end
__END__
:END
「ファイル読込」ボタンのハンドルがうまく捕まえられない場合はこちら。
@rem 座標ファイル
@echo off
REM #jw
REM #cd
REM #goto %1
REM #hm【座標ファイル】 |丸|四角|
REM #hc【座標ファイル】メニューを選択して下さい。
REM #:1
REM #:2
REM #e
:1
:2
copy jwc_temp.txt jwc_temp.bak
ruby -Ks -x %~f0 %1
start ruby -Ks -x %~f0 zread
REM pause
goto END
#! ruby -Ks
require 'win32ole'
require 'dl/win32'
User32 = DL.dlopen("user32")
def ztemp
wsh = WIN32OLE.new('WScript.Shell')
zfile='HKEY_CURRENT_USER\Software\Jw_cad\jw_win\Folder\ZFILE'
ztemp = wsh.RegRead zfile
ztemp=ztemp+"\\" unless /\\$/=~ ztemp
open(ztemp+"ZTEMP.txt","w"){|f|
if ARGV.include?("1") # 丸
f.puts "ci 0 0 10"
else # 四角
f.puts ["0 0 20 0","20 0 20 20",
"20 20 0 20","0 20 0 0"]
end}
end
def get_window_text(hwnd)
buf = "\0" * 500
gWT = Win32API.new('user32','GetWindowTextA','LPI','I')
gWT.call(hwnd,buf, buf.size)
return buf.unpack("A*")[0]
end
def get_class_name(hwnd)
buf = "\0" * 500
gCN= Win32API.new('user32','GetClassName','LPI','I')
gCN.Call(hwnd,buf, buf.size)
return buf.unpack("A*")[0]
end
def puts_handle(hwnd)
puts hwnd.to_s+";"+get_class_name(hwnd)+
";"+get_window_text(hwnd)
end
def zread
shell = WIN32OLE.new("WScript.Shell")
shell.AppActivate("jw_win");sleep(0.2)
hw=Win32API.new("user32","GetForegroundWindow",[],"L").call
# 座標ファイルコマンド呼び出し
sleep(0.2)
shell.Sendkeys("%AF");sleep(0.2)
# ボタン探し
hw2=0
ec= User32['EnumChildWindows', '0LPL']
enum_child_proc = DL.callback('IL'){|hwnd2|
hw2=hwnd2 if "ファイル読込"===get_window_text(hwnd2);-1}
ec.call(hw,enum_child_proc, 0)
sleep 0.2
# 左クリックを送る
shell.AppActivate("jw_win");sleep(0.2)
sm= Win32API.new("user32", "SendMessage",['L']*4,'L')
sleep 0.2
sm.call(hw2,0x201,0,0) #0x201:WM_LBUTTONDOWN
sleep 0.2
sm.call(hw2,0x202,0,0) #0x202:WM_LBUTTONUP
end
if ARGV.include?("zread")
zread
else
ztemp
end
__END__
:END
SendMessage がうまく働かない場合は mouse_event を使ってみましょう。
@rem 座標ファイル
@echo off
REM #jw
REM #cd
REM #goto %1
REM #hm【座標ファイル】 |丸|四角|
REM #hc【座標ファイル】メニューを選択して下さい。
REM #:1
REM #:2
REM #e
:1
:2
copy jwc_temp.txt jwc_temp.bak
ruby -Ks -x %~f0 %1
start ruby -Ks -x %~f0 zread
REM pause
goto END
#! ruby -Ks
require 'win32ole'
require 'dl/win32'
User32 = DL.dlopen("user32")
def ztemp
wsh = WIN32OLE.new('WScript.Shell')
zfile='HKEY_CURRENT_USER\Software\Jw_cad\jw_win\Folder\ZFILE'
ztemp = wsh.RegRead zfile
ztemp=ztemp+"\\" unless /\\$/=~ ztemp
open(ztemp+"ZTEMP.txt","w"){|f|
if ARGV.include?("1") # 丸
f.puts "ci 0 0 10"
else # 四角
f.puts ["0 0 20 0","20 0 20 20",
"20 20 0 20","0 20 0 0"]
end}
end
def zread
shell = WIN32OLE.new("WScript.Shell")
shell.AppActivate("jw_win");sleep(0.2)
# 最小化から復元
hw=Win32API.new("user32","GetForegroundWindow",[],"L").call
Win32API.new("user32", "OpenIcon",'L','V').call(hw);sleep(0.2)
# 座標ファイルコマンド呼び出し
shell.Sendkeys("%AF");sleep(0.2)
# 画面をクリック
require "Win32API"
me = Win32API.new("user32", "mouse_event", ['L'] * 5, 'V')
me.call(2,0,0,0,0)
me.call(4,0,0,0,0)
end
if ARGV.include?("zread")
zread
else
ztemp
end
__END__
:END
2008/05/21 :第2版改訂
2008/09/15 :初版
| 戻る |