上一次我们介绍了接受一个文件名称的方法,这次介绍如何接受多个的拖拽。UINT DragQueryFile(HDROP hDrop, //指向拖动文件结构的句柄;UINT iFile, //iFile 是以0开始的被托动文件的序号,因为一次可能拖动多个文件。当此参数设为0xFFFFFFFF,则函数返回拖动文件的数量LPTSTR lpszFile,//指向文件名的缓冲区;UINT cch //文件名缓冲区的大小);程序中,令iFile为-1(0xFFFFFFFF),调用DragQueryFile,之后取得拖拽的文件数量;再从0递增逐次取文件名到Buffer中,输出在RichEdit上。;MASMPlus 代码模板 - 普通的 Windows 程序代码.386.Model Flat, StdCallOption Casemap :NoneInclude windows.incInclude user32.incInclude kernel32.incInclude gdi32.incinclude shell32.incincludelib gdi32.libIncludeLib user32.libIncludeLib kernel32.libincludelib shell32.libinclude macro.asmWinMain PROTO :DWORD,:DWORD,:DWORD,:DWORDWndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD.DATAszClassName db "MASMPlus_Class",0szRichEditDLL db "riched20.dll",0szRichEditClass db "RichEdit20A",0szCRCL db 10,0.DATA?hInstance dd ?hwndRichEdit dd ? hRichEdit dd ?szBuffer db 200 dup(0) .CODESTART:invoke LoadLibrary,addr szRichEditDLL ;动态加载包含RichEdit的DLLmov hRichEdit,eax.if eax==0 ;加载失败的话简单提示invoke MessageBox,0,CTXT("Cannot find DLL"),NULL,MB_OK or MB_ICONERROR.endifinvoke GetModuleHandle,NULLmov hInstance,eaxinvoke WinMain,hInstance,NULL,NULL,SW_SHOWDEFAULTinvoke FreeLibrary,hRichEdit ;前面加载了,最后就要释放一次invoke ExitProcess,0WinMain proc hInst:DWORD,hPrevInst:DWORD,CmdLine:DWORD,CmdShow:DWORDLOCAL wc :WNDCLASSEXLOCAL msg :MSGlocal hWnd :HWNDmov wc.cbSize,sizeof WNDCLASSEXmov wc.style,CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOWmov wc.lpfnWndProc,offset WndProcmov wc.cbClsExtra,NULLmov wc.cbWndExtra,NULLpush hInstpop wc.hInstancemov wc.hbrBackground,COLOR_BTNFACE+1mov wc.lpszMenuName,NULLmov wc.lpszClassName,offset szClassNameinvoke LoadIcon,hInst,100mov wc.hIcon,eaxinvoke LoadCursor,NULL,IDC_ARROWmov wc.hCursor,eaxmov wc.hIconSm,0invoke RegisterClassEx, ADDR wcinvoke CreateWindowEx,NULL,ADDR szClassName,CTXT("http://www.aogosoft.com"),WS_OVERLAPPEDWINDOW,\200,200,600,200,NULL,NULL,hInst,NULLmov hWnd,eaxinvoke DragAcceptFiles,hWnd,TRUE ;要接受拖拽invoke ShowWindow,hWnd,SW_SHOWNORMALinvoke UpdateWindow,hWndStartLoop:invoke GetMessage,ADDR msg,NULL,0,0cmp eax, 0je ExitLoopinvoke TranslateMessage, ADDR msginvoke DispatchMessage, ADDR msgjmp StartLoopExitLoop:mov eax,msg.wParamretWinMain endpWndProc proc hWin:DWORD,uMsg:DWORD,wParam :DWORD,lParam :DWORD.if uMsg==WM_CREATEinvoke CreateWindowEx,WS_EX_CLIENTEDGE,addr szRichEditClass,0,WS_CHILD or WS_VISIBLE or ES_MULTILINE or WS_VSCROLL or WS_HSCROLL or ES_NOHIDESEL,\10,10, 570, 140,hWin,2001,hInstance,0mov hwndRichEdit,eax ;创建RichEdit.elseif uMsg == WM_DESTROYinvoke PostQuitMessage,NULL.ELSEIF uMsg==WM_DROPFILESinvoke DragQueryFile,wParam,-1,addr szBuffer,sizeof szBuffermov ecx,eax ;取得拖拽的文件数量xor ebx,ebxNextFileName:push ecxpush ebxinvoke DragQueryFile,wParam,ebx,ADDR szBuffer,sizeof szBufferinvoke SendMessage,hwndRichEdit,EM_SETSEL,-1,-1invoke SendMessage,hwndRichEdit,EM_REPLACESEL,0,addr szBuffer ;取文件名invoke SendMessage,hwndRichEdit,EM_SETSEL,-1,-1invoke SendMessage,hwndRichEdit,EM_REPLACESEL,0,addr szCRCL ;用这样的方法换行pop ebxinc ebxpop ecxloop NextFileName.elseinvoke DefWindowProc,hWin,uMsg,wParam,lParam.endifretWndProc endpEND START