两个位图子程序,请高手帮忙
子程序1用于从硬盘文件生成一个位图句柄,供下一步显示用。入口:hWnd -->用此句柄的设备环境作为位图句柄的设备环境
lpFileName -->指向一个BMP文件名的字符串
出口:位图句柄
_CreateBmp proc hWnd,lpFileName
local @hFile,@hFileMap,@lpMemory,@dwFileSize,@hBitmap,@lpBitmapBits,\\
@dwWidth,@dwHeight,@hDcBitmap,@hDcWnd,@lpBitmapInfo
invoke CreateFile,lpFileName,GENERIC_READ,FILE_SHARE_READ,0,\\
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
.if eax == INVALID_HANDLE_value
mov eax,0
ret
.endif
mov @hFile,eax
invoke GetFileSize,@hFile,NULL
mov @dwFileSize,eax
invoke CreateFileMapping,@hFile,NULL,PAGE_READONLY,0,0,NULL
.if ! eax
invoke CloseHandle,@hFile
mov eax,0
Ret
.endif
mov @hFileMap,eax
invoke MapViewOfFile,eax,FILE_MAP_READ,0,0,0
.if ! eax
invoke CloseHandle,@hFileMap
invoke CloseHandle,@hFile
Ret
.endif
mov @lpMemory,eax
pushad
mov @hBitmap,0
mov esi,@lpMemory
mov eax,BITMAPFILEHEADER.bfOffBits [esi]
add eax,esi
mov @lpBitmapBits,eax
add esi,sizeof BITMAPFILEHEADER
mov @lpBitmapInfo,esi
.if BITMAPINFO.bmiHeader.biSize [esi] == sizeof BITMAPCOREHEADER
movzx eax,BITMAPCOREHEADER.bcWidth [esi]
movzx ebx,BITMAPCOREHEADER.bcHeight [esi]
.else
mov eax,BITMAPINFOHEADER.biWidth [esi]
mov ebx,BITMAPINFOHEADER.biHeight [esi]
.endif
mov @dwWidth,eax
mov @dwHeight,ebx
invoke GetDC,hWnd
mov @hDcWnd,eax
invoke CreateCompatibleDC,eax
mov @hDcBitmap,eax
invoke CreateCompatibleBitmap,@hDcWnd,@dwWidth,@dwHeight
mov @hBitmap,eax
invoke SelectObject,@hDcBitmap,@hBitmap
invoke ReleaseDC,hWnd,@hDcWnd
invoke SetDIBitsToDevice,@hDcBitmap,0,0,@dwWidth,@dwHeight,\\
0,0,0,@dwHeight,@lpBitmapBits,@lpBitmapInfo,\\
DIB_RGB_COLORS
.if eax == 0
invoke DeleteObject,@hBitmap
mov @hBitmap,0
.else
; invoke wsprintf,addr szBuffer,addr szFormatFont,@dwFileSize,@dwWidth,@dwHeight
.endif
invoke UnmapViewOfFile,@lpMemory
invoke DeleteDC,@hDcBitmap
invoke CloseHandle,@hFileMap
invoke CloseHandle,@hFile
popad
mov eax,@hBitmap
ret
_CreateBmp endp
第二个子程序,拷贝位图信息用于显示
入口:hWnd2 -->用于显示的窗口句柄
hWnd1 -->上一个子程序生成的位图句柄
出口:无
_copyhdc proc hWnd2,hWnd1
local @hDc1,@hDc2
local @stRect:RECT
invoke GetDC,hWnd1
mov @hDc1,eax
invoke GetDC,hWnd2
mov @hDc2,eax
invoke GetClientRect,hWnd2,addr @stRect
invoke BitBlt,@hDc2,0,0,@stRect.right,@stRect.bottom,\\
@hDc1,0,0,SRCCOPY
invoke ReleaseDC,hWnd1,@hDc1
invoke ReleaseDC,hWnd2,@hDc2
ret
_copyhdc endp
这两个子程序,分别调试时,前一个子程序可以正常看到位图尺寸等信息,后一个子程序能正常拷贝位图信息,但就是两个子程序用下面两个命令执行是不能看到位图信息。
请高手帮忙
调用这两个子程序的命令如下:
invoke _CreateBmp,hWinMain1,addr bmpfilename
.if eax
mov hBmp,eax
invoke _copyhdc,hWinMain1,hBmp
.endif