📄 showdib2.asm
字号:
.IF eax==IDM_FILE_OPEN ; Show the File Open dialog box
invoke DibFileOpenDlg, hWnd, ADDR szFileName, ADDR szTitleName ;Open DIB dialog
.IF !eax
mov eax,0
ret
.ENDIF
.IF pbmfh ; If there's an existing DIB, free the memory
invoke GlobalUnlock, pbmfh
invoke GlobalFree, hMemory
.ENDIF
; Load entire DIB into memory
; ---------------------------
invoke LoadCursor, 0, IDC_WAIT
invoke SetCursor, eax
invoke ShowCursor, TRUE
invoke DibLoadImage, ADDR szFileName ; Pointer to allocated
mov pbmfh, eax ; memory for BITMAPFILEHEADER
mov ebx,eax
invoke ShowCursor, FALSE
invoke LoadCursor, 0, IDC_ARROW
invoke SetCursor, eax
invoke InvalidateRect, hWnd, NULL, TRUE ;Invalidate client area for later update
.IF pbmfh==NULL ; If NULL put out "Can't load" message
invoke MessageBox, hWnd, ADDR Cantload, ADDR szAppName, 0
mov eax, MB_ICONEXCLAMATION or MB_OK
ret
.ENDIF
; Get pointers to the info structure & the bits
; ---------------------------------------------
mov eax, sizeof BITMAPFILEHEADER ; BITMAPINFO immediately follows
add eax,ebx ; the header (pointed to by ebx)
mov pbmi,eax ; Points to bitmap information
mov esi,eax ; save to reg as well
mov eax,BITMAPFILEHEADER.bfOffBits[ebx]; offset from BMFH struct to pix bits
add eax,ebx
mov pBits,eax ; This is a pointer to the actual DIB pixel bits
; Get the DIB width & height
; --------------------------
.IF BITMAPINFO.bmiHeader.biSize[esi]== sizeof BITMAPCOREHEADER
; width & height are WORDs
xor eax,eax ; Make sure we clear high word
mov ax, BITMAPCOREHEADER.bcWidth[esi] ; Width of bitmap
mov cxDib, eax
mov ax, BITMAPCOREHEADER.bcHeight[esi] ; Height
mov cyDib, eax
.ELSE ; width & heght are DWORDs
xor eax,eax ; Make sure we clear high word
mov eax, BITMAPINFO.bmiHeader.biWidth[esi]
mov cxDib, eax
mov eax, BITMAPINFO.bmiHeader.biHeight[esi]
.IF eax < 1
neg eax ; Get abs value
.ENDIF
mov cyDib, eax
.ENDIF
mov eax,0
ret
.ELSEIF eax==IDM_FILE_SAVE
; Show the File Save dialog
; -------------------------
invoke DibFileSaveDlg, hWnd, ADDR szFileName, ADDR szTitleName
.IF !eax
mov eax,0
ret
.ENDIF
; Save the DIB to a disk file
; ---------------------------
invoke LoadCursor, 0, IDC_WAIT ; Load cursor resource
invoke SetCursor, eax ; Set cursor shape
invoke ShowCursor, TRUE
invoke DibSaveImage, ADDR szFileName, pbmfh ; Save image as DIB
mov bSuccess, eax
invoke ShowCursor, FALSE
invoke LoadCursor, 0, IDC_ARROW
invoke SetCursor, eax
.IF !bSuccess
invoke MessageBox, hWnd, ADDR Cantsave, ADDR szAppName, \
MB_ICONEXCLAMATION or MB_OK
.ENDIF
mov eax,0
ret
.ELSEIF eax==IDM_FILE_PRINT
.IF !pbmfh
mov eax,0
ret
.ENDIF
; Get printer DC
; --------------
mov eax,hWnd
mov pd.hWndOwner,eax
invoke PrintDlg, ADDR pd
.IF !eax ; If not true
mov eax,0
ret
.ENDIF
mov eax, pd.hDC
mov hdcPrn, eax
.IF !eax ;eax==NULL
invoke MessageBox, hWnd, ADDR CantgetDC, ADDR szAppName, \
MB_ICONEXCLAMATION or MB_OK
mov eax,0
ret
.ENDIF
; Check if printer can print bitmaps
; ----------------------------------
invoke GetDeviceCaps, hdcPrn, RASTERCAPS
and eax,RC_BITBLT
.IF !eax
invoke DeleteDC, hdcPrn
invoke MessageBox, hWnd, ADDR CantPrintBMP, ADDR szAppName, \
MB_ICONEXCLAMATION or MB_OK
mov eax,0
ret
.ENDIF
; Get size of printable area for page
; -----------------------------------
invoke GetDeviceCaps, hdcPrn, HORZRES
mov cxPage,eax
invoke GetDeviceCaps, hdcPrn, VERTRES
mov cyPage,eax
mov bSuccess,FALSE
; Send the DIB to the printer
; ---------------------------
invoke LoadCursor, NULL, IDC_WAIT
invoke SetCursor, eax
invoke ShowCursor, TRUE
invoke StartDoc, hdcPrn, ADDR doci; Start the document
push eax ; Save truth
invoke StartPage, hdcPrn ; Start the page
pop ecx ; Recover truth
.IF eax && ecx > 0 ; If StartDoc & StartPage calls are OK
invoke ShowDib, hdcPrn, pbmi, pBits, cxDib, cyDib, \
cxPage, cyPage, wShow
invoke EndPage, hdcPrn
.IF eax > 0
mov bSuccess, TRUE
invoke EndDoc, hdcPrn
.ENDIF
.ENDIF
invoke ShowCursor, FALSE
invoke LoadCursor, NULL, IDC_ARROW
invoke SetCursor, eax
invoke DeleteDC, hdcPrn
.IF !bSuccess
invoke MessageBox, hWnd, ADDR CantPrintBMP, ADDR szAppName, \
MB_ICONEXCLAMATION or MB_OK
.ENDIF
mov eax,0
ret
.ELSEIF eax==IDM_EDIT_COPY || eax==IDM_EDIT_CUT
.IF !pbmfh
mov eax,0
ret
.ENDIF
mov ebx, pbmfh ; Reload with pointer to DIB
; as ebx may have changed
; Make copy of the packed DIB
; ---------------------------
mov eax, BITMAPFILEHEADER.bfSize[ebx]
sub eax, sizeof BITMAPFILEHEADER
invoke GlobalAlloc, GHND or GMEM_SHARE, eax
mov hGlobal, eax
invoke GlobalLock, hGlobal
mov pGlobal, eax ; Points at destination
mov eax, ebx ; Get the source address
add eax, sizeof BITMAPFILEHEADER ;
mov ecx, BITMAPFILEHEADER.bfSize[ebx] ; Get length
sub ecx, sizeof BITMAPFILEHEADER ;
invoke CopyMemory, pGlobal, eax, ecx
; destn source length
invoke GlobalUnlock, hGlobal
; Transfer it to the clipboard
; ----------------------------
invoke OpenClipboard, hWnd
invoke EmptyClipboard
invoke SetClipboardData, CF_DIB, hGlobal
invoke CloseClipboard
LOWORD wParam
.IF eax==IDM_EDIT_COPY
mov eax,0
ret
.ENDIF
jmp Fallthr1 ; Fall through
.ELSEIF eax==IDM_EDIT_DELETE
Fallthr1: .IF pbmfh
invoke GlobalUnlock, pbmfh
invoke GlobalFree, hMemory
invoke InvalidateRect, hWnd, NULL, TRUE
.ENDIF
mov eax,0
ret
.ELSEIF eax==IDM_SHOW_NORMAL || eax==IDM_SHOW_CENTRE || \
eax==IDM_SHOW_STRETCH || eax==IDM_SHOW_ISOSTRETCH
invoke CheckMenuItem, hMenu, wShow, MF_UNCHECKED
LOWORD wParam
mov wShow, eax
invoke CheckMenuItem, hMenu, wShow, MF_CHECKED
invoke InvalidateRect, hWnd, NULL, TRUE
mov eax,0
ret
.ENDIF
.ELSEIF eax==WM_PAINT
invoke BeginPaint,hWnd, ADDR ps
mov hdc,eax
.IF pbmfh
invoke ShowDib, hdc, pbmi, pBits, cxDib, cyDib, cxClient, cyClient, wShow
.ENDIF
invoke EndPaint, hWnd, ADDR ps
mov eax,0
ret
.ELSEIF eax==WM_DESTROY
.IF pbmfh
invoke GlobalUnlock, pbmfh ; Free allocated memory
invoke GlobalFree, hMemory
.ENDIF
invoke PostQuitMessage,NULL
mov eax,0
ret
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
WndProc endp
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -