尝试用 Loadlibrary函数加载一个含窗口的DLL,总是以模态形式出现,即在显示DLL窗口的时候无法控件主程序,直到把DLL窗口关闭后主程序才能响应。有没有什么思路可以实现在DLL里封闭非模态DLL窗口?
以下是在网上找到的汇编代码,可以实现这个功能。但很多地方读不懂。高手们能否把它翻译成 Delphi代码 ?
;-----------------
.386
.model flat, stdcall
option casemap :none
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
IDD_DLG1 EQU 1000
IDC_BTN1 EQU 1001
.data?
hInstance dd ?
hWinMain dd ?
szOut db 100 dup(?)
hHandle dd ?
.const
szClassName db 'RemoteClass',0
szCaptionMain db 'RemoteWindow',0
szCalc db '计算器',0
szHandle db '计算器句柄: %lu ',0
.code
_ProcWinMain proc uses ebx edi esi,hWnd,uMsg,wParam,lParam
mov eax,uMsg
.if eax==WM_CLOSE
invoke DestroyWindow,hWnd
invoke PostQuitMessage,NULL
.elseif eax==WM_COMMAND
mov eax,wParam
.if ax==IDC_BTN1
invoke wsprintf,addr szOut,addr szHandle,addr hHandle
invoke SetWindowText,hWinMain,addr szOut
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
_ProcWinMain endp
_WinMain proc uses ebx esi edi _lParam
LOCAL @stMsg:MSG
invoke FindWindow,NULL,addr szCalc
mov hHandle,eax
invoke CreateDialogParam,hInstance,IDD_DLG1,hHandle,addr _ProcWinMain,NULL
mov hWinMain,eax
.while TRUE
invoke GetMessage,addr @stMsg,NULL,0,0
.break .if eax == 0
invoke TranslateMessage,addr @stMsg
invoke DispatchMessage,addr @stMsg
.endw
ret
_WinMain endp
DllEntry proc _hInstance,_dwReason,_dwReserved
local @dwThreadID
.if _dwReason == DLL_PROCESS_ATTACH
push _hInstance
pop hInstance
invoke CreateThread,NULL,0,offset _WinMain,NULL,\
NULL,addr @dwThreadID
invoke CloseHandle,eax
.endif
mov eax,TRUE
ret
DllEntry Endp
End DllEntry
;-------------
感激不尽
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!