Вы находитесь на странице: 1из 40

td_win32asm_170.

asm
;==============================================================================
;
Test Department's WINDOWS 32 BIT x86 ASSEMBLY EXAMPLE's
170
;==============================================================================
;==============================================================================
; ==> Part 170 : Graphic engine, load/save/spot bitmaps, general GDI operations
;-----------------------------------------------------------------------------; Hello,
; nice to meet you again, it takes me a lot of time and nerves but, after some
; experiment's with GDI, here is my source of a rudimentary graphic engine.
; The idea is to create effects on a bitmap using a mask (here spotlight)
; and/or some code (here depending to the mask), all in 24 bit per pixel !
; Special thanks flys to WIN32.HLP, search for "Storing an Image".
; It's a long and hard way in this example, so keep cool.
; On WM_CREATE I check if the display setting is 24 bit per pixel or greater.
; If not I call API "EnumDisplaySettings" searching for the required format.
; I create 3 compatible device context, 3 compatible Bitmap and 3 DIBSection.
; Now I am able to work with the 3 CDC and also with the 3 direct pointer
; to the bitmap data in memory (background, mask and the working area) !
; On WM_DESTROY I kill the active timer, I delete the CDC's and the bitmaps.
; On WM_PAINT I perform a simple bit transfer via API "BitBlt" from the
; working CDC to update the window.
; On WM_COMMAND I call several API's and some of My_Subroutines:
; "Load Bitmap" loads a bitmap from HDD for the background, receiving
;
the BITMAPFILEHEADER + BITMAPINFOHEADER data from the file.
;
I create a compatible device context and a pointer to the bitmap data.
;
Also I center and scale the bitmap, if necessary, to fit the window.
; "Save Bitmap" calculates the BITMAPFILEHEADER + BITMAPINFOHEADER
;
structures for the CURRENT BITMAP IN THE WINDOW !
;
I allocate memory for this structures and the bitmap data.
;
Now I am able to store this data to the HDD as a bitmap file (*.bmp).
; "Spotlight" starts a high resolution multimedia timer.
;
In the timer proc I check the key port and then I manipulate the bitmaps.
;
I copy the spotlight mask to the calculated position in the working area.
;
From the spotlight bytes and the background bytes I calculate new values.
;
How to manipulate the bitmaps is up to you, this is only an example.
; The color format of all RESOURCE bitmaps must be 24 bit per pixel.
; The background color of all RESOURCE bitmaps should be black until you
; change the code. Also this bitmap(s) size must (!) match the window size.
; Your main window size is defined as Xpos_max and Ypos_max.
; For example try another effect mask (320*240 pixel, 24 bits per color).
; To increase / decrease speed you can change ThreadTime, vSpeed, hSpeed.
; If you want use this source the main part is well prepared.
; Natural you need a background bitmap and optional a bitmap mask in RESOURCE.
; The subroutine My_EffectCode is the place to enter your assembler (!) code.
;
; Test Department
td@crahkob.com
;==============================================================================
; Assembler directives
;-----------------------------------------------------------------------------.486
; specifies the processor our program want run on
.Model Flat ,StdCall
; Flat for Win9x (32 Bit), Calling Convention
Page 1

td_win32asm_170.asm
option casemap:none

; case sensitive !

;==============================================================================
; Include all files where API functions resist you want use, set correct path
;-----------------------------------------------------------------------------include windows.inc
includelib kernel32.lib
includelib user32.lib
includelib comdlg32.lib
includelib gdi32.lib
includelib winmm.lib
;==============================================================================
; Declaration of used API functions,take a look into WIN32.HLP and *.inc files
;-----------------------------------------------------------------------------GetLastError
PROTO
GetModuleHandleA
PROTO :DWORD
GetSystemMetrics
PROTO :DWORD
EnumDisplaySettingsA
PROTO :DWORD,:DWORD,:DWORD
ChangeDisplaySettingsA PROTO :DWORD,:DWORD
GetCurrentThread
PROTO
SetThreadPriority
PROTO :DWORD,:DWORD
LoadIconA
PROTO :DWORD,:DWORD
CreateSolidBrush
PROTO :DWORD
LoadCursorA
PROTO :DWORD,:DWORD
RegisterClassExA
PROTO :DWORD
CreateWindowExA
PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,
:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
ShowWindow
PROTO :DWORD,:DWORD
UpdateWindow
PROTO :DWORD
GetMessageA
PROTO :DWORD,:DWORD,:DWORD,:DWORD
TranslateMessage
PROTO :DWORD
DispatchMessageA
PROTO :DWORD
PostQuitMessage
PROTO :DWORD
DestroyWindow
PROTO :DWORD
DefWindowProcA
PROTO :DWORD,:DWORD,:DWORD,:DWORD
ExitProcess
PROTO :DWORD
MessageBoxA
PROTO :DWORD,:DWORD,:DWORD,:DWORD
LoadBitmapA
PROTO :DWORD,:DWORD
GetMenu
PROTO :DWORD
CheckMenuItem
PROTO :DWORD,:DWORD,:DWORD
EnableMenuItem
PROTO :DWORD,:DWORD,:DWORD
InvalidateRect
PROTO :DWORD,:DWORD,:DWORD
FillRect
PROTO :DWORD,:DWORD,:DWORD
GetDeviceCaps
PROTO :DWORD,:DWORD
GetDC
PROTO :DWORD
GetObjectA
PROTO :DWORD,:DWORD,:DWORD
ReleaseDC
PROTO :DWORD,:DWORD
GetDIBits
PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
CreateDIBSection
PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
CreateCompatibleDC
PROTO :DWORD
CreateCompatibleBitmap PROTO :DWORD,:DWORD,:DWORD
SelectObject
PROTO :DWORD,:DWORD
Page 2

DeleteObject
DeleteDC
BeginPaint
SetMapMode
SetStretchBltMode
StretchDIBits

PROTO
PROTO
PROTO
PROTO
PROTO
PROTO

BitBlt

PROTO

EndPaint
timeGetDevCaps
timeSetEvent
timeKillEvent
GetOpenFileNameA
GetSaveFileNameA
CreateFileA
GetFileSize
SetFilePointer
ReadFile
WriteFile
CloseHandle
GlobalAlloc
GlobalFree
GetAsyncKeyState

PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO
PROTO

td_win32asm_170.asm
:DWORD
:DWORD
:DWORD,:DWORD
:DWORD,:DWORD
:DWORD,:DWORD
:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,
:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,
:DWORD,:DWORD,:DWORD
:DWORD,:DWORD
:DWORD,:DWORD
:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
:DWORD
:DWORD
:DWORD
:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
:DWORD,:DWORD
:DWORD,:DWORD,:DWORD,:DWORD
:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
:DWORD
:DWORD,:DWORD
:DWORD
:DWORD

;==============================================================================
; .const
= the constants area starts here, constants are defined and fixed
;-----------------------------------------------------------------------------.const
align 4
; - Parameter MAIN WINDOW CallBack Procedure ( API=RegisterClassExA ) WP1_CallBack
equ [ebp+4]
;return address
WP1_hWnd
equ [ebp+8]
;handle of window who receives message
WP1_uMsg
equ [ebp+12]
;the message number
WP1_wParam
equ [ebp+16]
;extra info about the message
WP1_lParam
equ [ebp+20]
;extra info about the message
;==============================================================================
; .Data
= the data area starts here, datas are defined but not fixed
;
MASM converts real4, real8 values into FPU/IEEE standard.
;-----------------------------------------------------------------------------.Data
align 4
NameBMP_spotlight
db "Spotlight",0
NameBMP_picture
db "Picture",0
IconName
db "TDIcon",0
;icon name in rc file
MenuName
db "TDMenu",0
;menu name in rc file
Class
db "TDWinClass",0
;name of window class
WindowName
db "Test Department - http://surf.to/TestD",0
MB0_Titel
db "Error",0
MB0_Text
db "Unable to switch display setting to 24 "
db "Bits per pixel (True Color).",13,10
db "Continue anyway ?",0
Page 3

MB1_Text
MB2_Text
MB10_Titel
MB10_Text
FileFilter
FileDefExt
FileName
LoadFileTitel
SaveFileTitel
; - BITMAPINFOHEADER align 4
temp_BitMapInfoHeader

db
db
db
db
db
db
db
db
db

td_win32asm_170.asm
"Error while loading / saving File.",0
"This program do not work in 256 color mode.",0
"Test Department",0
"Welcome to my small graphic engine ...",0
"Bitmap Files (*.bmp)",0,"*.bmp",0,0 ;file filter
"bmp",0h
104h dup(0),0
;buffer filename
"Load Bitmap in any color format",0 ;titel
"Save Bitmap in 24/32 Bit Colors",0 ;titel

dd
dd
dd
dw
dw
dd
dd
dd
dd
dd
dd

028h
140h
0F0h
001h
018h
0h
0h
0h
0h
0h
0h

;biSize
;biWidth
;biHeight
;biPlanes
;biBitCount
;biCompression
;biSizeImage
;biXPelsPerMeter
;biYPelsPerMeter
;biClrUsed
;biClrImportant

; - Various parameter align 4


ThreadTime
dd 40
WM_PAINT_proceed
dd 0h
temp
dd 0h

;time for effect thread in ms


;WM_PAINT flag
;temporary var

; - Screen parameter ModeNum


ScreenBpp
ScreenWidth
ScreenHeight
Xpos_org
Ypos_org
Xpos_max
Ypos_max

;graphics index
;bits per pixel
;width of screen
;height of screen
;X orgin point window
;Y orgin point window
;max. window width
;max. window height

dd
dd
dd
dd
dd
dd
dd
dd

0
0
0
0
0
0
320
240

; - Settings parameter AutoMode


dd 1h
TP1_Mode
dd 0h
; - Spotlight parameter sizeBMP
dd 0
Xspeed
dd 4
Yspeed
dd 4
OffXpos_work
dd 0
OffYpos_work
dd 0
OffXpos_light
dd 0
OffYpos_light
dd 0
OffXpos_max
dd 0

;flag, default automode on


;effect number-timer on/off
;Xpos_max*Ypos_max*colorbytes(3)-3
;horizontal speed
;vertical speed
;calculated position for spotlight
;
;
;
;calculated width and height
Page 4

td_win32asm_170.asm
;
;pointer to spotlight table
;77=right,72=up,75=left,80=down
;parameter=keyboard code (MAKECODE)
77,77,77,77,77,77,77,77,77,77,77,77,77,77,77
72,72,72,72,72,72,72,72,72,72,72,72,72,72,72
75,75,75,75,75,75,75,75,75,75,75,75,75,75,75
75,75,75,75,75,75,75,75,75,75,75,75,75,75,75
75,75,75,75,75,75,75,75,75,75,75,75,75,75,75
80,80,80,80,80,80,80,80,80,80,80,80,80,80,80
80,80,80,80,80,80,80,80,80,80,80,80,80,80,80
77,77,77,77,77,77,77,77,77,77,77,77,77,77,77
77,77,77,77,77,77,77,77,77,77,77,77,77,77,77
77,77,77,77,77,77,77,77,77,77,77,77,77,77,77
72,72,72,72,72,72,72,72,72,72,72,72,72,72,72
75,75,75,75,75,75,75,75,75,75,75,75,75,75,75

OffYpos_max
Index_spotlight

dd 0
dd 0

Table_spotlight

db
db
db
db
db
db
db
db
db
db
db
db

;==============================================================================
; .Data?
= the data? area starts here, not defined and not fixed
;-----------------------------------------------------------------------------.data?
align 4
handleWindow
dd ?
;handle, main window
handleMenu
dd ?
;handle, menu bar
handleDC
dd ?
;handle, main device context
handleBMP
dd ?
;handle, bitmap
handleCDC_light
dd ?
;handle compatible device context
pointerBMP_light
dd ?
;pointer to bitmap data in CDC
handleBMP_light
dd ?
;handle, bitmap
handleCDC_back
dd ?
;handle, compatible device context
pointerBMP_back
dd ?
;pointer to bitmap data in CDC
handleBMP_back
dd ?
;handle, bitmap
handleCDC_work
dd ?
;handle, compatible device context
pointerBMP_work
dd ?
;pointer to bitmap data in CDC
handleBMP_work
dd ?
;handle, bitmap
handleFile
dd ?
;handle, bitmap file
totalBytesFile
dd ?
;total # of bytes in *.bmp File
pGlobalMemFile
dd ?
;pointer to global memory
FileBytesReturn
dd ?
;bytes reading / writing file
pointerBMI_temp
dd ?
pointerDAT_temp
dd ?
biHeight_temp
dd ?
biWidth_temp
dd ?
YposOrg_temp
dd ?
XposOrg_temp
dd ?
Height_temp
dd ?
Width_temp
dd ?
timerevent1
dd ?
;handle of timer event 1
hdcSrc
dd ?
;handle of source device context
hdcDest
dd ?
;handle of dest. device context
handleOld
dd ?
;handle, old object
align 4
Page 5

td_win32asm_170.asm
; - DEVMODE Structure ( API=EnumDisplaySettings / ChangeDisplaySettings ) dmDeviceName
db 32 dup (?)
dmSpecVersion
dw ?
dmDriverVersion
dw ?
dmSize
dw ?
dmDriverExtra
dw ?
dmFields
dd ?
dmOrientation
dw ?
dmPaperSize
dw ?
dmPaperLength
dw ?
dmPaperWidth
dw ?
dmScale
dw ?
dmCopies
dw ?
dmDefaultSource
dw ?
dmPrintQuality
dw ?
dmColor
dw ?
dmDuplex
dw ?
dmYResolution
dw ?
dmTTOption
dw ?
dmCollate
dw ?
dmFormName
db 32 dup (?)
dmLogPixels
dw ?
dmBitsPerPel
dd ?
dmPelsWidth
dd ?
dmPelsHeight
dd ?
dmDisplayFlags
dd ?
dmDisplayFrequency
dd ?
dmICMMethod
dd ?
;Windows 95 only
dmICMIntent
dd ?
;Windows 95 only
dmMediaType
dd ?
;Windows 95 only
dmDitherType
dd ?
;Windows 95 only
dmReserved1
dd ?
;Windows 95 only
dmReserved2
dd ?
;Windows 95 only
align 4
; - WndClassEx Structure ( API=RegisterClassExA ) cbSize
dd ?
;size in bytes of this structure
style
dd ?
;window style
lpfnWndProc
dd ?
;address of user proc function
cbclsExtra
dd ?
;extra bytes to allocate set to 0
cbWndExtra
dd ?
;extra bytes class directive, rc file
hInstance
dd ?
;program handle(API=GetModuleHandleA)
hIcon
dd ?
;handle of icon (API=LoadIconA)
hcursor
dd ?
;handle of cursor (API=LoadCursor)
hbrBackground
dd ?
;background color, 0=transparent
lpszMenuName
dd ?
;name of menu class in resource file
lpszClassName
dd ?
;name of windows this window class
hIconSm
dd ?
;iconhandle 0=search in resource file
align 4
; - Msg Structure ( API=GetMessageA ) - member POINT = POINT structure
hWnd
dd ?
;handle of window who receives message
message
dd ?
;the message number
Page 6

wParam
lParam
time
xpt
ypt

dd
dd
dd
dd
dd

?
?
?
?
?

td_win32asm_170.asm
;extra info about the message
;extra info about the message
;time the message was posted
;cursor x-position, POINT struc
;cursor x-position, POINT struc

align 4
; - TIMECAPS Structure ( API=timeGetDevCaps ) wPeriodMin
dd ?
;TIMER minimum supported resolution
wPeriodMax
dd ?
;TIMER maximum supported resolution
align 4
; - Paint Structure ( API=BeginPaint ) - member rcPaint = RECT structure
hdc
dd ?
;id, display DC used for painting
fErase
dd ?
;must background must be erased
rcPaint_left
dd ?
;RECT,x-coordinate upper-left corner
rcPaint_top
dd ?
;RECT,y-coordinate upper-left corner
rcPaint_right
dd ?
;RECT,x-coordinate lower-right corner
rcPaint_bottom
dd ?
;RECT,y-coordinate lower-right corner
fRestore
dd ?
;reserved, used by Windows
fIncUpdate
dd ?
;reserved, used by Windows
rgbReserved
db 20h dup (?) ;reserved, used by Windows
align 4
; - OPENFILENAME Structure
lStructSize
dd
hWndOwner
dd
hInstance1
dd
lpstrFilter
dd
lpstrCustomFilter
dd
nMaxCustFilter
dd
nFilterIndex
dd
lpstrFile
dd
nMaxFile
dd
lpstrFileTitle
dd
nMaxFileTitle
dd
lpstrInitialDir
dd
lpstrTitle
dd
Flags
dd
nFileOffset
dw
nFileExtension
dw
lpstrDefExt
dd
lCustData
dd
lpfnHook
dd
lpTemplateName
dd

( API=GetOpenFileNameA / GetSaveFileNameA ) ?
;the length in bytes of structure
?
;handle of window that owns dialog box
?
;handle, our program handle
?
;pointer to string + filter
?
;pointer to user defined filter
?
;size bytes/characters of above
?
;filter index of lpstrFilter
?
;pointer initialize filename, 0=no
?
;size bytes/characters of above
?
;pointer title of the selected file
?
;size of the lpstrFileTitle buffer
?
;pointer init file dir,0=default
?
;pointer title of the box
?
;the dialog box creation flags
?
;offset filename in string lpstrFile
?
;offset extension in string lpstrFile
?
;pointer to default extension of file
?
;?
?
;used if flag is OFN_ENABLETEMPLATE
?
;used if flag is OFN_ENABLETEMPLATE

align 4
; - BITMAP Structure ( API=GetObject ) bmType
dd ?
;specifies the bitmap type
bmWidth
dd ?
;specifies the width, in pixels
bmHeight
dd ?
;specifies the height, in pixels
bmWidthBytes
dd ?
;specifies # of bytes in each scan line
bmPlanes
dw ?
;specifies the count of color planes
Page 7

td_win32asm_170.asm
;# bits to indicate the color of pixel
;points to bit values for the bitmap

bmBitsPixel
bmBits

dw ?
dd ?

align 4
; - BITMAPFILEHEADER bfType
bfSize
bfReserved1
bfReserved2
bfOffBits

dw
dd
dw
dw
dd

?
?
?
?
?

;specifies
;the size,
;reserved,
;reserved,
;offset in
;structure

align 4
; - BITMAPINFOHEADER biSize
biWidth
biHeight
biPlanes
biBitCount
biCompression
biSizeImage
biXPelsPerMeter
biYPelsPerMeter
biClrUsed
biClrImportant

dd
dd
dd
dw
dw
dd
dd
dd
dd
dd
dd

?
?
?
?
?
?
?
?
?
?
?

;# of bytes required by the structure


;the width of the bitmap, in pixels
;height of the bitmap, in pixels
;# of planes for target device, must 1
;# bits per pixel, 1,4,8,16,24 or 32
;type of compression bottom-up bitmap
;the size, in bytes, of the image
;horiz. resolution, in pixels per meter
;verti. resolution, in pixels per meter
;# of color indices in the color table
;# of color indices that are important

the file type, must be BM


in bytes, of the bitmap file
must be zero
must be zero
bytes, from BITMAPFILEHEADER
to the bitmap bit

;==============================================================================
; .CODE = our code area starts here
Main = label of our program code
;-----------------------------------------------------------------------------align 4
.Code
Main:
;==============================================================================
; Always get your program ID first (API=GetModuleHandleA)
;-----------------------------------------------------------------------------push
0h
;lpModuleHandle, 0=get program handle
call
GetModuleHandleA
;- API Function mov
hInstance,eax
;return value in eax=handle of program
;==============================================================================
; Init the Floating Point Unit and the bitmap size in bytes.
;-----------------------------------------------------------------------------finit
;init FPU
mov
eax,Xpos_max
;window width
mov
OffXpos_max,eax
;
mov
ebx,Ypos_max
;window height
mov
OffYpos_max,ebx
;
mov
ecx,3h
;24 bit per pixel (3 byte)
mul
ebx
;mul, Xpos_max*Ypos_max
mul
ecx
;mul, eax*3
sub
eax,3h
;sub, eax-3
mov
sizeBMP,eax
;store result
Page 8

td_win32asm_170.asm
;==============================================================================
; The GetCurrentThread function returns a pseudohandle for the current thread.
;-----------------------------------------------------------------------------call
GetCurrentThread
;- API Function ;==============================================================================
; SetThreadPriority function sets the priority value for the specified thread.
;-----------------------------------------------------------------------------push
2h
;nPriority, thread priority level
;THREAD_PRIORITY_HIGHEST = 2h
push
eax
;hThread, handle to the thread
call
SetThreadPriority
;- API Function cmp
eax,0h
;ERROR ?
je
ExitPrg
;
;==============================================================================
; The API function "RegisterClassExA" registers a window class.
; This API needs a "WNDCLASSEX" structure so we fill it with correct values.
;-----------------------------------------------------------------------------mov
cbSize,30h
;size in bytes of WNDCLASSEX structure
mov
style,3h
;window style
mov
lpfnWndProc,OFFSET WP1
;address of user lpfnWndProc function
mov
cbclsExtra,0h
;extra bytes to allocate set to 0
mov
cbWndExtra,0h
;class directive in rc file
mov
lpszMenuName,OFFSET MenuName;menu name in resource file,0=no menu
mov
lpszClassName,OFFSET Class ;name of windows class
mov
hIconSm,0h
;iconhandle 0=search in rc file
;-----------------------------------------------------------------------------; API "CreateSolidBrush" creates a logical brush with the specified solid color
;-----------------------------------------------------------------------------push
00000000h
;crColor, brush color value RGB
call
CreateSolidBrush
;- API Function mov
hbrBackground,eax
;handle brush, background color
;-----------------------------------------------------------------------------; API "LoadIconA" loads an icon defined in the resource file and stores the
; handle in the "WNDCLASSEX" structure
;-----------------------------------------------------------------------------push
OFFSET IconName
;icon-string or icon resource id
push
hInstance
;our program handle
call
LoadIconA
;- API Function mov
hIcon,eax
;store handle of newly loaded icon
;-----------------------------------------------------------------------------; API "LoadCursorA" loads a default system cursor, in this case we must set
; hInstance to 0 and lpCursorName to a default system cursor value, here 32512
; Then we store the cursor handle in the "WNDCLASSEX" structure
;-----------------------------------------------------------------------------push
32512
;lpCursorName, default value in dezimal
push
0h
;hInstance, 0=default system cursor
call
LoadCursorA
;- API Function mov
hcursor,eax
;store handle of the cursor
;-----------------------------------------------------------------------------; Now, after filled the "WNDCLASSEX" structure we call API "RegisterClassEx"
Page 9

td_win32asm_170.asm
;-----------------------------------------------------------------------------push
OFFSET cbSize
;pointer to WNDCLASSEX structure
call
RegisterClassExA
;- API Function ;==============================================================================
; API "CreateWindowExA" creates an overlapped, pop-up, or child window with an
; extended style. The return value in EAX is the handle of the new window.
; This API sends a WM_CREATE message to the window procedure (WP1).
;-----------------------------------------------------------------------------push
0h
;lpParam, extra pointer data 0=no data
push
hInstance
;hInstance, handle of our program
push
0h
;hMenu, handle window menu 0=class menu
push
0h
;hWndParent, handle parent window 0=no
mov
eax,Ypos_max
add
eax,48
push
eax
;intnHeight, window height pixel
mov
eax,Xpos_max
add
eax,10
push
eax
;intnWidth, window width pixel
push
10h
;inty, vertical position window
push
80h
;intx, horizontal position window
push
04CA0000h
;dwStyle, look into WIN32.HLP
push
OFFSET WindowName
;lpWindowName, pointer to window name
push
OFFSET Class
;lpClassName, pointer to class name
push
0300h
;dwExStyle, extra window style 0=no
call
CreateWindowExA
;- API Function mov
hWnd,eax
;hwnd,return value=handle of window
;-----------------------------------------------------------------------------; API "MessageBoxA" creates a message box, we can only click OK
;-----------------------------------------------------------------------------push
0h
;uType, style, 0=MB_OK Button
push
OFFSET MB10_Titel
;lpCaption, pointer message box title
push
OFFSET MB10_Text
;lpText, pointer message box text
push
hWnd
;handle of owner window 0=no owner
call
MessageBoxA
;- API Function ;==============================================================================
; API "ShowWindow" function sets the specified window's show state.
;-----------------------------------------------------------------------------push
1h
;nCmdShow, show state 1=SW_SHOWNORMAL
push
hWnd
;hwnd, handle of window
call
ShowWindow
;- API Function ;==============================================================================
; API "UpdateWindow" updates the area of the specified window by sending a
; WM_PAINT message to the window if the window's update region is not empty.
;-----------------------------------------------------------------------------push
hWnd
;hwnd, handle of window
call
UpdateWindow
;- API Function LoopGetMessage:
;==============================================================================
Page 10

td_win32asm_170.asm
; API "GetMessageA" retrieves a message + places it in the specified structure.
;-----------------------------------------------------------------------------push
0h
;wMsgFilterMax, highest message value
push
0h
;wMsgFilterMin, lowest message value
push
0h
;hWnd, handle of window who gets msg.
push
OFFSET hWnd
;lpMsg, pointer to MSG structure
call
GetMessageA
;- API Function cmp
eax,0h
;check if return value=0 (exit)
je
ExitPrg
;if return value is 0 goto LABEL
;==============================================================================
; API "TranslateMessage" translates virtual-key messages in character messages
;-----------------------------------------------------------------------------push
OFFSET hWnd
;lpMSG, pointer to msg structure
call
TranslateMessage
;- API Function - keyboard code
;==============================================================================
; API "DispatchMessageA" function dispatches a message to a window procedure.
;-----------------------------------------------------------------------------push
OFFSET hWnd
;lpMSG, pointer to msg structure
call
DispatchMessageA
;- API Function jmp
LoopGetMessage
;check for message again, goto LABEL
ExitPrg:
;==============================================================================
; Next we terminate our program (API=ExitProcess)
;-----------------------------------------------------------------------------push
hInstance
;push our programm handle to exit
call
ExitProcess
;- API Function ;##############################################################################
; The Window Procedure (API=RegisterClassExA) for this registered window.
;-----------------------------------------------------------------------------WP1:
push
ebp
;create stack frame
mov
ebp,esp
;
pushad
;push all register to the stack
mov
eax,WP1_uMsg
;move the message number to eax
;==============================================================================
; WM_CREATE (value=01h) message received ?
; Creating the BITMAPFILEHEADER and the BITMAPINFOHEADER from the resource.
; Also creating a pointer to the bitmap bits.
;-----------------------------------------------------------------------------WP1_uMsg_01h:
cmp
eax,1h
;check if WM_CREATE message recieved
jne
WP1_uMsg_02h
;if not goto LABEL
;---------mov
eax,OFFSET temp_BitMapInfoHeader
add
eax,4
mov
ebx,Xpos_max
mov
[eax],ebx
;our bitmap / screen width
;---------Page 11

td_win32asm_170.asm
mov
eax,OFFSET temp_BitMapInfoHeader
add
eax,8
mov
ebx,Ypos_max
mov
[eax],ebx
;our bitmap / screen height
;---------call
My_WM_CREATE
;- Subroutine jmp
WP1_return
;==============================================================================
; WM_DESTROY (value=02h) message received ?
;-----------------------------------------------------------------------------WP1_uMsg_02h:
cmp
eax,2h
;check if value=2h (WM_DESTROY)
jne
WP1_uMsg_0Fh
;if not 2h go to LABEL
call
My_CleanSystem
;- SubRoutine ;-----------------------------------------------------------------------------; API "PostQuitMessage" indicates to Windows a request to terminate
;-----------------------------------------------------------------------------push
0h
;nExitCode, exit code=wParam
call
PostQuitMessage
;- API Function popad
;pop all register back from stack
xor
eax,eax
;set eax to 0 to exit our program
mov
esp,ebp
;delete stack frame
pop
ebp
;
ret
10h
;return and clear stack
;==============================================================================
; WM_PAINT (value=0Fh) message, used to repaint the window area
;-----------------------------------------------------------------------------WP1_uMsg_0Fh:
cmp
eax,0Fh
;check if WM_PAINT message recieved
jne
WP1_uMsg_111h
;if not goto label
;-----------------------------------------------------------------------------; API "BeginPaint" prepares the specified window for painting and fills a
; PAINTSTRUCT structure with information about the painting
;-----------------------------------------------------------------------------push
OFFSET hdc
;lpPaint, pointer to PAINTSTRUCT
push
WP1_hWnd
;hwnd, handle of the window
call
BeginPaint
;- API Function mov
hdcDest,eax
;handle, display device (DC)=dest.
;-----------------------------------------------------------------------------; API "BitBlt" performs a bit-block transfer of the color data corresponding
; to a rectangle of pixels from the specified source device context into a
; destination device context.
;-----------------------------------------------------------------------------push
0CC0020h
;dwRop, SRCCOPY
push
Ypos_org
;nYSrc, y=src. rect. up-left corner
push
Xpos_org
;nXSrc, x=src. rect. up-left corner
push
handleCDC_work
;hdcSrc, handle of source device
push
Ypos_max
;nHeight, height of dest. rect.
push
Xpos_max
;nWidth, width of dest. rect.
push
Ypos_org
;nYDest, y=dest. rect. up-left corner
push
Xpos_org
;nXDest, x=dest. rect. up-left corner
Page 12

td_win32asm_170.asm
push
hdcDest
;hdcDest, handle destination device
call
BitBlt
;- API Function ;-----------------------------------------------------------------------------; API "EndPaint" marks the end of painting in the given window.
; This function is required for each call to the BeginPaint function, but only
; after painting is complete.
;-----------------------------------------------------------------------------push
OFFSET hdc
;lpPaint, pointer PAINTSTRUCT
push
WP1_hWnd
;hwnd, handle of the window
call
EndPaint
;- API Function mov
WM_PAINT_proceed,1h
;set flag, WM_PAINT is proceed !
jmp
WP1_return
;==============================================================================
; WM_COMMAND (value=111h) message recieved ?
;-----------------------------------------------------------------------------WP1_uMsg_111h:
cmp
eax,111h
;check if WM_COMMAND message recieved
jne
WP1_uMsg_112h
;if not goto label
mov
eax,WP1_wParam
;extra info about the message in ax
WP1_uMsg_wParam_10h:
cmp
ax,10h
;"Load Bitmap" clicked ?
jne
WP1_uMsg_wParam_12h
;
call
My_EffectCodeAll_Off
;- Subroutine call
My_LoadBMP
;- Subroutine call
My_RestoreScreen
;- Subroutine jmp
WP1_return
WP1_uMsg_wParam_12h:
cmp
ax,12h
jne
WP1_uMsg_wParam_20h
call
My_EffectCodeAll_Off
call
My_SaveBMP
call
My_RestoreScreen
jmp
WP1_return

;"Save Bitmap" clicked ?


;
;- Subroutine ;- Subroutine ;- Subroutine -

WP1_uMsg_wParam_20h:
cmp
ax,20h
jne
WP1_uMsg_wParam_21h
call
My_EffectCodeAll_Off
call
My_RestoreScreen
jmp
WP1_return

;"Effect off" clicked ?


;
;- Subroutine ;- Subroutine -

WP1_uMsg_wParam_21h:
cmp
ax,21h
jne
WP1_uMsg_wParam_22h
call
My_EffectCode001_On
jmp
WP1_return

;"Spotlight 1" clicked ?


;
;- Subroutine -

WP1_uMsg_wParam_22h:
cmp
ax,22h
jne
WP1_uMsg_wParam_A0h
call
My_EffectCode002_On

;"Spotlight 2" clicked ?


;
;- Subroutine Page 13

td_win32asm_170.asm
jmp

WP1_return

WP1_uMsg_wParam_A0h:
cmp
ax,0A0h
jne
WP1_uMsg_wParam_A1h
call
My_AutoMode
jmp
WP1_return

;"AutoMode" clicked ?
;
;- Subroutine -

WP1_uMsg_wParam_A1h:
cmp
ax,0A1h
jne
WP1_return
call
My_Keyboard
jmp
WP1_return

;"Keyboard" clicked ?
;
;- Subroutine -

;==============================================================================
; WM_SYSCOMMAND (value=112h) message recieved ?
;-----------------------------------------------------------------------------WP1_uMsg_112h:
cmp
eax,112h
;check if WM_COMMAND message recieved
jne
WP1_return
;if not goto label
mov
eax,WP1_wParam
;extra info about the message
cmp
eax,0F060h
;SC_CLOSE=0F060h received ?
jne
WP1_return
;
call
My_CleanSystem
;- SubRoutine jmp
WP1_return
;==============================================================================
; API "DefWindowProcA" calls the window procedure to provide default processing
; for any window messages that an application does not process.
; This function ensures that every message is processed.
; It is called with the same parameters received by the window procedure.
;-----------------------------------------------------------------------------WP1_return:
popad
;pop all register from stack
push
WP1_lParam
;extra info about the message
push
WP1_wParam
;extra info about the message
push
WP1_uMsg
;the message number
push
WP1_hWnd
;handle of window who receives message
call
DefWindowProcA
;- API Function mov
esp,ebp
;delete stack frame
pop
ebp
;
ret
10h
;return and clear stack
;##############################################################################
;##############################################################################
; HIGH RESOLUTION TIMER procedure (Mmedia.hlp) !
;-----------------------------------------------------------------------------TP1:
pushad
;save all register
cmp
jne

WM_PAINT_proceed,1h
TP1_return

;check if last WM_PAINT msg. is proceed


;if not 1h nothing to do, TIME CRITICAL
Page 14

td_win32asm_170.asm
cmp
AutoMode,1h
;check AutoMode flag
je
Table_Spotlight
;skip AutoMode
;-----------------------------------------------------------------------------; API "GetAsyncKeyState" determines whether a key is up or down at the time the
; function is called ...
;-----------------------------------------------------------------------------push
26h
;vKey, virtual-key code, VK_UP=26h
call
GetAsyncKeyState
;- API Function shr
eax,1Fh
cmp
eax,1h
jne
LeftArrow
add
eax,71
jmp
Go
LeftArrow:
;-----------------------------------------------------------------------------; API "GetAsyncKeyState" determines whether a key is up or down at the time the
; function is called ...
;-----------------------------------------------------------------------------push
25h
;vKey, virtual-key code, VK_LEFT=25h
call
GetAsyncKeyState
;- API Function shr
eax,1Fh
cmp
eax,1h
jne
RightArrow
add
eax,74
jmp
Go
RightArrow:
;-----------------------------------------------------------------------------; API "GetAsyncKeyState" determines whether a key is up or down at the time the
; function is called ...
;-----------------------------------------------------------------------------push
27h
;vKey, virtual-key code, VK_RIGHT=27h
call
GetAsyncKeyState
;- API Function shr
eax,1Fh
cmp
eax,1h
jne
DownArrow
add
eax,76
jmp
Go
DownArrow:
;-----------------------------------------------------------------------------; API "GetAsyncKeyState" determines whether a key is up or down at the time the
; function is called ...
;-----------------------------------------------------------------------------push
28h
;vKey, virtual-key code, VK_DOWN=28h
call
GetAsyncKeyState
;- API Function shr
eax,1Fh
cmp
eax,1h
jne
TP1_return
add
eax,79
jmp
Go
Page 15

td_win32asm_170.asm
Table_Spotlight:
mov
eax,Index_spotlight
mov
ebx,OFFSET Table_spotlight
add
ebx,eax
mov
al,[ebx]
inc
Index_spotlight
cmp
Index_spotlight,180
jbe
Go
mov
Index_spotlight,0h

;get value from table


;
;
;
;
;
;
;

Go:
mov
mov
mov
mov

;vertical speed
;horizontal speed
;max. window width
;max. window height

ecx,Yspeed
edx,Xspeed
esi,Xpos_max
edi,Ypos_max

Up:
cmp
al,72
jne
Left
cmp
OffYpos_work,0h
ja
SubY_work
cmp
OffYpos_light,edi
jae
TP1_return
add
OffYpos_light,ecx
sub
edi,OffYpos_light
mov
OffYpos_max,edi
jmp
Effect
SubY_work:
sub
OffYpos_work,ecx
sub
edi,OffYpos_work
mov
OffYpos_max,edi
jmp
Effect
Left:
cmp
al,75
jne
Right
cmp
OffXpos_work,0h
ja
SubX_work
cmp
OffXpos_light,esi
jae
TP1_return
add
OffXpos_light,edx
sub
esi,OffXpos_light
mov
OffXpos_max,esi
jmp
Effect
SubX_work:
sub
OffXpos_work,edx
sub
esi,OffXpos_work
mov
OffXpos_max,esi
jmp
Effect
Right:
cmp
jne

al,77
Down

;up arrow key

= 72

;left arrow key

= 75

;right arrow key

= 77
Page 16

td_win32asm_170.asm
cmp
OffXpos_light,0h
je
AddX_work
sub
OffXpos_light,edx
sub
esi,OffXpos_light
mov
OffXpos_max,esi
jmp
Effect
AddX_work:
cmp
OffXpos_work,esi
jae
TP1_return
add
OffXpos_work,edx
sub
esi,OffXpos_work
mov
OffXpos_max,esi
jmp
Effect
Down:
cmp
al,80
jne
TP1_return
cmp
OffYpos_light,0h
je
AddY_work
sub
OffYpos_light,ecx
sub
edi,OffYpos_light
mov
OffYpos_max,edi
jmp
Effect
AddY_work:
cmp
OffYpos_work,edi
jae
TP1_return
add
OffYpos_work,ecx
sub
edi,OffYpos_work
mov
OffYpos_max,edi
Effect:
call
My_EffectCode
mov
WM_PAINT_proceed,0h

;down arrow key

= 80

;- Subroutine ;reset flag

TP1_return:
popad
;pop all register back from stack
ret
14h
;return and clear stack (14h !!!)
;##############################################################################
;******************************************************************************
; My own (sub)routine(s) for a compacter code resist here ...
;-----------------------------------------------------------------------------My_CleanSystem:
call
My_EffectCodeAll_Off
;- Subroutine ;-----------------------------------------------------------------------------; API "DeleteObject" deletes a logical pen, brush, font, bitmap, region, or
; palette, freeing all system resources associated with the object.
;-----------------------------------------------------------------------------push
handleBMP
;hObject, handle compatible graphic object
call
DeleteObject
;- API Function ;-----------------------------------------------------------------------------; API "DeleteObject" deletes a logical pen, brush, font, bitmap, region, or
; palette, freeing all system resources associated with the object.
Page 17

td_win32asm_170.asm
;-----------------------------------------------------------------------------push
handleBMP_light
;hObject, handle compatible graphic object
call
DeleteObject
;- API Function ;-----------------------------------------------------------------------------; API "DeleteObject" deletes a logical pen, brush, font, bitmap, region, or
; palette, freeing all system resources associated with the object.
;-----------------------------------------------------------------------------push
handleBMP_back
;hObject, handle compatible graphic object
call
DeleteObject
;- API Function ;-----------------------------------------------------------------------------; API "DeleteObject" deletes a logical pen, brush, font, bitmap, region, or
; palette, freeing all system resources associated with the object.
;-----------------------------------------------------------------------------push
handleBMP_work
;hObject, handle compatible graphic object
call
DeleteObject
;- API Function ;-----------------------------------------------------------------------------; API "DeleteDC" deletes the specified device context (DC).
;-----------------------------------------------------------------------------push
handleCDC_light
;hdc, handle of compatible device context
call
DeleteDC
;- API Function ;-----------------------------------------------------------------------------; API "DeleteDC" deletes the specified device context (DC).
;-----------------------------------------------------------------------------push
handleCDC_back
;hdc, handle of compatible device context
call
DeleteDC
;- API Function ;-----------------------------------------------------------------------------; API "DeleteDC" deletes the specified device context (DC).
;-----------------------------------------------------------------------------push
handleCDC_work
;hdc, handle of compatible device context
call
DeleteDC
;- API Function ret
My_EffectCode:
;-----------------------------------------------------------------------------; API "FillRect" fills a rectangle using the specified brush. Includes the left
; and top borders, but excludes the right and bottom borders of the rectangle.
;-----------------------------------------------------------------------------push
hbrBackground
;hbr, handle of brush
push
OFFSET Xpos_org
;lprc, address of rectangle structure
push
handleCDC_work
;hDC, handle of device context
call
FillRect
;- API Function ;-----------------------------------------------------------------------------; API "BitBlt" performs a bit-block transfer of the color data corresponding
; to a rectangle of pixels from the specified source device context into a
; destination device context.
;-----------------------------------------------------------------------------push
0CC0020h
;dwRop, SRCCOPY
push
OffYpos_light
;nYSrc, y=src. rect. up-left corner
push
OffXpos_light
;nXSrc, x=src. rect. up-left corner
push
handleCDC_light
;hdcSrc, handle of source device
push
OffYpos_max
;nHeight, height of dest. rect.
push
OffXpos_max
;nWidth, width of dest. rect.
push
OffYpos_work
;nYDest, y=dest. rect. up-left corner
Page 18

td_win32asm_170.asm
push
OffXpos_work
;nXDest, x=dest. rect. up-left corner
push
handleCDC_work
;hdcDest, handle destination device
call
BitBlt
;- API Function ;-----------------------------------------------------------------------------; This is my routine to manipulate the bitmap. It must (!) be short and fast.
;-----------------------------------------------------------------------------mov
ecx,sizeBMP
;max. size of bitmap
mov
esi,pointerBMP_back
;pointer background bitmap memory area
mov
edi,pointerBMP_work
;pointer working bitmap memory area
cmp
TP1_Mode,1h
jne
EffectCode_002
My_EffectCode_001:
mov
al,[edi]
cmp
al,0h
jne
YesEffectCode_001
mov
al,[esi]
jmp
NoEffectCode_001
YesEffectCode_001:
mov
bl,0FFh
mov
ah,[esi]
sub
bl,ah
cmp
bl,al
jae
OkEffectCode_001
mov
al,bl
OkEffectCode_001:
add
al,ah
NoEffectCode_001:
mov
[edi],al
inc
esi
inc
edi
dec
ecx
jne
My_EffectCode_001
jmp
My_EffectCode_Done
EffectCode_002:
cmp
TP1_Mode,2h
jne
My_EffectCode_return
My_EffectCode_002:
mov
eax,[edi]
and
eax,0FFFFFF00h
cmp
eax,0h
jne
Test01_EffectCode_002
mov
al,[esi]
mov
[edi],al
mov
al,[esi+1]
mov
[edi+1],al
mov
al,[esi+2]
mov
[edi+2],al
add
esi,3
add
edi,3
sub
ecx,3
jne
My_EffectCode_002

;
;
;calculating the spotlight effect 001

;
;
;calculating the spotlight effect 002

Page 19

td_win32asm_170.asm
jmp

My_EffectCode_Done

Test01_EffectCode_002:
mov
eax,[esi]
and
eax,0FFFFFF00h
cmp
eax,0h
jne
Test02_EffectCode_002
mov
[edi],al
mov
[edi+1],al
mov
[edi+2],al
add
esi,3
add
edi,3
sub
ecx,3
jne
My_EffectCode_002
jmp
My_EffectCode_Done
Test02_EffectCode_002:
mov
edx,3
LoopEffectCode_002:
mov
al,[edi]
mov
bl,0FFh
mov
ah,[esi]
sub
bl,ah
cmp
bl,al
jae
OkEffectCode_002
mov
al,bl
OkEffectCode_002:
add
al,ah
mov
[edi],al
inc
esi
inc
edi
dec
ecx
je
My_EffectCode_Done
dec
edx
jne
LoopEffectCode_002
jmp
My_EffectCode_002
My_EffectCode_Done:
;-----------------------------------------------------------------------------; API "InvalidateRect" adds a rectangle to specified window's update region.
; This function performs a WM_PAINT message.
;-----------------------------------------------------------------------------push
0h
;bErase, erase-background flag
push
0h
;lpRect, rect structure, 0h=client area
push
handleWindow
;hWnd, handle window update region
call
InvalidateRect
;- API Function My_EffectCode_return:
ret
My_WM_CREATE:
mov
eax,WP1_hWnd
;store main window handle
mov
handleWindow,eax
;
;-----------------------------------------------------------------------------Page 20

td_win32asm_170.asm
; API "GetMenu" retrieves the handle of the menu assigned to the given window.
;-----------------------------------------------------------------------------push
WP1_hWnd
;hWnd, handle of window
call
GetMenu
;- API Function mov
handleMenu,eax
;handle of menu
;-----------------------------------------------------------------------------; API "GetDC" retrieves a handle of a display device context (DC) for the
; client area of the specified window.
;-----------------------------------------------------------------------------push
WP1_hWnd
;hwnd, handle of window
call
GetDC
;- API Function mov
handleDC,eax
;handle of DC
;-----------------------------------------------------------------------------; API "GetDeviceCaps" retrieves device-specific infos about a specified device.
;-----------------------------------------------------------------------------push
12
;nIndex, index to query, BITSPIXEL
push
handleDC
;hdc, device-context handle
call
GetDeviceCaps
;- API Function mov
ScreenBpp,eax
;
;-----------------------------------------------------------------------------; API "ReleaseDC" releases a device context (DC), freeing it for use by other.
;-----------------------------------------------------------------------------push
handleDC
;hdc, handle of device context
push
WP1_hWnd
;hwnd, handle of window
call
ReleaseDC
;- API Function Palette:
cmp
ScreenBpp,16
;program do not work in 256 color modi
jae
RGB
;if display >=16 bit go to RGB
;-----------------------------------------------------------------------------; API "MessageBoxA" creates a message box, we can only click OK
;-----------------------------------------------------------------------------push
0h
;uType, style, 0=MB_OK Button
push
OFFSET MB0_Titel
;lpCaption, pointer message box title
push
OFFSET MB2_Text
;lpText, pointer message box text
push
WP1_hWnd
;handle of owner window 0=no owner
call
MessageBoxA
;- API Function ;-----------------------------------------------------------------------------; API "DestroyWindow" function destroys the given window
;-----------------------------------------------------------------------------push
WP1_hWnd
;hwnd, handle of window to destroy
call
DestroyWindow
;- API Function ret
RGB:
cmp
ScreenBpp,24
;
jae
ReadyOnCreate
;if display >=24 bit skip EnumDisplay
;-----------------------------------------------------------------------------; API "GetSystemMetrics" retrieves system metrics and system config. settings.
;-----------------------------------------------------------------------------push
0h
;nIndex, parameter to retrieve, SM_CXSCREEN
call
GetSystemMetrics
;- API Function mov
ScreenWidth,eax
;store result
Page 21

push
call
mov

1h
GetSystemMetrics
ScreenHeight,eax

td_win32asm_170.asm
;nIndex, parameter to retrieve, SM_CYSCREEN
;- API Function ;store result

EnumDisplay:
;-----------------------------------------------------------------------------; API "EnumDisplaySettingsA" obtains information about one of a display
; device's graphics modes.
;-----------------------------------------------------------------------------push
OFFSET dmDeviceName
;lpDevMode, structure to receive settings
push
ModeNum
;iModeNum, specifies the graphics mode
push
0h
;lpszDeviceName, specifies display device
call
EnumDisplaySettingsA
;- API Function cmp
eax,0h
;compare, error or max entry
je
ErrorOnCreate
;
inc
ModeNum
;inc entry index
cmp
dmBitsPerPel,24
;check if 24/32 Bits per pixel is avaible
jb
EnumDisplay
;if not test next entry
mov
eax,dmPelsWidth
;check avaible screen width
cmp
eax,ScreenWidth
;do not change screen width
jne
EnumDisplay
;test next entry
mov
eax,dmPelsHeight
;check avaible screen height
cmp
eax,ScreenHeight
;do not change screen height
jne
EnumDisplay
;test next entry
;-----------------------------------------------------------------------------; API "ChangeDisplaySettingsA" sets the display to the specified graphics mode.
;-----------------------------------------------------------------------------push
0h
;dwflags, flags for settings change, 0=dyn.
push
OFFSET dmDeviceName
;lpDevMode, points to a DEVMODE structure
call
ChangeDisplaySettingsA
;- API Function cmp
eax,1
;
jbe
ReadyOnCreate
;success
ErrorOnCreate:
;-----------------------------------------------------------------------------; API "EnableMenuItem" function enables, disables or grays the given menu item.
;-----------------------------------------------------------------------------push
1h
;uEnable, flags, MF_BYCOMMAND | MF_GRAYED
push
12h
;uIDEnableItem, item to enable,disable,gray
push
handleMenu
;hMenu, handle of menu
call
EnableMenuItem
;- API Function ;-----------------------------------------------------------------------------; API "MessageBoxA" creates a message box, we can click Yes or No.
;-----------------------------------------------------------------------------push
44h
;uType, MB_ICONINFORMATION | MB_YESNO
push
OFFSET MB0_Titel
;lpCaption, pointer message box title
push
OFFSET MB0_Text
;lpText, pointer message box text
push
WP1_hWnd
;handle of owner window 0=no owner
call
MessageBoxA
;- API Function cmp
eax,6h
;return value, 7h=IDYES
je
ReadyOnCreate
;
;-----------------------------------------------------------------------------; API "DestroyWindow" function destroys the given window
Page 22

td_win32asm_170.asm
;-----------------------------------------------------------------------------push
WP1_hWnd
;hwnd, handle of window to destroy
call
DestroyWindow
;- API Function ret
ReadyOnCreate:
;-----------------------------------------------------------------------------; API "timeGetDevCaps" queries the timer device to determine its resolution.
; Returned values in the TIMECAPS struc are different from system to system.
;-----------------------------------------------------------------------------push
8h
;cbtc, size in bytes TIMECAPS structure
push
OFFSET wPeriodMin
;ptc, address of a TIMECAPS structure
call
timeGetDevCaps
;- API Function ;-----------------------------------------------------------------------------; API "GetDC" retrieves a handle of a display device context (DC) for the
; client area of the specified window.
;-----------------------------------------------------------------------------push
WP1_hWnd
;hwnd, handle of window
call
GetDC
;- API Function mov
handleDC,eax
;handle of DC
;-----------------------------------------------------------------------------; API "CreateCompatibleDC" creates a memory device context (DC) compatible with
; the specified device.
;-----------------------------------------------------------------------------push
handleDC
;hdc, handle memory device context
call
CreateCompatibleDC
;- API Function mov
handleCDC_light,eax
;handle, compatible DC
;-----------------------------------------------------------------------------; API "CreateDIBSection" creates a device-independent bitmap (DIB) that
; applications can write to directly.
; The return value is a handle to the newly created device-independent bitmap,
; and ppvBits points to the bitmap's bit values.
;-----------------------------------------------------------------------------push
0h
;dwOffset, offset to bitmap bit values
push
0h
;hSection, optional handle to a file
push
OFFSET pointerBMP_light
;ppvBits, receive pointer to bitmap bits
push
0h
;iUsage,color data type, DIB_RGB_COLORS
push
OFFSET temp_BitMapInfoHeader;pbmi, address of BITMAPINFO structure
push
handleDC
;hdc, handle of device context
call
CreateDIBSection
;- API Function mov
handleBMP_light,eax
;
;-----------------------------------------------------------------------------; API "SelectObject" selects an object into the specified device context.
; The new object replaces the previous object of the same type.
;-----------------------------------------------------------------------------push
handleBMP_light
;hgdiobj, handle of object
push
handleCDC_light
;hdc, handle of device context
call
SelectObject
;- API Function mov
handleOld,eax
;handle of previously object
;-----------------------------------------------------------------------------; API "LoadBitmapA" loads the specified bitmap resource from our module's
; executable file, returning a handle.
;-----------------------------------------------------------------------------Page 23

td_win32asm_170.asm
push
OFFSET NameBMP_spotlight
;lpBitmapName, pic name in rc file
push
hInstance
;handle, id of our programm
call
LoadBitmapA
;- API Function mov
handleBMP,eax
;hObject, handle of bitmap
;-----------------------------------------------------------------------------; API "GetDIBits" retrieves the bits of the specified bitmap and copies them
; into a buffer using the specified format.
;-----------------------------------------------------------------------------push
0h
;uUsage, RGB / palette, DIB_RGB_COLORS
push
OFFSET temp_BitMapInfoHeader;lpbi, address structure with bitmap data
push
pointerBMP_light
;lpvBits, address of array for bitmap bits
push
Ypos_max
;cScanLines, number of scan lines to copy
push
0h
;uStartScan, first scan line to set in dest
push
handleBMP
;hbmp, handle of bitmap
push
handleDC
;hdc, handle of device context
call
GetDIBits
;- API Function ;-----------------------------------------------------------------------------; API "DeleteObject" deletes a logical pen, brush, font, bitmap, region, or
; palette, freeing all system resources associated with the object.
;-----------------------------------------------------------------------------push
handleBMP
;hObject, handle compatible graphic object
call
DeleteObject
;- API Function ;-----------------------------------------------------------------------------; API "CreateCompatibleDC" creates a memory device context (DC) compatible with
; the specified device.
;-----------------------------------------------------------------------------push
handleDC
;hdc, handle memory device context
call
CreateCompatibleDC
;- API Function mov
handleCDC_back,eax
;handle, compatible DC
;-----------------------------------------------------------------------------; API "CreateDIBSection" creates a device-independent bitmap (DIB) that
; applications can write to directly.
; The return value is a handle to the newly created device-independent bitmap,
; and ppvBits points to the bitmap's bit values.
;-----------------------------------------------------------------------------push
0h
;dwOffset, offset to bitmap bit values
push
0h
;hSection, optional handle to a file
push
OFFSET pointerBMP_back
;ppvBits, receive pointer to bitmap bits
push
0h
;iUsage, color data type, DIB_RGB_COLORS
push
OFFSET temp_BitMapInfoHeader;pbmi, address of BITMAPINFO structure
push
handleDC
;hdc, handle of device context
call
CreateDIBSection
;- API Function mov
handleBMP_back,eax
;
;-----------------------------------------------------------------------------; API "SelectObject" selects an object into the specified device context.
; The new object replaces the previous object of the same type.
;-----------------------------------------------------------------------------push
handleBMP_back
;hgdiobj, handle of object
push
handleCDC_back
;hdc, handle of device context
call
SelectObject
;- API Function mov
handleOld,eax
;handle of previously object
;-----------------------------------------------------------------------------; API "LoadBitmapA" loads the specified bitmap resource from our module's
Page 24

td_win32asm_170.asm
; executable file, returning a handle.
;-----------------------------------------------------------------------------push
OFFSET NameBMP_picture
;lpBitmapName, pic name in rc file
push
hInstance
;handle, id of our programm
call
LoadBitmapA
;- API Function mov
handleBMP,eax
;hObject, handle of bitmap
;-----------------------------------------------------------------------------; API "GetDIBits" retrieves the bits of the specified bitmap and copies them
; into a buffer using the specified format.
;-----------------------------------------------------------------------------push
0h
;uUsage, RGB / palette, DIB_RGB_COLORS
push
OFFSET temp_BitMapInfoHeader;lpbi, address structure with bitmap data
push
pointerBMP_back
;lpvBits, address of array for bitmap bits
push
Ypos_max
;cScanLines, number of scan lines to copy
push
0h
;uStartScan, first scan line to set in dest.
push
handleBMP
;hbmp, handle of bitmap
push
handleDC
;hdc, handle of device context
call
GetDIBits
;- API Function ;-----------------------------------------------------------------------------; API "DeleteObject" deletes a logical pen, brush, font, bitmap, region, or
; palette, freeing all system resources associated with the object.
;-----------------------------------------------------------------------------push
handleBMP
;hObject, handle compatible graphic object
call
DeleteObject
;- API Function ;-----------------------------------------------------------------------------; API "CreateCompatibleDC" creates a memory device context (DC) compatible with
; the specified device.
;-----------------------------------------------------------------------------push
handleDC
;hdc, handle memory device context,0=screen
call
CreateCompatibleDC
;- API Function mov
handleCDC_work,eax
;handle, compatible DC
;-----------------------------------------------------------------------------; API "CreateDIBSection" creates a device-independent bitmap (DIB) that
; applications can write to directly.
; The return value is a handle to the newly created device-independent bitmap,
; and *ppvBits points to the bitmap's bit values.
;-----------------------------------------------------------------------------push
0h
;dwOffset, offset to bitmap bit values
push
0h
;hSection, optional handle to a file
push
OFFSET pointerBMP_work
;ppvBits, receive pointer bitmap's bit
push
0h
;iUsage, color data type, DIB_RGB_COLORS
push
OFFSET temp_BitMapInfoHeader;pbmi, address of BITMAPINFO structure
push
handleDC
;hdc, handle of device context
call
CreateDIBSection
;- API Function mov
handleBMP_work,eax
;
;-----------------------------------------------------------------------------; API "SelectObject" selects an object into the specified device context.
; The new object replaces the previous object of the same type.
;-----------------------------------------------------------------------------push
handleBMP_work
;hgdiobj, handle of object
push
handleCDC_work
;hdc, handle of device context
call
SelectObject
;- API Function mov
handleOld,eax
;handle of previously object
Page 25

td_win32asm_170.asm
;-----------------------------------------------------------------------------; API "BitBlt" performs a bit-block transfer of the color data corresponding
; to a rectangle of pixels from the specified source device context into a
; destination device context.
;-----------------------------------------------------------------------------push
0CC0020h
;dwRop, SRCCOPY
push
Ypos_org
;nYSrc, y=src. rect. up-left corner
push
Xpos_org
;nXSrc, x=src. rect. up-left corner
push
handleCDC_back
;hdcSrc, handle of source device
push
Ypos_max
;nHeight, height of dest. rect.
push
Xpos_max
;nWidth, width of dest. rect.
push
Ypos_org
;nYDest, y=dest. rect. up-left corner
push
Xpos_org
;nXDest, x=dest. rect. up-left corner
push
handleCDC_work
;hdcDest, handle destination device
call
BitBlt
;- API Function ;-----------------------------------------------------------------------------; API "ReleaseDC" releases a device context (DC), freeing it for use by other.
;-----------------------------------------------------------------------------push
handleDC
;hdc, handle of device context
push
WP1_hWnd
;hwnd, handle of window
call
ReleaseDC
;- API Function cmp
ScreenBpp,24
;
jae
ReturnOnCreate
;
;-----------------------------------------------------------------------------; API "ChangeDisplaySettingsA" sets the display to the default graphics mode.
;-----------------------------------------------------------------------------push
0h
;dwflags, flags for settings change, 0=dyn.
push
0h
;lpDevMode, 0=default mode
call
ChangeDisplaySettingsA
;- API Function ReturnOnCreate:
ret
My_EffectCodeAll_Off:
cmp
TP1_Mode,0h
;check if timer is active
je
EffectOff_return
;
;-----------------------------------------------------------------------------; The timeKillEvent function cancels a specified high precision timer event.
;-----------------------------------------------------------------------------push
timerevent1
;uTimerID, ID of timer event to cancel
call
timeKillEvent
;- API Function ;-----------------------------------------------------------------------------; API "CheckMenuItem" sets the state of the specified menu item's check mark
; attribute to either checked or unchecked.
;-----------------------------------------------------------------------------push
8h
;uCheck, MF_BYCOMMAND=0h | MF_CHECKED=8h
push
20h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function push
0h
;uCheck, MF_BYCOMMAND=0h | MF_UNCHECKED=0h
push
21h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function Page 26

td_win32asm_170.asm
push
0h
;uCheck, MF_BYCOMMAND=0h | MF_UNCHECKED=0h
push
22h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function mov
TP1_Mode,0h
;reset timer flag / effect number
;-----------------------------------------------------------------------------EffectOff_return:
ret
My_RestoreScreen:
;-----------------------------------------------------------------------------; API "BitBlt" performs a bit-block transfer of the color data corresponding
; to a rectangle of pixels from the specified source device context into a
; destination device context.
;-----------------------------------------------------------------------------push
0CC0020h
;dwRop, SRCCOPY
push
Ypos_org
;nYSrc, y=src. rect. up-left corner
push
Xpos_org
;nXSrc, x=src. rect. up-left corner
push
handleCDC_back
;hdcSrc, handle of source device
push
Ypos_max
;nHeight, height of dest. rect.
push
Xpos_max
;nWidth, width of dest. rect.
push
Ypos_org
;nYDest, y=dest. rect. up-left corner
push
Xpos_org
;nXDest, x=dest. rect. up-left corner
push
handleCDC_work
;hdcDest, handle destination device
call
BitBlt
;- API Function call
My_InvalidateRect
;- Subroutine ret
My_EffectCode001_On:
cmp
TP1_Mode,1h
;check if timer is active
je
EffectCode001_On_return
;
cmp
TP1_Mode,0h
;check if timer is inactive
je
EffectCode001_skip
;
;-----------------------------------------------------------------------------; The timeKillEvent function cancels a specified high precision timer event.
;-----------------------------------------------------------------------------push
timerevent1
;uTimerID, ID of timer event to cancel
call
timeKillEvent
;- API Function EffectCode001_skip:
;-----------------------------------------------------------------------------; API "CheckMenuItem" sets the state of the specified menu item's check mark
; attribute to either checked or unchecked.
;-----------------------------------------------------------------------------push
0h
;uCheck, MF_BYCOMMAND=0h | MF_UNCHECKED=0h
push
20h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function push
8h
;uCheck, MF_BYCOMMAND=0h | MF_CHECKED=8h
push
21h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function push
0h
;uCheck, MF_BYCOMMAND=0h | MF_UNCHECKED=0h
push
22h
;uIDCheckItem, menu item to check/uncheck
Page 27

td_win32asm_170.asm
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function mov
TP1_Mode,1h
;set timer flag / effect number
call
My_EffectCode
;- Subroutine ;-----------------------------------------------------------------------------; The timeSetEvent function starts a PRECISION timer event. After activated, it
; calls the specified callback function. It runs in its own thread !
;-----------------------------------------------------------------------------push
1h
;fuEvent, timer type, TIME_PERIODIC=1h
push
0h
;dwUser, user-supplied callback data
push
OFFSET TP1
;lpTimeProc, address callback function
push
wPeriodMin
;uResolution, resolution in ms
push
ThreadTime
;uDelay, event delay in milliseconds
call
timeSetEvent
;- API Function mov
timerevent1,eax
;store handle
;-----------------------------------------------------------------------------EffectCode001_On_return:
ret
My_EffectCode002_On:
cmp
TP1_Mode,2h
;check if timer is active
je
EffectCode002_On_return
;
cmp
TP1_Mode,0h
;check if timer is inactive
je
EffectCode002_skip
;
;-----------------------------------------------------------------------------; The timeKillEvent function cancels a specified high precision timer event.
;-----------------------------------------------------------------------------push
timerevent1
;uTimerID, ID of timer event to cancel
call
timeKillEvent
;- API Function EffectCode002_skip:
;-----------------------------------------------------------------------------; API "CheckMenuItem" sets the state of the specified menu item's check mark
; attribute to either checked or unchecked.
;-----------------------------------------------------------------------------push
0h
;uCheck, MF_BYCOMMAND=0h | MF_UNCHECKED=0h
push
20h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function push
0h
;uCheck, MF_BYCOMMAND=0h | MF_UNCHECKED=0h
push
21h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function push
8h
;uCheck, MF_BYCOMMAND=0h | MF_CHECKED=8h
push
22h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function mov
TP1_Mode,2h
;set timer flag / effect number
call
My_EffectCode
;- Subroutine ;-----------------------------------------------------------------------------; The timeSetEvent function starts a PRECISION timer event. After activated, it
; calls the specified callback function. It runs in its own thread !
;-----------------------------------------------------------------------------push
1h
;fuEvent, timer type, TIME_PERIODIC=1h
Page 28

td_win32asm_170.asm
push
0h
;dwUser, user-supplied callback data
push
OFFSET TP1
;lpTimeProc, address callback function
push
wPeriodMin
;uResolution, resolution in ms
push
ThreadTime
;uDelay, event delay in milliseconds
call
timeSetEvent
;- API Function mov
timerevent1,eax
;store handle
;-----------------------------------------------------------------------------EffectCode002_On_return:
ret
My_AutoMode:
;-----------------------------------------------------------------------------; API "CheckMenuItem" sets the state of the specified menu item's check mark
; attribute to either checked or unchecked.
;-----------------------------------------------------------------------------push
8h
;uCheck, MF_BYCOMMAND=0h | MF_CHECKED=8h
push
0A0h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function push
0h
;uCheck, MF_BYCOMMAND=0h | MF_UNCHECKED=0h
push
0A1h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function ;-----------------------------------------------------------------------------; Reset effect parameter
;-----------------------------------------------------------------------------mov
Index_spotlight,0h
;
mov
OffXpos_work,0h
;
mov
OffYpos_work,0h
;
mov
OffXpos_light,0h
;
mov
OffYpos_light,0h
;
mov
eax,Xpos_max
;
mov
OffXpos_max,eax
;
mov
eax,Ypos_max
;
mov
OffYpos_max,eax
;
mov
AutoMode,1h
;AutoMode on, Keyboard off
;-----------------------------------------------------------------------------AutoMode_return:
ret
My_Keyboard:
;-----------------------------------------------------------------------------; API "CheckMenuItem" sets the state of the specified menu item's check mark
; attribute to either checked or unchecked.
;-----------------------------------------------------------------------------push
8h
;uCheck, MF_BYCOMMAND=0h | MF_CHECKED=8h
push
0A1h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function push
0h
;uCheck, MF_BYCOMMAND=0h | MF_UNCHECKED=0h
push
0A0h
;uIDCheckItem, menu item to check/uncheck
push
handleMenu
;hmenu, handle of menu
call
CheckMenuItem
;- API Function Page 29

td_win32asm_170.asm
mov
AutoMode,0h
;Keyboard on, AutoMode off
;-----------------------------------------------------------------------------Keyboard_return:
ret
My_LoadBMP:
;-----------------------------------------------------------------------------; API "GetOpenFileName" creates a system-defined dialog box that enables the
; user to select a file to open.
;-----------------------------------------------------------------------------mov
lStructSize,4Ch
;length in bytes of structure
mov
eax,WP1_hWnd
mov
hWndOwner,eax
;id window that owns dialog box
mov
eax,hInstance
mov
hInstance1,eax
;handle, our program id
mov
lpstrFilter,OFFSET FileFilter
;pointer to string + filter, 0= no
mov
lpstrCustomFilter,0h
;pointer to user defined filter
mov
nMaxCustFilter,0h
;size bytes/characters of above
mov
nFilterIndex,0h
;filter index of lpstrFilter
mov
lpstrFile,OFFSET FileName
;pointer initialize filename, 0=no
mov
nMaxFile,104h
;max size bytes/characters of above
mov
lpstrFileTitle,0h
;pointer title of the selected file
mov
nMaxFileTitle,0h
;size of the lpstrFileTitle buffer
mov
lpstrInitialDir,0h
;pointer init file dir,0=default
mov
lpstrTitle,OFFSET LoadFileTitel ;pointer title of the box
mov
Flags,00281804h
;the dialog box creation flags
mov
nFileOffset,0h
;offset filename in string lpstrFile
mov
nFileExtension,0h
;offset extension in string lpstrFile
mov
lCustData,0h
;?
mov
lpfnHook,0h
;? used if flag is OFN_ENABLETEMPLATE
mov
lpTemplateName,0h
;? used if flag is OFN_ENABLETEMPLATE
mov
lpstrDefExt,OFFSET FileDefExt
;pointer default extension file, 0=no
push
OFFSET lStructSize
;pointer to OPENFILENAME Structure
call
GetOpenFileNameA
;- API Function cmp
eax,0h
;
je
My_FileError_2
;Error
;-----------------------------------------------------------------------------; API "CreateFileA" creates or opens a file, it returns a handle.
;-----------------------------------------------------------------------------push
0h
;hTemplateFile,
push
80h
;dwFlagsAndAttributes, 80h = normal
push
3h
;dwCreationDistribution, OPEN_EXISTING
push
0h
;lpSecurityAttributes,
push
0h
;dwShareMode,
push
80000000h
;dwDesiredAccess, GENERIC_READ
push
OFFSET FileName
;lpFileName,pointer to filename
call
CreateFileA
;- API Function cmp
eax,-1
;
je
My_FileError_1
;Error
mov
handleFile,eax
;store handle in variable
;-----------------------------------------------------------------------------; API "GetFileSize" retrieves the size, in bytes, of the specified file.
;-----------------------------------------------------------------------------Page 30

td_win32asm_170.asm
push
0h
;lpFileSizeHigh, highword file size
push
handleFile
;hFile, handle of file to get size of
call
GetFileSize
;- API Function cmp
eax,-1
;
je
My_FileError_0
;Error
mov
totalBytesFile,eax
;store size in variable
;-----------------------------------------------------------------------------; API "GlobalAlloc" allocates the specified number of bytes
;-----------------------------------------------------------------------------push
totalBytesFile
;dwBytes, number of bytes to allocate
push
0h
;uFlags, alloc attributes 0=GMEM_FIXED
call
GlobalAlloc
;- API Function cmp
eax,0h
;
je
My_FileError_0
;Error
mov
pGlobalMemFile,eax
;store memory pointer in variable
;-----------------------------------------------------------------------------; API "ReadFile" reads data from a file, starting at the position file pointer
;-----------------------------------------------------------------------------push
0h
;lpOverlapped,address data structure
push
OFFSET FileBytesReturn
;lpNumberOfBytesRead, readed bytes
push
totalBytesFile
;nNumberOfBytesToRead, bytes to read
push
pGlobalMemFile
;lpBuffer, address buffer receives data
push
handleFile
;hFile, handle of file to read
call
ReadFile
;- API Function cmp
eax,0h
;
je
My_FileError_0
;Error
;-----------------------------------------------------------------------------; API "CloseHandle" closes an open object handle.
;-----------------------------------------------------------------------------push
handleFile
;hObject, handle of object to close
call
CloseHandle
;- API Function ;-----------------------------------------------------------------------------; Calculate the pointer to the BITMAPINFO structure and to the bitmap data.
; Also receive the biHeight and biWidth values for future use.
;-----------------------------------------------------------------------------mov
eax,pGlobalMemFile
;first byte in global memory
add
eax,14
;calculate pointer to BITMAPINFOHEADER
mov
pointerBMI_temp,eax
;
mov
eax,pGlobalMemFile
;first byte in global memory
mov
ebx,pGlobalMemFile
;first byte in global memory
add
ebx,10
;offset to bitmap data
add
eax,[ebx]
;calculate pointer to bitmap data
mov
pointerDAT_temp,eax
;
mov
eax,pGlobalMemFile
;pointer to global memory
add
eax,18
;member biWidth of BITMAPINFO
mov
ebx,[eax]
;
mov
biWidth_temp,ebx
;
add
eax,4h
;member biHeight of BITMAPINFO
mov
ebx,[eax]
;
mov
biHeight_temp,ebx
;
;-----------------------------------------------------------------------------; Scale and center bitmap to our window if it is smaller or greater !!!
;-----------------------------------------------------------------------------Page 31

td_win32asm_170.asm
mov
eax,Xpos_max
;check if our window < bitmap width
cmp
eax,biWidth_temp
jb
ScaleBMP
sub
eax,biWidth_temp
shr
eax,1h
mov
XposOrg_temp,eax
;-----------------------------------------------------------------------------mov
eax,Ypos_max
;check if our window < bitmap height
cmp
eax,biHeight_temp
jb
ScaleBMP
sub
eax,biHeight_temp
shr
eax,1h
mov
YposOrg_temp,eax
mov
eax,biHeight_temp
mov
Height_temp,eax
mov
eax,biWidth_temp
mov
Width_temp,eax
jmp
CreateBMP_temp
;-----------------------------------------------------------------------------ScaleBMP:
mov
eax,Ypos_max
;scale bitmap to our window metrics
mov
Height_temp,eax
inc
Height_temp
ScaleBMP_loop:
dec
Height_temp
;set new calculated height
ffree
ST(7)
;free ST(7), must be empty for load
fild
biWidth_temp
;load bitmap width, integer
fidiv
biHeight_temp
;div, biWidth/biHeight, scale factor !
fimul
Height_temp
;mul, scale factor*Height_temp
fistp
Width_temp
;store new calculated width
mov
eax,Xpos_max
cmp
Width_temp,eax
;compare
ja
ScaleBMP_loop
;loop
;-----------------------------------------------------------------------------mov
eax,Xpos_max
;center scaled bitmap into window, Xpos
sub
eax,Width_temp
shr
eax,1h
mov
XposOrg_temp,eax
mov
eax,Ypos_max
;center scaled bitmap into window, Ypos
sub
eax,Height_temp
shr
eax,1h
mov
YposOrg_temp,eax
CreateBMP_temp:
;-----------------------------------------------------------------------------; API "FillRect" fills a rectangle using the specified brush. Includes the left
; and top borders, but excludes the right and bottom borders of the rectangle.
;-----------------------------------------------------------------------------push
hbrBackground
;hbr, handle of brush
push
OFFSET Xpos_org
;lprc, address of rectangle structure
push
handleCDC_back
;hDC, handle of device context
call
FillRect
;- API Function ;-----------------------------------------------------------------------------Page 32

td_win32asm_170.asm
; API "SetStretchBltMode" sets the bitmap stretching mode in the specified DC.
;-----------------------------------------------------------------------------push
3h
;iStretchMode, COLORONCOLOR
push
handleCDC_back
;hdc, handle of device context
call
SetStretchBltMode
;- API Function ;-----------------------------------------------------------------------------; API "SetMapMode" sets the mapping mode of the specified device context. The
; mapping mode defines the unit of measure used to transform page-space units
; into device-space units and the orientation of the device's x and y axes.
;-----------------------------------------------------------------------------push
1h
;fnMapMode, mapping mode, MM_TEXT
push
handleCDC_back
;hdc, handle of device context
call
SetMapMode
;- API Function ;-----------------------------------------------------------------------------; API "StretchDIBits" copies the color data for a rectangle of pixels in a
; device-independent bitmap (DIB) to the specified destination rectangle.
; If the destination rectangle is larger than the source rectangle, this API
; stretches the rows and columns of color data to fit the destination rectangle
; If the destination rectangle is smaller than the source rectangle, this API
; compresses the rows and columns by using the specified raster operation.
;-----------------------------------------------------------------------------push
0CC0020h
;dwRop, raster operation code
push
0h
;iUsage, DIB_RGB_COLORS
push
pointerBMI_temp
;lpBitsInfo, address of bitmap data
push
pointerDAT_temp
;lpBits, address of bitmap bits
push
biHeight_temp
;nSrcHeight, height of src rectangle
push
biWidth_temp
;nSrcWidth, width of source rectangle
push
Ypos_org
;YSrc, y=src. rect. up-left
push
Xpos_org
;XSrc, x=src. rect. up-left
push
Height_temp
;nDestHeight, height dest. rectangle
push
Width_temp
;nDestWidth, width dest. rectangle
push
YposOrg_temp
;YDest, y=dest. rect. up-left
push
XposOrg_temp
;XDest, x=dest. rect. up-left
push
handleCDC_back
;hdc, handle of destination DC
call
StretchDIBits
;- API Function ;-----------------------------------------------------------------------------; API "GlobalFree" frees the global memory object and invalidates its handle.
;-----------------------------------------------------------------------------push
pGlobalMemFile
;hMem, handle to global memory object
call
GlobalFree
;- API Function ;-----------------------------------------------------------------------------; API "FillRect" fills a rectangle using the specified brush. Includes the left
; and top borders, but excludes the right and bottom borders of the rectangle.
;-----------------------------------------------------------------------------push
hbrBackground
;hbr, handle of brush
push
OFFSET Xpos_org
;lprc, address of rectangle structure
push
handleCDC_work
;hDC, handle of device context
call
FillRect
;- API Function ret
My_SaveBMP:
;-----------------------------------------------------------------------------; API "GetObjectA" obtains information about a specified graphics object.
Page 33

td_win32asm_170.asm
; Depending on the graphics object, the function places a filled-in BITMAP,
; DIBSECTION, EXTLOGPEN, LOGBRUSH, LOGFONT, or LOGPEN structure, or a count of
; table entries (for a logical palette), into a specified buffer.
;-----------------------------------------------------------------------------push
OFFSET bmType
;lpvObject, pointer buffer, bitmap struc
push
18h
;cbBuffer, size of buffer for object info
push
handleBMP_work
;hgdiobj, handle graphic object of interest
call
GetObjectA
;- API Function ;-----------------------------------------------------------------------------; Convert color format to a count of bits = bmPlanes * bmBitsPixel
;-----------------------------------------------------------------------------mov
eax,0h
;
mov
edx,0h
;
mov
ax,bmPlanes
;
mul
bmBitsPixel
;
shl
edx,16
;get the High word from multiplication
or
eax,edx
;
mov
ecx,1
;
cmp
eax,1
;
je
Init_BMI
;
mov
ecx,4
;
cmp
eax,4
;
jbe
Init_BMI
;
mov
ecx,8
;
cmp
eax,8
;
jbe
Init_BMI
;
mov
ecx,16
;
cmp
eax,16
;
jbe
Init_BMI
;
mov
ecx,24
;
cmp
eax,24
;
jbe
Init_BMI
;
mov
ecx,32
;
Init_BMI:
;-----------------------------------------------------------------------------; Init BITMAPINFO structure, calculate the biSizeImage and biClrUsed member.
; ecx
= cClrBits !!!
; biClrUsed
= 2^cClrBits
; biSizeImage
= (biWidth+7)/8*biHeight*cClrBits
; ==> Take a look into Win32.hlp for and search for "BITMAPINFO".
;-----------------------------------------------------------------------------mov
biSize,28h
;size of BITMAPINFOHEADER structure =28h
mov
eax,bmWidth
;
mov
biWidth,eax
;
mov
eax,bmHeight
;
mov
biHeight,eax
;
mov
ax,bmPlanes
;
mov
biPlanes,ax
;
mov
ax,bmBitsPixel
;
mov
biBitCount,ax
;
mov
biCompression,0h
;BI_RGB, no compression
mov
biClrImportant,0h
;all of the device colors are important
;-----------------------------------------------------------------------------Page 34

td_win32asm_170.asm
mov
eax,biWidth
;calculate the size of the image
add
eax,7
;EAX=biWidth+7, prevents 0div
shr
eax,3h
;EAX=EAX/8, ignore the rest !!!
mul
biHeight
;EAX=EAX*biHeight
mul
ecx
;EAX=EAX*cClrBits
mov
biSizeImage,eax
;store result
;-----------------------------------------------------------------------------mov
biClrUsed,0h
;
cmp
cl,24
;check if color format < 24 bit
jae
Init_BMFH
;
mov
eax,2h
;EAX=2
shl
eax,cl
;EAX=2^cClrBits
mov
biClrUsed,eax
;store result
Init_BMFH:
;-----------------------------------------------------------------------------; Init BITMAPFILEHEADER structure, calculate bfSize and bfOffBits member.
; bfSize
= 14+28h+biClrUsed*4+biSizeImage
; bfOffBits
= 14+28h+biClrUsed*4
; ==> Take a look into Win32.hlp for and search for "BITMAPFILEHEADER".
;-----------------------------------------------------------------------------mov
bfType,4d42h
;4d42h="BM"
mov
ebx,4h
;
mov
eax,biClrUsed
;EAX=biClrUsed
mul
ebx
;EAX=biClrUsed*4
add
eax,28h
;size of BITMAPINFO = 28h
add
eax,14
;size of BITMAPFILEHEADER = 14
mov
bfOffBits,eax
;store result
add
eax,biSizeImage
;
mov
bfSize,eax
;store result
mov
bfReserved1,0h
;must be 0
mov
bfReserved2,0h
;must be 0
;-----------------------------------------------------------------------------; Calculate the total number of bytes required for the bitmap.
; 14+28h+biClrUsed*4+biSizeImage
;-----------------------------------------------------------------------------mov
ebx,4h
;
mov
eax,biClrUsed
;EAX=biClrUsed
mul
ebx
;EAX=biClrUsed*4
add
eax,biSizeImage
;
add
eax,28h
;size of BITMAPINFO
add
eax,14
;size of BITMAPFILEHEADER = 14
mov
totalBytesFile,eax
;store result
;-----------------------------------------------------------------------------; API "GlobalAlloc" allocates the calculated number of bytes.
;-----------------------------------------------------------------------------push
totalBytesFile
;dwBytes, number of bytes to allocate
push
40h
;uFlags, alloc attributes 40h = GPTR
call
GlobalAlloc
;- API Function cmp
eax,0h
;
je
My_FileError_1
;Error
mov
pGlobalMemFile,eax
;store memory pointer in variable
;-----------------------------------------------------------------------------; Copy the BITMAPFILEHEADER and BITMAPINFO structure into allocated memory.
Page 35

td_win32asm_170.asm
;-----------------------------------------------------------------------------mov
ecx,0h
;
mov
ebx,OFFSET bfType
;
Copy_C_BMFH_BMI:
mov
dl,[ebx]
;
mov
[eax],dl
;
inc
eax
;
inc
ebx
;
inc
ecx
;
cmp
ecx,14
;size of BITMAPFILEHEADER
jb
Copy_C_BMFH_BMI
;
;-----------------------------------------------------------------------------; Bugfix, thanks to Nico for the bug report and the bug fix !!!
;-----------------------------------------------------------------------------mov
ecx,0h
;
mov
ebx,OFFSET biSize
;
Copy_C_BMFH_BI:
mov
dl,[ebx]
;
mov
[eax],dl
;
inc
eax
;
inc
ebx
;
inc
ecx
;
cmp
ecx,40
;size of BITMAPINFO
jb Copy_C_BMFH_BI
;-----------------------------------------------------------------------------; Getting the bitmap parameter from the BITMAPFILEHEADER / BITMAPINFOHEADER
;-----------------------------------------------------------------------------mov
eax,pGlobalMemFile
;first byte in global memory
mov
ebx,pGlobalMemFile
;first byte in global memory
add
ebx,10
;offset to bitmap data
add
eax,[ebx]
;calculate pointer to bitmap data
mov
pointerDAT_temp,eax
;pointer to bitmap data !
;-----------------------------------------------------------------------------mov
eax,pGlobalMemFile
;first byte in global memory
add
eax,14
;calculate pointer to BITMAPINFO struc
mov
pointerBMI_temp,eax
;pointer to BITMAPINFO structure !
;-----------------------------------------------------------------------------; API "GetDC" retrieves a handle of a display device context (DC) for the
; client area of the specified window.
;-----------------------------------------------------------------------------push
WP1_hWnd
;hwnd, handle of window
call
GetDC
;- API Function mov
handleDC,eax
;handle of DC
;-----------------------------------------------------------------------------; API "GetDIBits" retrieves the bits of the specified bitmap and copies them
; into a buffer using the specified format.
;-----------------------------------------------------------------------------push
0h
;uUsage, RGB / palette, DIB_RGB_COLORS
push
pointerBMI_temp
;lpbi, address structure with bitmap data
push
pointerDAT_temp
;lpvBits, address of array for bitmap bits
push
biHeight
;cScanLines, number of scan lines to copy
push
0h
;uStartScan, first scan line to set in dest
push
handleBMP_work
;hbmp, handle of bitmap
Page 36

td_win32asm_170.asm
push
handleDC
;hdc, handle of device context
call
GetDIBits
;- API Function ;-----------------------------------------------------------------------------; API "ReleaseDC" releases a device context (DC), freeing it for use by other.
;-----------------------------------------------------------------------------push
handleDC
;hdc, handle of device context
push
WP1_hWnd
;hwnd, handle of window
call
ReleaseDC
;- API Function ;-----------------------------------------------------------------------------; API "GetSaveFileName" creates a system-defined dialog box that enables the
; user to select a file to save.
;-----------------------------------------------------------------------------mov
lStructSize,4Ch
;length in bytes of structure
mov
eax,WP1_hWnd
;
mov
hWndOwner,eax
;id window that owns dialog box
mov
eax,hInstance
;
mov
hInstance1,eax
;handle, our program id
mov
lpstrFilter,OFFSET FileFilter
;pointer to string + filter, 0= no
mov
lpstrCustomFilter,0h
;pointer to user defined filter
mov
nMaxCustFilter,0h
;size bytes/characters of above
mov
nFilterIndex,0h
;filter index of lpstrFilter
mov
lpstrFile,OFFSET FileName
;pointer initialize filename, 0=no
mov
nMaxFile,104h
;max size bytes/characters of above
mov
lpstrFileTitle,0h
;pointer title of the selected file
mov
nMaxFileTitle,0h
;size of the lpstrFileTitle buffer
mov
lpstrInitialDir,0h
;pointer init file dir,0=default
mov
lpstrTitle,OFFSET SaveFileTitel ;pointer title of the box
mov
Flags,00281804h
;the dialog box creation flags
mov
nFileOffset,0h
;offset filename in string lpstrFile
mov
nFileExtension,0h
;offset extension in string lpstrFile
mov
lCustData,0h
;?
mov
lpfnHook,0h
;? used if flag is OFN_ENABLETEMPLATE
mov
lpTemplateName,0h
;? used if flag is OFN_ENABLETEMPLATE
mov
eax,OFFSET FileDefExt
;
mov
lpstrDefExt,eax
;pointer default extension file, 0=no
push
OFFSET lStructSize
;pointer to OPENFILENAME Structure
call
GetSaveFileNameA
;- API Function cmp
eax,0h
;check for error
je
My_FileError_2
;
;-----------------------------------------------------------------------------; API "CreateFileA" creates or opens a file.
; It returns a handle that can be used to access the object.
;-----------------------------------------------------------------------------push
0h
;hTemplateFile,
push
80h
;dwFlagsAndAttributes, 80h=normal
push
2h
;dwCreationDistribution, CREATE_ALWAYS
push
0h
;lpSecurityAttributes,
push
0h
;dwShareMode,
push
40000000h
;dwDesiredAccess,GENERIC_WRITE
push
OFFSET FileName
;lpFileName,pointer to filename
call
CreateFileA
;- API Function cmp
eax,-1
;error ? INVALID_HANDLE_VALUE = -1
je
My_FileError_1
;
Page 37

td_win32asm_170.asm
mov
handleFile,eax
;store handle in variable
;-----------------------------------------------------------------------------; API "WriteFile" writes data to a file
;-----------------------------------------------------------------------------push
0h
;lpOverlapped, structure overlapped I/O
push
OFFSET FileBytesReturn
;lpNumberOfBytesWritten,
push
totalBytesFile
;nNumberOfBytesToWrite, bytes to write
push
pGlobalMemFile
;lpBuffer, address data write to file
push
handleFile
;hFile, handle of file to write to
call
WriteFile
;- API Function cmp
eax,0h
;check for error
je
My_FileError_0
;
;-----------------------------------------------------------------------------; API "CloseHandle" closes an open object handle.
;-----------------------------------------------------------------------------push
handleFile
;hObject, handle of object to close
call
CloseHandle
;- API Function ;-----------------------------------------------------------------------------; API "GlobalFree" frees the global memory object and invalidates its handle.
;-----------------------------------------------------------------------------push
pGlobalMemFile
;hMem, handle to the global memory object
call
GlobalFree
;- API Function ret
My_InvalidateRect:
;-----------------------------------------------------------------------------; API "InvalidateRect" adds a rectangle to specified window's update region.
; This function performs a WM_PAINT message.
;-----------------------------------------------------------------------------push
0h
;bErase, erase-background flag
push
0h
;lpRect, rect structure, 0h=client area
push
WP1_hWnd
;hWnd, handle window update region
call
InvalidateRect
;- API Function ret
My_FileError_0:
;-----------------------------------------------------------------------------; API "CloseHandle" closes an open object handle.
;-----------------------------------------------------------------------------push
handleFile
;hObject, handle of object to close
call
CloseHandle
;- API Function My_FileError_1:
;-----------------------------------------------------------------------------; API "MessageBoxA" creates a message box, we can only click OK
;-----------------------------------------------------------------------------push
0h
;uType, style, 0=MB_OK Button
push
OFFSET MB0_Titel
;lpCaption, pointer message box title
push
OFFSET MB1_Text
;lpText, pointer message box text
push
WP1_hWnd
;handle of owner window 0=no owner
call
MessageBoxA
;- API Function My_FileError_2:
Page 38

td_win32asm_170.asm
ret
My_HexDDtoStringDec:
;don't forget to save register (pushad/popad)
;-----------------------------------------------------------------------------; Converts a 32 bit value in EAX into an ascii decimal string to offset EDI.
; Fast DWORD to decimal string conversion. Made by tE! // TMG.
;-----------------------------------------------------------------------------push
0h
;get some additional space on stack (10 bytes min.)
push
0h
;'' upper dword is 0
push
eax
;'' lower dword -> 32 bit integer to convert
fild
qword ptr[esp]
;load 64 bit integer value on TOS
fbstp
real10 ptr[esp]
; store value as 80bit BCD value
pop
ecx
pop
eax
mov
edx,ecx
mov
ebx,eax
shr
ecx,4
shr
eax,4
and
ebx,0000000Fh
;mask nibbles
and
edx,0F0F0F0Fh
;...
and
ecx,0F0F0F0Fh
add
edx,30303030h
;build ascii numbers
add
ecx,30303030h
;...
add
eax,30h
add
ebx,30h
mov
[edi],al
;store in buffer
mov
[edi+1],bl
;...
mov
[edi+8],cl
mov
[edi+9],dl
mov
[edi+6],ch
mov
[edi+7],dh
bswap
ecx
;endian conversion (486 processor needed)
bswap
edx
;dto.
mov
[edi+2],cl
mov
[edi+3],dl
mov
[edi+4],ch
mov
[edi+5],dh
pop
eax
;correct stack
ret
;******************************************************************************
;==============================================================================
; end Main = end of our program code
;-----------------------------------------------------------------------------end Main
;end of our program code, entry point
;==============================================================================
; To create the exe file use this commands with your Microsoft Assembler/Linker
;-----------------------------------------------------------------------------; ml.exe /c /coff td__170.asm
;asm command
; rc.exe /v rsrc.rc
;rc command
; cvtres.exe /machine:ix86 rsrc.res
; link.exe /subsystem:windows td__170.obj rsrc.obj
;link command
Page 39

td_win32asm_170.asm
;==============================================================================

Page 40

Вам также может понравиться