Rotating Text Window
I once laid out the program with rotating text, now I had to update it, because with a sharp change in the size of the window, the rotating inscription lost the center of the window and its movements became unpredictable. Now I have corrected this defect
; GUI #
include win64a.inc
.code
WinMain proc
local msg:MSG
xor ebx,ebx
mov esi,IMAGE_BASE
mov edi,offset ClassName
mov ecx,offset FileName
invoke LoadCursorFromFile
mov r12,rax
mov ecx,0FF0000h
invoke CreateSolidBrush
push r12 ;hIconSm
push rdi ;lpszClassName
push rbx ;lpszMenuName
push rax ;hbrBackground
push 10003h ;hCursor
push r12 ;hIcon
push rsi ;hInstance
push rbx ;cbClsExtra & cbWndExtra
pushaddr WndProc ;lpfnWndProc
push sizeof WNDCLASSEX;cbSize & style
invoke RegisterClassEx,esp ;addr WNDCLASSEX
push rbx
push rsi ;rsi=400000h
shr esi,7 ;Special CreateWindow position value CW_USEDEFAULT=8000h
push rbx
push rbx
push rsi
push rsi
push rsi
push rsi
sub esp,20h
invoke CreateWindowEx,0,edi,edi,WS_OVERLAPPEDWINDOW or WS_VISIBLE
;create timer #0 in 50mSec
invoke SetTimer,eax,0,50,0
; +---------------------------+
; | entering the message loop |
; +---------------------------+
lea edi,msg
@@: invoke GetMessage,edi,0,0,0
invoke DispatchMessage,edi
jmp @b
WinMain endp
WndProc proc hwnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
local ps:PAINTSTRUCT
local newFont:qword
local oldFont:qword
local x1:dword
local y1:dword
local hDC:qword
local lpPoint:POINT
mov hwnd,rcx
cmp edx,WM_DESTROY
je wmDESTROY
cmp edx,WM_PAINT
je wmPAINT
cmp edx,WM_SIZE
je wmSIZE
cmp edx,WM_TIMER
je wmTIMER
leave
jmp NtdllDefWindowProc_
wmDESTROY:invoke KillTimer,,0;destroy timer #0
invoke RtlExitUserProcess,0
wmSIZE: mov edx,offset expRect
invoke GetClientRect ;get the size of the client area.
;Dimensions return to a variable expRect
mov eax,expRect.bottom
shr eax,1
mov y,eax ;y-coordinate of the middle of the screen
mov eax,expRect.right
shr eax,1
mov x,eax ;x-coordinate of the middle of the screen
jmp wmBYE
wmTIMER:invoke InvalidateRect,,0,TRUE;redraw the text with the current angle value
finit
jmp wmBYE
wmPAINT:lea edx,ps
invoke BeginPaint
mov hDC,rax
invoke SetTextColor,hDC,32C8C8h;RGB=50,200,200 golden letters
invoke SetBkColor,hDC,0FF0000h;RGB=0,0,255 on a blue background
;create a font with the rotation angle specified in lfEscapement and lfOrientation
pushaddr expFont
push DEFAULT_PITCH or FF_SCRIPT
push rbx ;DEFAULT_QUALITY=0
push rbx ;CLIP_DEFAULT_PRECIS=0
push rbx ;OUT_DEFAULT_PRECIS=0
push OEM_CHARSET
push rbx
push rbx
push rbx
push 400
sub esp,20h
invoke CreateFont,26,12,angle,r8
mov newFont,rax
invoke SelectObject,hDC,rax
mov oldFont,rax
;---------text output
mov qword ptr [rsp+20h],sizeof expTxt;length of string
mov r9d,offset expTxt ;line address
;---------I calculate the position of the beginning of the text
fld angle2;angle of text rotation in radians
fld st(0)
fsincos ;in st(0) the sine of the angle, in st(1) cosine
mov y1,227 ;half of hypotenuse
fimul y1 ;hypotenuse * sin = x
fistp x1
mov edx,x
add edx,x1
fimul y1 ;hypotenuse * cos = y
fistp y1 ;-y
fadd delta ;increased the angle by 1.6 degrees
fst angle2
fmul delta2 ;translate radians to degrees
fsub delta3 ;The angle of the text is lagging behind the rotation angle by 180 degrees
fld st(0)
fmul delta4
fsubp st(1),st(0)
fistp angle ;divide the angle by 360 degrees and remember the remainder
mov r8d,y
sub r8d,y1
invoke TextOut,hDC
invoke DeleteObject,newFont ;delete the new font
invoke SelectObject,hDC,oldFont;return the old font to the system
invoke EndPaint,hwnd,&ps
wmBYE:leave
retn
WndProc endp
;---------------------------------------
ClassName db "Uncle Remus tales:#5 Painting with Rotation Text",0
expTxt db "Win64 assembly with MASM is great and easy!",0
expFont db "script",0
angle dq 0
angle2 dq 3.14159265358979323846264338328
delta dq 0.02792526803190927323077905229;pi*1,6/180
delta2 dq 572.957795130823208767981548141;1800/pi
delta3 dq 1800.0
delta4 dq 0.00027777777777777777777777778;1/3600
hIcon dq ?
FileName db "br_Rabbit3.cur",0
expRect RECT <>
x dd ?
y dd ?
end