转载:http://www.aogosoft.com/bbs/view.asp?id=48298&keyword=OLE
作者:鬼龙之舞
.386
.Model Flat, StdCall
Option Casemap :None
;;-------------------------------------------------------
Include windows.inc
Include user32.inc
Include kernel32.inc
IncludeLib user32.lib
IncludeLib kernel32.lib
include ole32.inc
includelib ole32.lib
;-------------------------------------------------------
include oaidl.inc
include shlobj.inc
include shell32.inc
includelib shell32.lib
include gdi32.inc
includelib gdi32.lib
;过程声明
DlgProc proto :DWORD,:DWORD,:DWORD,:DWORD
;-------------------------------------------------------
DEBUG=1
include macro.asm
.const
;常数定义,只使用一次的ID无需定义为常数,这里仅做为例子
DLG_MAIN equ 100
ole_s struct
lpVtbl dd offset ole
nRefCount dd 0
ole_s ends
.data ;数据段
ole dd DropTarget_QueryInterface,\
DropTarget_AddRef,\
DropTarget_Release,\
DropTarget_DragEnter,\
DropTarget_DragOver,\
DropTarget_DragLeave,\
DropTarget_Drop
DropTarget ole_s <>
.data
szAppName db 'IDropTarget DEMO',0
.data?
hInstance dd ?
hWndMain dd ?
hBitmap dd ?
CF_URL dw ?
;-------------------------------------------------------
.CODE
START:
invoke RegisterClipboardFormat,ctext("UniformResourceLocator")
mov CF_URL,ax
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,DLG_MAIN,0,offset DlgProc,0
invoke ExitProcess,0
DlgProc proc uses esi edi ebx hWnd,uMsg,wParam,lParam
local ps:PAINTSTRUCT ,bm:BITMAP ,buf[100]
mov eax,uMsg
.if eax==WM_INITDIALOG
invoke OleInitialize,NULL
invoke RegisterDragDrop,hWnd,addr DropTarget
invoke LoadBitmap,hInstance,101
mov hBitmap,eax
push hWnd
pop hWndMain
.elseif eax==WM_CLOSE
invoke RevokeDragDrop,hWnd
invoke OleUninitialize
invoke DeleteObject,hBitmap
invoke EndDialog,hWnd,FALSE
.elseif eax==WM_PAINT
invoke BeginPaint,hWnd,addr ps
invoke CreateCompatibleDC,0
mov esi,eax
invoke SelectObject,esi,hBitmap
invoke GetObject,hBitmap,addr bm,sizeof bm
invoke BitBlt,ps.hdc,0,0,bm.bmWidth,bm.bmHeight,esi,0,0,SRCCOPY
invoke DeleteDC,esi
invoke EndPaint,hWnd,addr ps
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
DlgProc endp
DropTarget_QueryInterface proc this_,riid,ppvObj
mov eax,S_OK
ret
DropTarget_QueryInterface endp
DropTarget_AddRef proc this_
ret
DropTarget_AddRef endp
DropTarget_Release proc this_
ret
DropTarget_Release endp
DropTarget_DragEnter proc this_,pDataObject,grfKeyState,pt:POINTL,pdwEffect
mov eax,pdwEffect
mov DWORD ptr [eax],DROPEFFECT_COPY or DROPEFFECT_LINK
mov eax,S_OK
ret
DropTarget_DragEnter endp
DropTarget_DragOver proc this_,grfKeyState,pt:POINTL,pdwEffect
mov eax,S_OK
ret
DropTarget_DragOver endp
DropTarget_DragLeave proc this_
mov eax,S_OK
ret
DropTarget_DragLeave endp
DropTarget_Drop proc uses esi edi ebx this_,pDataObject,grfKeyState,pt:POINTL,pdwEffect
local pIEnumFormatETC,pceltFetched,buf[255]:BYTE
local fe:FORMATETC,sm:STGMEDIUM
mov esi,pDataObject
mov esi,[esi]
assume esi:ptr IDataObject
invoke [esi].EnumFormatEtc,pDataObject,1,addr pIEnumFormatETC
mov edi,pIEnumFormatETC
mov edi,[edi]
assume edi:ptr IEnumFORMATETC
invoke [edi].Reset,pIEnumFormatETC
.while TRUE
invoke [edi].Next,pIEnumFormatETC,1,addr fe,NULL
.break .if eax!=S_OK
invoke [esi].GetData,pDataObject,addr fe,addr sm
mov eax,fe.cfFormat
movzx edx,ax
.if ax==CF_TEXT ;文本;网页上的连接
invoke GlobalLock,sm.hData
invoke MessageBox,hWndMain,eax,ctext("TEXT"),32
invoke GlobalUnlock,sm.hData
.elseif ax==CF_URL
invoke GlobalLock,sm.hData
invoke MessageBox,hWndMain,eax,ctext("URL"),32
invoke GlobalUnlock,sm.hData
.elseif ax==CF_HDROP ;文件
xor ebx,ebx
.while TRUE
invoke DragQueryFile,sm.hData,ebx,addr buf,255
.break .if eax==0
invoke MessageBox,hWndMain,addr buf,ctext("FILE"),32
inc ebx
.endw
.elseif ax==CF_DIB
;位图,你可以在“写字板”里粘贴一幅位图,然后拖进来
invoke GlobalLock,sm.hData
mov esi,eax
assume esi:ptr BITMAPINFO
.if hBitmap
invoke DeleteObject,hBitmap
.endif
invoke GetDC,hWndMain
mov edi,eax
invoke CreateDIBitmap,edi,esi,CBM_INIT,addr [esi].bmiColors,esi,DIB_RGB_COLORS
mov hBitmap,eax
invoke ReleaseDC,hWndMain,edi
invoke InvalidateRect,hWndMain,0,0
invoke GlobalUnlock,sm.hData
.else
.continue
.endif
invoke ReleaseStgMedium,addr sm
.break
.endw
mov eax,S_OK
ret
DropTarget_Drop endp
END START
=============================================================
这份代码我编译没通过