GDi+ ASM 图形界面编程的问题
在VB中我经常用GDI+来载入png后来发现载入的很慢打算用Asm写一个DLL
准备先写一个窗体看看行不行
从行动到现在已经快一个月
代码反复的敲始终出不来效果
已确认
invoke GdipGetImageWidth,gdip_pngImage,offset pngWidth
invoke GdipGetImageHeight,gdip_pngImage,offset pngHeight
pngWidth/pngHeight 都获取到了图片大小
在调用GdipDrawImageRect 来绘制图片的时候就始终显示不出来
用反汇编来调试也始终找不出头绪
麻烦高人指点指点帮忙纠错
开始用的对话框由于要发代码
所以我自己写了一个窗体
现在心里非常的烦躁我这一个月完全专研他去了
代码如下:
.386
.model flat,stdcall
option casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 文件定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include gdi32.inc
includelib gdi32.lib
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include gdiplus_structs.inc
includelib gdiplus.lib
include gdiplus.inc
GdiplusStartupInput struct
GdiplusVersion dword ?
DebugEventCallback dword ?
SuppressBackgroundThread dword ?
SuppressExternalCodecs dword ?
GdiplusStartupInput ends
.data
GpInput GdiplusStartupInput<1,0,0,0>
.data?
pngWidth dd ?
pngHeight dd ?
szBuffer dd 50 dup(?)
szBuffer1 dd 50 dup(?)
Token dd ?
hInstance dd ?
hWinMain dd ?
.const
DebugPng db '加载Png图片错误',0
DebugHDC db '创建窗体DC失败',0
DebugGdip db 'Gdip初始化失败',0
FilePath db '\splash.png',0
szClassName db 'MyClass',0
szCaptionMain db 'My first Window !',0
szText db 'Win32 Assembly, Simple and powerful !',0
.code
_ProcWinMain proc uses ebx edi esi hWnd,uMsg,wParam,lParam
LOCAL lngHeight
LOCAL lngWidth
LOCAL hdc:HDC
LOCAL Graphics
LOCAL addrBuffer
LOCAL gdip_Graphics
local gdip_pngImage
mov eax,uMsg
;********************************************************************
.if eax == WM_PAINT
;********************************************************************
.elseif eax == WM_CLOSE
invoke DestroyWindow,hWinMain
invoke PostQuitMessage,NULL
;********************************************************************
.elseif eax == WM_CREATE
invoke GdiplusStartup,offset Token,offset GpInput,NULL ;Gdip初始化
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.if eax!=GpStatusOk
invoke MessageBox,NULL,offset DebugGdip,NULL,MB_OK
.endif
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
mov gdip_Graphics,0
mov gdip_pngImage,0
invoke GetDC,hWinMain
mov hdc,eax
invoke GdipCreateFromHDC,hdc,addr gdip_Graphics
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.if eax!=GpStatusOk
invoke MessageBox,NULL,offset DebugHDC,NULL,MB_OK ;创建窗体DC失败
invoke GdiplusShutdown,Token
.endif
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
invoke RtlZeroMemory,offset szBuffer,sizeof szBuffer
invoke RtlZeroMemory,offset szBuffer1,sizeof szBuffer1
invoke GetCurrentDirectory,sizeof szBuffer1,offset szBuffer1 ; 获得当前地址
lea eax,szBuffer1 ;取字符串长度
mov ebx,eax
@@: cmp byte ptr [eax],0
jz @F
add eax,1
jmp @B
@@: nop
mov addrBuffer,eax ;取字符串长度结束
invoke lstrcpy,addrBuffer,offset FilePath ;szBuffer1文件全路径+addrBuffer=szBuffer1
invoke MultiByteToWideChar,CP_ACP,NULL,offset szBuffer1,-1,offset szBuffer,sizeof szBuffer ;ANSI TO Unicode
invoke GdipLoadImageFromFile,offset szBuffer,addr gdip_pngImage
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.if eax!=GpStatusOk
invoke MessageBox,NULL,offset DebugPng,NULL,MB_OK
invoke GdiplusShutdown,Token
.endif
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
mov pngWidth,0
mov pngWidth,0
invoke GdipGetImageWidth,gdip_pngImage,offset pngWidth
invoke GdipGetImageHeight,gdip_pngImage,offset pngHeight
invoke GdipDrawImageRect,gdip_Graphics,gdip_pngImage,0,0,offset pngWidth,offset pngHeight
invoke GdipDisposeImage,gdip_pngImage
invoke GdipDeleteGraphics,gdip_Graphics
.elseif eax==WM_TIMER
invoke MessageBox,NULL,offset FilePath,NULL,MB_OK
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.endif
xor eax,eax
ret
_ProcWinMain endp
_WinMain proc
local @stWndClass:WNDCLASSEX
local @stMsg:MSG
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
invoke LoadCursor,0,IDC_ARROW
mov @stWndClass.hCursor,eax
push hInstance
pop @stWndClass.hInstance
mov @stWndClass.cbSize,sizeof WNDCLASSEX
mov @stWndClass.style,CS_HREDRAW or CS_VREDRAW
mov @stWndClass.lpfnWndProc,offset _ProcWinMain
mov @stWndClass.hbrBackground,COLOR_WINDOW + 1
mov @stWndClass.lpszClassName,offset szClassName
invoke RegisterClassEx,addr @stWndClass
invoke CreateWindowEx,WS_EX_CLIENTEDGE,offset szClassName,offset szCaptionMain,WS_OVERLAPPEDWINDOW,100,100,600,400,NULL,NULL,hInstance,NULL
mov hWinMain,eax
invoke ShowWindow,hWinMain,SW_SHOWNORMAL
invoke UpdateWindow,hWinMain
.while TRUE
invoke GetMessage,addr @stMsg,NULL,0,0
.break .if eax == 0
invoke TranslateMessage,addr @stMsg
invoke DispatchMessage,addr @stMsg
.endw
ret
_WinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
call _WinMain
invoke GdiplusShutdown,Token
invoke ExitProcess,NULL
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
end start