silkodyssey
Joined: 02 Oct 2003
Posts: 198
Location: St.Vincent & the Grenadines
|
I am trying to convert petzold's system metrics program to fasm but the call to GetTextMetrics in the window proecedure is crashing the program and I have no idea why. If I comment out the call to GetTextMetrics, the program runs otherwise it crashes, Any help would be appreciated.
; template for program using standard Win32 headers
format PE GUI 4.0
entry start
include '%include%\win32a.inc'
section '.data' data readable writeable
include 'sysmets.inc'
_title db 'Get System Metrics No. 1',0
_class db 'SysMets1',0
hInstance dd ?
CommandLine dd 0
cxCaps dd 0
cxChar dd 0
cyChar dd 0
section '.code' code readable executable
start:
invoke GetModuleHandle,0
mov [hInstance],eax
invoke GetCommandLine
mov [CommandLine], eax
stdcall WinMain, [hInstance],NULL,[CommandLine], SW_SHOWDEFAULT
invoke ExitProcess,eax
proc WinMain, hInst, hPrevInst, CmdLine, CmdShow
.wc WNDCLASSEX
.msg MSG
.hwnd dd 0
enter
mov [.wc.cbSize], sizeof.WNDCLASSEX
invoke LoadIcon,0,IDI_APPLICATION
mov [.wc.hIcon],eax
mov [.wc.hIconSm], eax
invoke LoadCursor,0,IDC_ARROW
mov [.wc.hCursor],eax
mov [.wc.style], CS_HREDRAW or CS_VREDRAW
mov [.wc.lpfnWndProc],WindowProc
mov [.wc.cbClsExtra],0
mov [.wc.cbWndExtra],0
mov eax,[hInstance]
mov [.wc.hInstance],eax
mov [.wc.hbrBackground],COLOR_WINDOW+1
mov [.wc.lpszMenuName],0
mov [.wc.lpszClassName],_class
lea eax, [.wc]
invoke RegisterClassEx, eax
invoke CreateWindowEx,0,_class,_title,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,[hInst],NULL
mov [.hwnd],eax
invoke ShowWindow, [.hwnd], [CmdShow]
invoke UpdateWindow, [.hwnd]
msg_loop:
lea eax, [WinMain.msg]
invoke GetMessage,eax,NULL,0,0
or eax,eax
jz end_loop
lea eax, [WinMain.msg]
invoke TranslateMessage, eax
lea eax, [WinMain.msg]
invoke DispatchMessage, eax
jmp msg_loop
end_loop:
mov eax,[WinMain.msg.wParam]
return
proc WindowProc, hwnd,wmsg,wparam,lparam
.hdc dd 0
.ps PAINTSTRUCT
.szBuffer rb 10
.tm TEXTMETRIC
enter
push ebx esi edi
cmp [wmsg],WM_DESTROY
je wmdestroy
cmp [wmsg], WM_CREATE
je wmcreate
defwndproc:
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
jmp finish
wmcreate:
invoke GetDC, [hwnd]
mov [WindowProc.hdc], eax
lea edx, [WindowProc.tm]
; here is the problem
invoke GetTextMetrics, [WindowProc.hdc] , edx
;mov eax, [WindowProc.tm.tmAveCharWidth]
;mov [cxChar], eax
;mov al, [WindowProc.tm.tmPitchAndFamily]
;and al, 1
;cmp al, 1
;jne .bitnotset
;mov eax, 3
;jmp .continue
.bitnotset:
;mov eax, 2
.continue:
;mul [cxChar]
;mov edx, 0
;mov ecx, 2
;div ecx
;mov [cxCaps], eax
;mov eax, [WindowProc.tm.tmHeight]
;add eax, [WindowProc.tm.tmExternalLeading]
;mov [cyChar], eax
;invoke ReleaseDC, [hwnd], [WindowProc.hdc]
;xor eax, eax
jmp finish
wmdestroy:
invoke PostQuitMessage,0
xor eax,eax
finish:
pop edi esi ebx
return
section '.idata' import data readable writeable
library kernel32,'KERNEL32.DLL',\
user32,'USER32.DLL'
include '%include%\apia\kernel32.inc'
include '%include%\apia\user32.inc'
include '%include%\apia\gdi32.inc'
_________________ silkodyssey
|