问题描述
我一直在尝试使用 winmm 在我的应用程序中播放视频;我找到了一个 VB 示例并将其翻译成 FASM,但我不知道如何将窗口的句柄放入我尝试发送的字节中;
v1 db 'open 123.avi alias vid1 parent (the handle has to be here) style child',0
v2 db 'put vid1 window at 0 0 100 100',0
v3 db 'Play vid1 notify',0
invoke mciSendString,v1,nullstring,v2,v3,0
我尝试使用 wprintf 但无济于事;有人可以给我一个在应用程序窗口中播放视频的例子吗?
解决方法
终于明白 wsprintf 的工作原理了!下面是一个视频播放器的工作示例:
format PE GUI 4.0
include 'win32a.inc'
section '.text' code readable executable
start:
invoke GetModuleHandle,0
mov [wc.hInstance],eax
invoke LoadIcon,IDI_APPLICATION
mov [wc.hIcon],eax
invoke LoadCursor,IDC_ARROW
mov [wc.hCursor],eax
invoke CreateSolidBrush,0x000000
mov [wc.hbrBackground],eax
invoke RegisterClass,wc
test eax,eax
jz error
invoke CreateWindowEx,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,128,640,480,NULL,[wc.hInstance],NULL
mov [hwnd],eax
test eax,eax
jz error
invoke wsprintf,str_buffer,str_format,[hwnd]
invoke mciSendString,0
invoke mciSendString,str_put,str_play,0
msg_loop:
invoke GetMessage,msg,0
cmp eax,1
jb end_loop
jne msg_loop
invoke TranslateMessage,msg
invoke DispatchMessage,msg
jmp msg_loop
error:
invoke MessageBox,_error,MB_ICONERROR+MB_OK
end_loop:
invoke ExitProcess,[msg.wParam]
proc WindowProc uses ebx esi edi ecx,hwnd,wmsg,wparam,lparam
cmp [wmsg],WM_DESTROY
je .wmdestroy
.defwndproc:
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
jmp .finish
.wmdestroy:
invoke PostQuitMessage,0
xor eax,eax
jmp .finish
.finish:
ret
endp
section '.data' data readable writeable
str_format db "open intro.wmv alias video parent %d style child",0
str_buffer db 256 dup (0)
str_play db "play video notify",0
str_put db 'put video window at 0 0 0 0',0
hwnd dd ?
_class TCHAR 'FASMWIN32',0
_title TCHAR 'Video',0
_error TCHAR 'Error',0
msg MSG
wc WNDCLASS 0,WindowProc,COLOR_BACKGROUND,_class
import winmm,\
mciSendString,'mciSendStringA'
section '.idata' import data readable writeable
library kernel32,'KERNEL32.DLL',\
user32,'USER32.DLL',\
gdi32,'GDI32.DLL',\
advapi32,'ADVAPI32.DLL',\
comctl32,'COMCTL32.DLL',\
winmm,'WINMM.DLL',\
comdlg32,'COMDLG32.DLL',\
shell32,'SHELL32.DLL',\
wsock32,'WSOCK32.DLL'
include 'api/kernel32.inc'
include 'api/user32.inc'
include 'api/gdi32.inc'
include 'api/advapi32.inc'
include 'api/comctl32.inc'
include 'api/comdlg32.inc'
include 'api/shell32.inc'
include 'api/wsock32.inc'