⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rbcircle.asm

📁 拖动鼠标画线
💻 ASM
字号:
;  Rbcircle.asm	 "Demonstrates a rubber-band circle"

;	by	Ron Thomas 
 	
;	Ron_Thom@Compuserve.com 28/5/99	
;---------------------------------------------

.386				; 32 bit when .386 appears before .MODEL
.MODEL FLAT,STDCALL

include windows.inc

include user32.inc
include kernel32.inc
include gdi32.inc

includelib user32.lib
includelib kernel32.lib
includelib gdi32.lib

WinMain		PROTO :DWORD, :DWORD, :DWORD, :SDWORD     	

.data

ClassName db "SimpleWinClass",0
AppName   db "Rubber-Band Circle.   'Press LH button and move mouse to make circle'",0

centreX		DD	?		; Circle centre
centreY		DD	?
circumX		DD	?		; Coords of a circumferential point
circumY		DD	?
radius		DD	?		; computed value

hdc		HDC	?
	
cxClient	DD	?
cyClient	DD	?

bluepen		DD	?			; Pen handle
centreset	db	?			; Flag for circle centre
	
.data?

hInstance HINSTANCE ?
CommandLine LPSTR ?

LOWORD	MACRO 	bigword	;; Retrieves the low word from double word argument

	mov	eax,bigword
	and	eax,0FFFFh	;; Set to low word 
	ENDM

HIWORD	MACRO   bigword	;; Retrieves the high word from double word argument

	mov	ebx,bigword
	shr	ebx,16		;; Shift 16 for high word to set to high word
				
	ENDM
;----------------------------------------------------------------------------
.code
start:
	invoke GetModuleHandle, NULL
	mov    hInstance,eax
	invoke GetCommandLine
        invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
	invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:SDWORD

	LOCAL wc:WNDCLASSEX
	LOCAL msg:MSG
        LOCAL hwnd:HWND
	mov   wc.cbSize,SIZEOF WNDCLASSEX
	mov   wc.style, CS_HREDRAW or CS_VREDRAW
	mov   wc.lpfnWndProc, OFFSET WndProc
	mov   wc.cbClsExtra,NULL
	mov   wc.cbWndExtra,NULL
        push  hInstance
        pop   wc.hInstance
	mov   wc.hbrBackground,COLOR_WINDOW+1 
	mov   wc.lpszMenuName,NULL
	mov   wc.lpszClassName,OFFSET ClassName
        invoke LoadIcon,NULL,IDI_APPLICATION
	mov   wc.hIcon,eax
        mov   wc.hIconSm,0
        invoke LoadCursor,NULL,IDC_ARROW
	mov   wc.hCursor,eax 
        invoke RegisterClassEx, addr wc
        INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
           hInst,NULL
        mov   hwnd,eax
        INVOKE ShowWindow, hwnd,SW_SHOWNORMAL
        INVOKE UpdateWindow, hwnd
        .WHILE TRUE
                INVOKE GetMessage, ADDR msg,NULL,0,0
                .BREAK .IF (!eax)
                INVOKE TranslateMessage, ADDR msg
                INVOKE DispatchMessage, ADDR msg
        .ENDW
        mov     eax,msg.wParam
        ret
WinMain endp

WndProc proc uses ebx, hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

        LOCAL ps:PAINTSTRUCT

	mov   eax,uMsg

	.IF	eax==WM_MOUSEMOVE

	  jmp	fallthr				; Fall through

	.ELSEIF	eax==WM_LBUTTONDOWN

fallthr:
	  .IF	wParam & MK_LBUTTON		; If LH Button down 

	    .IF	centreset			; Do we have the centre yet ?

	      invoke  GetDC, hWnd
	      mov     hdc,eax
	      invoke  GetStockObject, WHITE_PEN	
	      invoke  SelectObject, hdc, eax
	      call    drawcircle		; erase old circle

 	      LOWORD  lParam
	      mov     circumX,eax		; coords of point on circumference
	      HIWORD  lParam
	      mov     circumY,ebx		; 

 	      invoke  SelectObject, hdc, bluepen
	      call    drawcircle		; make new circle visible
	      invoke  ReleaseDC, hWnd, hdc

	    .ELSE
	      LOWORD  lParam
	      mov     centreX,eax		; Set circle centre coords
	      HIWORD  lParam			
	      mov     centreY,ebx		;
	      mov     centreset,TRUE		; We have the circle centre 
	    .ENDIF

	  .ENDIF
 	
	.ELSEIF eax==WM_CREATE

	  finit						; Initialise coprocessor
	  invoke CreatePen, PS_SOLID, 1, 0FF0000h	; Solid, thin & blue 
	  mov	bluepen,eax

 	.ELSEIF eax==WM_SIZE
	
	  LOWORD  lParam
	  mov	cxClient,eax
 	  HIWORD  lParam
	  mov	cyClient,ebx

        .ELSEIF eax==WM_PAINT 	

	  invoke InvalidateRect, hWnd, NULL, TRUE

	  invoke BeginPaint,hWnd, ADDR ps
	  mov    hdc,eax

	  invoke  SelectObject, hdc, bluepen
	  call   drawcircle			; Repaint if resized 
	  
          invoke EndPaint,hWnd, ADDR ps

	.ELSEIF eax==WM_DESTROY

	  invoke DeleteObject, bluepen
          invoke PostQuitMessage,NULL

        .ELSE

          invoke DefWindowProc,hWnd,uMsg,wParam,lParam
          ret
	.ENDIF

        xor    eax,eax
	ret

WndProc endp

drawcircle	PROC		; Use to erase/show the rubber-band circle 

	fild	centreX
	fisub	circumX
	fld	st		; take copy
	fmul			; base squared
	fild	centreY
	fisub	circumY
	fld	st
	fmul			; vertical side squared
	fadd
	fsqrt			; Get hypotenuse
	fistp	radius

	mov	eax,centreX			; Set the bounding coordinates  
	sub	eax,radius			;
	mov	ebx,centreY			;
	sub	ebx,radius			;
	mov	ecx,centreX			;
	add	ecx,radius			;	
	mov	edx,centreY			;
	add	edx,radius			;
	
	invoke Ellipse, hdc, eax,ebx,ecx,edx	; draw the circle		   	 
	 
	  ret

drawcircle	ENDP

        end start

⌨️ 快捷键说明

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