📄 dlggraphic.asm
字号:
;-----------------------------------------------------------------------------------
;-- Write the content of the display window to a bitmap file.
@@:
invoke SaveDisplayAsBitmap, OFFSET filenameBMP
.ENDIF
@Return:
ret
@DrawElements:
;---------------------------------------------------------------------------------------
;-- Repaint the elements.
invoke PaintElements, -1, NULL, FALSE
;---------------------------------------------------------------------------------------
;-- Redraw the compared elements (if any).
.IF Element1 != -1
push eax
invoke PaintElements, Element1, NULL, TRUE
pop eax
.IF Element2 != -1
invoke PaintElements, Element2, NULL, TRUE
.ENDIF
.ENDIF
ret
ShowContextMenu_GraphicDialog ENDP
;-----------------------------------------------------------------------------------------
; Purpose: Write the content of the display window to a bitmap file.
;
; Inputs: lpFilename - pointer to the name of the bitmap file
;
; Outputs: bitmap file
;
; Notes: none
;-----------------------------------------------------------------------------------------
SaveDisplayAsBitmap PROC lpFilename:LPSTR
LOCAL BFH :BITMAPFILEHEADER
LOCAL BIH :BITMAPINFOHEADER
LOCAL hFile :HANDLE
LOCAL BytesWritten :DWORD
LOCAL Palette[256] :RGBQUAD
LOCAL lpBitmapData :DWORD
LOCAL fError :BYTE
LOCAL currentElement :DWORD
LOCAL xAxis :DWORD
LOCAL yStart :DWORD
LOCAL Value :DWORD
;---------------------------------------------------------------------------------------
;-- These equates define the characteristics of the bitmap.
.const
BITMAP_SIZE_X EQU 128*4 + 2*20
BITMAP_SIZE_Y EQU 128 + 2*20 ; must not be larger than 255!
IF BITMAP_SIZE_Y GE 256
!! ERROR: BITMAP_SIZE_Y must not be greater than 255 !!
ENDIF
;---------------------------------------------------------------------------------------
;-- Do not change the values of the next equates unless you do the right changes in the
;-- code.
BIT_PER_PIXEL EQU 8
BYTE_PER_SCANLINE EQU ((BITMAP_SIZE_X * BIT_PER_PIXEL + 31) AND NOT 31) / 8
COLORS EQU 1 SHL BIT_PER_PIXEL
PALETTE_SIZE EQU 4*COLORS
BITMAP_DATA_SIZE EQU BYTE_PER_SCANLINE * BITMAP_SIZE_Y
.code
;---------------------------------------------------------------------------------------
;-- Set fError to TRUE.
mov fError, TRUE
;---------------------------------------------------------------------------------------
;-- Fill in the BITMAPFILEHEADER structure.
mov BFH.bfType, 4D42h
mov BFH.bfSize, SIZEOF BITMAPFILEHEADER + SIZEOF BITMAPINFOHEADER + PALETTE_SIZE + BITMAP_DATA_SIZE
mov BFH.bfReserved1, NULL
mov BFH.bfReserved2, NULL
mov BFH.bfOffBits, SIZEOF BITMAPFILEHEADER + SIZEOF BITMAPINFOHEADER + PALETTE_SIZE
;---------------------------------------------------------------------------------------
;-- Fill in the BITMAPINFOHEADER structure.
mov BIH.biSize, SIZEOF BITMAPINFOHEADER
mov BIH.biWidth, BITMAP_SIZE_X
mov BIH.biHeight, BITMAP_SIZE_Y
mov BIH.biPlanes, 1
mov BIH.biBitCount, BIT_PER_PIXEL
mov BIH.biCompression, BI_RGB
mov BIH.biSizeImage, 0
mov BIH.biXPelsPerMeter, 0
mov BIH.biYPelsPerMeter, 0
mov BIH.biClrUsed, COLORS
mov BIH.biClrImportant, COLORS
;---------------------------------------------------------------------------------------
;-- Allocate the memory for the bitmap data.
invoke SysAllocStringByteLen, NULL, BITMAP_DATA_SIZE
mov lpBitmapData, eax
;---------------------------------------------------------------------------------------
;-- Create the palette entries.
lea ebx, Palette
mov eax, 00FEA5h
mov ecx, 127
@@:
mov DWORD PTR [ebx + ecx*4], eax
sub eax, 000200h
dec ecx
jns @B
mov DWORD PTR [ebx + 128*4], 0FFFFFFh
mov DWORD PTR [ebx + 129*4], 0FF0000h
mov DWORD PTR [ebx + 130*4], 0000000h
;---------------------------------------------------------------------------------------
;-- Create the bitmap data.
;-------------------------------------------------------------------------------------
;-- Draw the white background.
mov ecx, BITMAP_SIZE_Y - 1
@Loop1:
mov ebx, BITMAP_SIZE_X - 1
xor edx, edx
mov eax, ecx
mov edi, BYTE_PER_SCANLINE
mul edi
add eax, lpBitmapData
@Loop2:
mov BYTE PTR [eax + ebx], 128
dec ebx
jns @Loop2
dec ecx
jns @Loop1
;-------------------------------------------------------------------------------------
;-- Mark the currently compared elements (if any).
.IF Element1 != -1
mov eax, lpBitmapData
mov ecx, SortInfo.numElements
shl ecx, 1
sub eax, ecx
add eax, (BITMAP_SIZE_X SHR 1) + 1 + (BYTE_PER_SCANLINE * (BITMAP_SIZE_Y - 1))
mov ecx, SortInfo.lpElements
mov ebx, Element1
sub ebx, ecx
mov edx, Element2
.IF edx != -1
sub edx, ecx
.ENDIF
mov cx, BITMAP_SIZE_Y + 300h
@@:
mov WORD PTR [eax + ebx], 8181h
.IF edx != -1
mov WORD PTR [eax + edx], 8181h
.ENDIF
dec ch
.IF ZERO?
dec cl
jz @F
dec cl
jz @F
dec cl
jz @F
mov ch, 3
sub eax, BYTE_PER_SCANLINE*3
.ENDIF
sub eax, BYTE_PER_SCANLINE
dec cl
jnz @B
.ENDIF
@@:
;-------------------------------------------------------------------------------------
;-- Draw the elements.
mov ecx, SortInfo.numElements
mov currentElement, ecx
lea ebx, [(BITMAP_SIZE_X SHR 1) + 2*ecx - 3] ; EBX contains the value fo the
; x-axis for the first element.
mov eax, BITMAP_SIZE_Y
.IF !fDisplayLines
sub eax, ecx
.ENDIF
xor edx, edx
mov ecx, BYTE_PER_SCANLINE
shr ecx, 1
mul ecx
mov yStart, eax
dec currentElement
@Loop3:
;-----------------------------------------------------------------------------------
;-- Get the value of the current element.
mov eax, currentElement
mov ecx, SortInfo.lpElements
mov eax, DWORD PTR [ecx + 4*eax]
mov Value, eax
;-----------------------------------------------------------------------------------
;-- Draw the value of the element.
.IF fDisplayLines
xor edx, edx
mov eax, BYTE_PER_SCANLINE
mov ecx, Value
shr ecx, 1
mul ecx
add eax, yStart
add eax, ebx
add eax, lpBitmapData
mov cl, BYTE PTR [Value]
test cl, 1
jnz @F
inc cl
@@:
mov ch, cl
mov dl, cl
@@:
mov WORD PTR [eax], cx
sub eax, BYTE_PER_SCANLINE
dec dl
jns @B
.ELSE
xor edx, edx
mov eax, BYTE_PER_SCANLINE
mov ecx, Value
mul ecx
add eax, yStart
add eax, ebx
add eax, lpBitmapData
mov cl, BYTE PTR [Value]
mov ch, cl
mov WORD PTR [eax], cx
mov WORD PTR [eax + BYTE_PER_SCANLINE], cx
.ENDIF
sub ebx, 4
;-----------------------------------------------------------------------------------
;-- Process the next element.
dec currentElement
jns @Loop3
.IF Element1 != -1
.ENDIF
;---------------------------------------------------------------------------------------
;-- Create the file.
invoke CreateFile, lpFilename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL
mov hFile, eax
cmp eax, INVALID_HANDLE_VALUE
jz @ReturnWithError
;---------------------------------------------------------------------------------------
;-- Write the content of the two structures to the file.
invoke WriteFile, hFile, ADDR BFH, SIZEOF BITMAPFILEHEADER, ADDR BytesWritten, NULL
invoke WriteFile, hFile, ADDR BIH, SIZEOF BITMAPINFOHEADER, ADDR BytesWritten, NULL
;---------------------------------------------------------------------------------------
;-- Write the palette to the file.
invoke WriteFile, hFile, ADDR Palette, PALETTE_SIZE, ADDR BytesWritten, NULL
;---------------------------------------------------------------------------------------
;-- Write the bitmap data to the file.
invoke WriteFile, hFile, lpBitmapData, BITMAP_DATA_SIZE, ADDR BytesWritten, NULL
;---------------------------------------------------------------------------------------
;-- Close the file.
invoke CloseHandle, hFile
@Return:
invoke SysFreeString, lpBitmapData
ret
@ReturnWithError:
invoke MessageBox, hDialogFrame, lpSTR_ERR_SAVEASBITMAP, lpSTR_TITLE_ERROR, MB_OK or MB_ICONEXCLAMATION
invoke SysFreeString, lpBitmapData
ret
SaveDisplayAsBitmap ENDP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -