📄 appack.asm
字号:
; #########################################################################
; aPPack is a test piece for MASM programmers using Joergen Ibsen's
; MASM version of "aPLib". It is an implementation of the LZ77 algorithm
; that has the characteristics of reasonable compression speed and very
; high decompression speed.
; This makes it highly suitable for installations and other similar
; applications where decompression speed is critical. The compression
; ratio averages slightly better than PKZIP.
; aPLib is included in MASM32 because it is available from the author
; for personal use as freeware. Commercial applications should contact
; the author for licence of the software.
; This example uses an 8 byte header to store a signature "AP32" and
; the length of the decompressed data. The signature is used to determine
; if a file has been compressed, the stored decompressed length is so
; that the decompression algorithm knows the correct buffer size to
; allocate.
; This example uses OLE string memory which is implemented in 2 macros
; for convenience of use. The macros are "stralloc" and "strfree".
; Note that the toolbar bitmap is the single largest component in the
; assembled program.
; #########################################################################
.386
.model flat, stdcall ; 32 bit memory model
option casemap :none ; case sensitive
include aPPack.inc ; local includes for this file
; #########################################################################
.code
start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke GetCommandLine
mov CommandLine, eax
invoke InitCommonControls
invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
invoke ExitProcess,eax
; #########################################################################
WinMain proc hInst :DWORD,
hPrevInst :DWORD,
CmdLine :DWORD,
CmdShow :DWORD
;====================
; Put LOCALs on stack
;====================
LOCAL wc :WNDCLASSEX
LOCAL msg :MSG
LOCAL Wwd :DWORD
LOCAL Wht :DWORD
LOCAL Wtx :DWORD
LOCAL Wty :DWORD
;==================================================
; Fill WNDCLASSEX structure with required variables
;==================================================
invoke LoadIcon,hInst,500 ; icon ID
mov hIcon, eax
szText szClassName,"aPLib_Class"
mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW \
or CS_BYTEALIGNWINDOW
mov wc.lpfnWndProc, offset WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
m2m wc.hInstance, hInst
mov wc.hbrBackground, COLOR_BTNFACE+1
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, offset szClassName
m2m wc.hIcon, hIcon
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor, eax
m2m wc.hIconSm, hIcon
invoke RegisterClassEx, ADDR wc
;================================
; Centre window at following size
;================================
mov Wwd, 334
mov Wht, 191
invoke GetSystemMetrics,SM_CXSCREEN
invoke TopXY,Wwd,eax
mov Wtx, eax
invoke GetSystemMetrics,SM_CYSCREEN
invoke TopXY,Wht,eax
mov Wty, eax
invoke CreateWindowEx,WS_EX_LEFT,
ADDR szClassName,
ADDR szDisplayName,
WS_OVERLAPPED or WS_SYSMENU,
Wtx,Wty,Wwd,Wht,
NULL,NULL,
hInst,NULL
mov hWnd,eax
invoke LoadMenu,hInst,600 ; menu ID
invoke SetMenu,hWnd,eax
invoke ShowWindow,hWnd,SW_SHOWNORMAL
invoke UpdateWindow,hWnd
;===================================
; Loop until PostQuitMessage is sent
;===================================
StartLoop:
invoke GetMessage,ADDR msg,NULL,0,0
cmp eax, 0
je ExitLoop
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
jmp StartLoop
ExitLoop:
return msg.wParam
WinMain endp
; #########################################################################
WndProc proc hWin :DWORD,
uMsg :DWORD,
wParam :DWORD,
lParam :DWORD
LOCAL var :DWORD
LOCAL caW :DWORD
LOCAL caH :DWORD
LOCAL hFont :DWORD
LOCAL Rct :RECT
LOCAL hDC :DWORD
LOCAL Ps :PAINTSTRUCT
LOCAL tbab :TBADDBITMAP
LOCAL tbb :TBBUTTON
LOCAL buffer1[128]:BYTE ; these are two spare buffers
LOCAL buffer2[128]:BYTE ; for text manipulation etc..
.if uMsg == WM_COMMAND
; ********************************************************
; first check commands that are not allowed while packing
; ********************************************************
.if Packing == 0
.if wParam == 50
.data
ThreadID dd 0
.code
; start compressing in a thread
mov eax, OFFSET PackFile
invoke CreateThread,NULL,NULL,eax,
NULL,0,ADDR ThreadID
invoke CloseHandle,eax
.elseif wParam == 51
invoke UnpackFile
.elseif wParam == 53
invoke SendMessage,hWin,WM_SYSCOMMAND,SC_CLOSE,NULL
.elseif wParam == 54
.data
SelectFile db "Select File",0
fPattern db "*.*",0,0
.code
mov szFileName[0], 0
invoke GetFileName,hWin,ADDR SelectFile,ADDR fPattern
.if szFileName[0] != 0
invoke lcase,ADDR szFileName
invoke SetWindowText,hEdit1,ADDR szFileName
.endif
.endif
.endif
; **************************************
; then commands that are always allowed
; **************************************
.if wParam == 52
.data
AboutTtl db "aPLib Pack",0
AboutMsg db "Joergen Ibsen's aPLib example",13,10,\
"Copyright
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -