ddtest.asm

来自「工欲善其事」· 汇编 代码 · 共 196 行

ASM
196
字号

;*** program demonstrates creation of a directdraw object
;*** no direct draw surface is created here, it just
;*** displays available video modes
;*** written by japheth (mail@japheth.de)

	.386
	.model flat,stdcall
	option casemap :none   ; case sensitive

	 .nolist
	 .nocref
	 include \masm32\include\windows.inc
	 include \masm32\include\kernel32.inc
	 include \masm32\include\user32.inc
	 include \masm32\include\gdi32.inc
	 include \masm32\include\ddraw.inc
	 .list
	 .cref

	 includelib \masm32\lib\kernel32.lib
	 includelib \masm32\lib\user32.lib
	 includelib \masm32\lib\gdi32.lib
	 includelib \masm32\lib\ddraw.lib
	 includelib \masm32\lib\dxguid.lib


	include unknwn.inc
	include ddraw.inc
	include windowsx.inc

;*** string define macro CStr(xxx)

CStr macro y:req,x
local sym
ifnb <x>
x	  segment dword public 'DATA'
else
CONST segment dword public 'DATA'
endif
ifidni <y>,<"">
sym db 0
else
sym db y,0
endif
ifnb <x>
x	  ends
else
CONST ends
endif
	exitm <offset sym>
	endm



IDD_DIALOG1 	 equ			   101
IDC_LIST1		 equ			   1000

	.data

hInstance HINSTANCE 0
hWndLB  HWND 0
pIDD	LPDIRECTDRAW 0
ddsd	DDSURFACEDESC	<>
ddc		DDCAPS	<>
ddc2	DDCAPS	<>

	.code

DebugOut proc pStr:ptr byte
	.if (hWndLB)
		ListBox_AddString hWndLB,pStr
	.else
		invoke OutputDebugString, pStr
		invoke OutputDebugString, CStr(<13,10>)
	.endif
	ret
DebugOut endp

;*** callback proc for mode enumeration

EnumDisplayModesCB proc lpDDSD:LPDDSURFACEDESC,lpVoid:ptr

local szStr[128]:byte

	mov edx,lpDDSD
	invoke wsprintf,addr szStr,CStr("%ux%ux%u"),\
		[edx].DDSURFACEDESC.dwWidth,
		[edx].DDSURFACEDESC.dwHeight,
		[edx].DDSURFACEDESC.ddpfPixelFormat.dwRGBBitCount
	ListBox_AddString hWndLB,addr szStr
	mov eax,DDENUMRET_OK
	ret
EnumDisplayModesCB endp

;*** write listbox content

Init	proc hWnd:HWND

local szStr[260]:byte

	invoke DirectDrawCreate, NULL,addr pIDD, NULL
	.if (eax == S_OK)
		mov ddsd.dwSize,sizeof DDSURFACEDESC
		invoke vf(pIDD,IDirectDraw,GetDisplayMode),addr ddsd
		.if (eax == S_OK)
		.else
			 invoke DebugOut,CStr(<"GetDisplayMode failed",0dh,0ah>)
		.endif
		mov ddc.dwSize,sizeof DDCAPS
		mov ddc2.dwSize,sizeof DDCAPS
		invoke vf(pIDD,IDirectDraw,GetCaps),addr ddc, addr ddc2
		.if (eax == S_OK)
		.else
			invoke DebugOut,CStr(<"GetCaps failed",0dh,0ah>)
		.endif
	.else
		invoke DebugOut,CStr(<"DirectDrawCreate failed",0dh,0ah>)
		ret
	.endif

;---------------------------------------- put information in LB

	invoke wsprintf,addr szStr,CStr("actual Mode=%ux%ux%u"),ddsd.dwWidth,ddsd.dwHeight,\
                                            ddsd.ddpfPixelFormat.dwRGBBitCount
	ListBox_AddString hWndLB,addr szStr
	invoke wsprintf,addr szStr,CStr("dwVidMemTotal=%u"),ddc.dwVidMemTotal
	ListBox_AddString hWndLB,addr szStr
	invoke wsprintf,addr szStr,CStr("dwVidMemFree=%u"),ddc.dwVidMemFree
	ListBox_AddString hWndLB,addr szStr

;---------------------------------------- enumerate available modes

	ListBox_AddString hWndLB,CStr("Modes:")
	invoke vf(pIDD,IDirectDraw,EnumDisplayModes),0,NULL,0,EnumDisplayModesCB
	ret
Init	endp

;*** dialog proc

dialogproc proc export uses ebx hWnd:dword,message:dword,wParam:dword,lParam:dword

local rc:dword

	mov rc,0
	mov eax,message
	.if (eax == WM_INITDIALOG)

		invoke GetDlgItem,hWnd,IDC_LIST1
		mov hWndLB,eax
		invoke Init,hWnd
		mov rc,1 

	.elseif (eax == WM_ACTIVATE)

	.elseif (eax == WM_CLOSE)

        .if (pIDD)
			invoke vf(pIDD,IDirectDraw,Release)
        .endif

	    invoke EndDialog,hWnd,0

	.elseif (eax == WM_COMMAND)

	   mov eax,wParam
	   .if (ax == IDCANCEL)
		  invoke PostMessage,hWnd,WM_CLOSE,0,0
	   .endif

	.endif
	mov eax,rc
	ret
dialogproc endp

;---------- this is a "dialog box" app

WinMain proc export hInst:HINSTANCE,hInstPrev:HINSTANCE,lpszCmdLine:dword,iCmdShow:dword

	mov eax,hInst
	mov hInstance,eax
	invoke DialogBoxParam,hInst,IDD_DIALOG1,0,dialogproc,0
	ret
				
WinMain endp

WinMainCRTStartup proc

	invoke GetModuleHandle,0
	invoke WinMain,eax,0,0,0
	invoke ExitProcess,eax

WinMainCRTStartup endp

	end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?