/*-------------------------------------- ; http://www.setsuki.com/ ;--------------------------------------- 簡単な説明) [[[ ondrop ]]]  onclick や onkey のような感覚で ドラッグ&ドロップの設定ができます。 [[[ getDropFile ]]]  ドロップされたファイルを取り出します。 [[[ get_comdline ]]]  スペースで区切ってあるコマンドラインを分解し、 notesel、noteget で簡単に取り出せるようにします。  EXEファイルのアイコンの上に ドラッグしたファイルの名前を取り出す時に便利です。 ;-------------------------------------- 使用例) #include "dragdrop.as" //ファイル用の変数を設定 sdim file, 260 //コマンドラインからファイルを取得 get_cmdline file //ドラッグ&ドロップの設定 ondrop gosub *OnDropFile stop *OnDropFile //ドロップされたファイルを取得 getDropFile file return // ファイルをひとつだけ取得 // getDropFile file, 1 // 同じくひとつだけ取得 // get_cmdline file, 1 -------------------------------------*/ #include "kernel32.as" #ifdef __hsp30__ #ifndef __SHELL32__ #define global __SHELL32__ #uselib "SHELL32.DLL" #func global DragAcceptFiles "DragAcceptFiles" sptr,sptr #func global DragQueryFile "DragQueryFile" sptr,sptr,sptr,sptr #func global DragFinish "DragFinish" sptr #endif #endif #ifndef WM_DROPFILES #define global WM_DROPFILES 0x0233 #endif ;-------------------------------------- ; ドラッグ&ドロップの設定 ;-------------------------------------- #define ondrop(%1,%2=hwnd) oncmd %1, WM_DROPFILES : DragAcceptFiles %2, 1 #module dragdrop ;-------------------------------------- ; ドラッグ&ドロップ (ファイル名取得) ;-------------------------------------- #deffunc getDropFile var list, int flag mref stt,64 hdrop = wparam DragQueryFile hdrop, -1, 0, 0 num = stat if( flag != 0 ){ DragQueryFile hdrop, 0, varptr(list), 260 num = 1 } else { if( num > 0 ){ notesel list : sdim file,260 repeat num DragQueryFile hdrop, cnt, varptr(file), 260 noteadd file loop noteunsel } } DragFinish hdrop stt = num return ;-------------------------------------- ; コマンドラインを取得 ;-------------------------------------- #deffunc get_cmdline var list, int flag mref stt,64 hdrop = strlen(dir_cmdline) : sdim cline,hdrop+1 cline = dir_cmdline : sdim file ,260 : num=0 if( hdrop < 1 ) : stt=0 : return if( flag != 0 ) : hdrop=1 notesel list : i = 0 repeat hdrop if( num >= hdrop ): break //ファイル名を取得 if peek(cline,num) == '"' { getstr file,cline,num+1,'"' : num+=strsize+2 } else { getstr file,cline,num ,' ' : num+=strsize } //短いファイル名を正常に変換 #ifdef GetLongPathName GetLongPathName varptr(file),varptr(file),260 #endif noteadd file loop num = notemax : noteunsel : sdim cline,1 if( flag != 0 ) : list = file stt = num return ;-------------------------------------- #global