AutoHotkey スレッド part11

このエントリーをはてなブックマークに追加
330名無しさん@お腹いっぱい。
流行らせるページのDragDrop関数
http://www.autohotkey.com/forum/topic45041.html

これをAutohotkeyLのユニコード版で使うにはどうすればいいんでしょう。
DllCallの中のStrをAStrに変えただけではうまく動作しません。
上記のフォーラムの中で出てきたDragFileA関数も動作しませんでした。

Numputのあたりをいじるようなのですが、DllCallはさっぱりなので宜しければご教授下さい。
331330:2010/10/19(火) 12:56:58 ID:clvatLXW0
自己解決しました。

NumputではなくStrLenでした。全角も1文字と数えるので、全角文字=2文字となる補正すればOKでした。
Dropするファイルのパスを一文字ずつ分解して、正規表現で半角以外だったら補正値+1、
とすることで、かなり力業ですが解決しました。

まったくスマートではないのですが、取り敢えず動きました。
332名無しさん@お腹いっぱい。:2010/10/19(火) 13:24:17 ID:cCnrDLPW0
個人的に移植したやつ。
hwnd : 対象窓, files : 対象ファイル(`n区切り), ptX&ptY : 落とす座標, fNC: 真なら絶対座標/偽なら相対

DropFiles(hwnd, files, ptX=0, ptY=0, fNC=False) {
 static char_type:= A_IsUnicode ? "UShort" : "UChar"
  , char_size := A_IsUnicode ? 2 : 1
  , isUnicode := A_IsUnicode ? 1 : 0
 files := RTrim(files, "`r`n`t ") . "`n`n"
 byte_length := StrLen(files) * char_size
 Loop, Parse, files
  If (A_LoopField = "`n")
   NumPut(0x00, files, (A_Index-1) * char_size, char_type)
 hDrop := DllCall("GlobalAlloc", "UInt", 0x42, "UInt",20 + byte_length, "Ptr")
 p := DllCall("GlobalLock", "Ptr", hDrop)
 NumPut(20 , p + 00, "Int") ; offset
 NumPut(ptX , p + 04, "Int") ; pt.x
 NumPut(ptY , p + 08, "Int") ; pt.y
 NumPut(fNC , p + 12, "Int") ; fNC
 NumPut(isUnicode, p + 16, "Int") ; fWide
 DllCall("RtlMoveMemory", "Ptr", p + 20, "Str", files, "UInt", byte_length)
 DllCall("GlobalUnlock", "Ptr", hDrop)
 PostMessage, WM_DROPFILES := 0x233, hDrop , 0, , ahk_id %hwnd%
}

利用例)
IfWinNotExist, ahk_class Notepad
{
 Run, Notepad
 WinWait, ahk_class Notepad
}
DropFiles(WinExist(), A_ScriptFullPath)