2012年7月5日星期四

WM_DROPFILES and drag.asm


.386
.model flat,stdcall
option casemap:none
include windows.inc

include kernel32.inc
includelib kernel32.lib

include user32.inc
includelib user32.lib

include shell32.inc
includelib shell32.lib

.data
szClassName db "correy",0
szCaptionMain db "made by correy",0
Rich db 'RichEd20.dll',0
szRich db "RichEdit20A",0
szCRCL db 13,10,0 ;换成10,13,0是两个换行。

.data?
hInstance dd ?
hWinMain dd ?
stWndClass WNDCLASSEX <>
stMsg MSG <>
hwndRichEdit dd ?
szBuffer db 260 dup(?) 

.code

liuchunli proc uses ebx edi esi,hWnd,uMsg,wParam,lParam
local p:POINT
local x:dword
local y:dword
.if uMsg == WM_CLOSE
  invoke DestroyWindow,hWinMain
  invoke PostQuitMessage,NULL

.elseif uMsg == WM_LBUTTONDOWN ;就这两行就能实现。
  invoke SendMessage,hWnd,WM_SYSCOMMAND,SC_MOVE or HTCAPTION, 0
  ;或者invoke SendMessage,hWnd,WM_NCLBUTTONDOWN,HTCAPTION,lParam

.ELSEIF uMsg==WM_DROPFILES ;主要的配合在主窗口中加入WS_EX_ACCEPTFILES属性。
  invoke DragQueryFile,wParam,-1,addr szBuffer,sizeof szBuffer ;只取一个文件,第二个参数可以设置为0。KmdManager.exe 就是这样实现的。
  mov ecx,eax ;取得拖拽的文件数量

  xor ebx,ebx
  NextFileName:
  push ecx
  push ebx
  invoke DragQueryFile,wParam,ebx,ADDR szBuffer,sizeof szBuffer

  invoke SendMessage,hwndRichEdit,EM_SETSEL,-1,-1
  invoke SendMessage,hwndRichEdit,EM_REPLACESEL,0,addr szBuffer ;取文件名

  invoke SendMessage,hwndRichEdit,EM_SETSEL,-1,-1
  invoke SendMessage,hwndRichEdit,EM_REPLACESEL,0,addr szCRCL ;用这样的方法换行

  pop ebx
  inc ebx
  pop ecx
  loop NextFileName
  invoke DragFinish,wParam

.elseif uMsg == WM_CREATE
  INVOKE CreateWindowEx,0,addr szRich,0,WS_VISIBLE or ES_MULTILINE or WS_CHILD or WS_VSCROLL, 0,0,610,500,hWnd,0,hInstance,0
  mov hwndRichEdit,eax
  
.else
  invoke DefWindowProc,hWnd,uMsg,wParam,lParam
  ret
.endif
xor eax,eax
ret
liuchunli endp

start:
;invoke InitCommonControls
invoke LoadLibrary,addr Rich

invoke GetModuleHandle,NULL
mov hInstance,eax
mov stWndClass.hInstance,eax

;invoke LoadIcon,hInstance,1
;mov stWndClass.hIcon,eax

invoke LoadCursor,0,32512
mov dword ptr stWndClass+28,eax

mov stWndClass.cbSize,48
mov stWndClass.style,3
mov stWndClass.lpfnWndProc,offset liuchunli
mov stWndClass.hbrBackground,6
mov stWndClass.lpszClassName,offset szClassName

invoke RegisterClassEx,addr stWndClass
invoke CreateWindowEx,200h or WS_EX_ACCEPTFILES,offset szClassName,offset szCaptionMain,0Ca0000h,80000000h,80000000h,710,530,0,0,hInstance,0
mov hWinMain,eax
invoke ShowWindow,hWinMain,1
;invoke UpdateWindow,hWinMain
.while TRUE
invoke GetMessage,addr stMsg,0,0,0
.break .if eax == 0
;invoke TranslateMessage,addr stMsg
invoke DispatchMessage,addr stMsg
.endw
invoke ExitProcess,0
end start
;made at 2011.08.16
;还有个drop呢?

没有评论:

发表评论