Hi. I wrote this ownerdraw button app and it works fine on Win98, but it crashes on Win2000(Server). I have no idea why this occurs.. can anyone help? Sorry but I couldn't attach the files. Thanks



.386
.MODEL FLAT, STDCALL
LOCALS @@

EXTRN GetModuleHandleA :PROC
EXTRN LoadIconA :PROC
EXTRN LoadCursorA :PROC
EXTRN RegisterClassExA :PROC
EXTRN CreateDialogParamA :PROC
EXTRN ShowWindow :PROC
EXTRN GetMessageA :PROC
EXTRN TranslateMessage :PROC
EXTRN DispatchMessageA :PROC
EXTRN ExitProcess :PROC
EXTRN PostQuitMessage :PROC
EXTRN DefWindowProcA :PROC

EXTRN GetDlgItem :PROC
EXTRN SetWindowLongA :PROC
EXTRN GetClientRect :PROC
EXTRN CreateCompatibleDC :PROC
EXTRN CreateCompatibleBitmap :PROC
EXTRN DrawFrameControl :PROC
EXTRN FillRect :PROC
EXTRN GetWindowLongA :PROC
EXTRN CreateSolidBrush :PROC
EXTRN SelectObject :PROC
EXTRN SendMessageA :PROC
EXTRN GetTextExtentPoint32A :PROC
EXTRN GetSysColor :PROC
EXTRN SetTextColor :PROC
EXTRN SetBkMode :PROC
EXTRN TextOutA :PROC
EXTRN BitBlt :PROC
EXTRN DeleteObject :PROC
EXTRN DeleteDC :PROC

INCLUDE TOOLS\W32.INC

.DATA

NOME_CLASSE DB "JANELA_1", 0
BUFFER DB 256 DUP(0)
bLENGTH DB 0, 0
hMemDC DD 0, 0

ALIGN 4
WNDCLASSEX STRUC
cbSize DD ?
style DD ?
lpfnWndProc DD ?
cbClsExtra ? ? ? ? ? ? ? ? DD ?
cbWndExtra DD ?
hInstance ? ? ? ? ? ? ? ? DD ?
hIcon DD ?
hCursor DD ?
hbrBackground DD ?
lpszMenuName DD ?
lpszClassName DD ?
hIconSm DD ?
WNDCLASSEX ENDS
WCX WNDCLASSEX <48,0,OFFSET WNDPROC,0,DLGWINDOWEXTRA,?,?,?,COLOR_MENU + 1,0,OFFSET NOME_CLASSE,?>

ALIGN 4
MESSAGE STRUC
hWnd DD ?
uMsg DD ?
wParam DD ?
lParam DD ?
time DD ?
xPT DD ?
yPT DD ?
MESSAGE ENDS
MSG MESSAGE <>

DRAWITEMSTRUCT STRUC
ctlType DD ?
ctlID DD ?
itemID DD ?
itemAction ? ? ? ? ? ? ? ? DD ?
itemState ? ? ? ? ? ? ? ? DD ?
hwndItem ? ? ? ? ? ? ? ? DD ?
hdc DD ?
rcItemLeft ? ? ? ? ? ? ? ? DD ?
rcItemTop ? ? ? ? ? ? ? ? DD ?
rcItemRight DD ?
rcItemBottom DD ?
itemData ? ? ? ? ? ? ? ? DD ?
DRAWITEMSTRUCT ENDS

ALIGN 4
RECTANGLE STRUC
left DD ?
top DD ?
right DD ?
bottom DD ?
RECTANGLE ENDS
RECT RECTANGLE <>

ALIGN 4
SIZEL STRUC
x DD ?
y DD ?
SIZEL ENDS
SZ SIZEL <>

.CODE

MAIN PROC
LOCAL hDlg:DWORD

PUSH 0
CALL GetModuleHandleA
MOV , EAX

PUSH IDC_CROSS
PUSH 0
CALL LoadIconA
MOV , EAX
MOV , EAX

PUSH IDI_APPLICATION
PUSH 0
CALL LoadCursorA
MOV , EAX

PUSH OFFSET WCX
CALL RegisterClassExA

PUSH 0
PUSH 0
PUSH 0
PUSH 10
PUSH
CALL CreateDialogParamA
MOV , EAX

PUSH SW_SHOWNORMAL
PUSH
CALL ShowWindow

RECEBE_MSG: PUSH 0
PUSH 0
PUSH 0
PUSH OFFSET MSG
CALL GetMessageA
TEST EAX, EAX
JZ SAIR

PUSH OFFSET MSG
CALL TranslateMessage

PUSH OFFSET MSG
CALL DispatchMessageA
JMP RECEBE_MSG

SAIR: PUSH
CALL ExitProcess
MAIN ENDP
;---------------------------------------------------------------------------------------IN?CIO---
WNDPROC PROC
ARG WND_hWnd:DWORD, WND_uMsg:DWORD, WND_wParam:DWORD, WND_lParam:DWORD
USES EBX, ESI, EDI, EBP

;---WM_DRAWITEM-----------------------

@@MSG_2: CMP DWORD PTR , 2Bh
JNE @@MSG_3

MOV EDI,
CMP DWORD PTR , ODT_BUTTON
JNE @@RESTO

PUSH OFFSET RECT
PUSH
CALL GetClientRect

PUSH
CALL CreateCompatibleDC
MOV , EAX

PUSH
PUSH
PUSH
CALL CreateCompatibleBitmap

PUSH EAX
PUSH
CALL SelectObject
MOV ESI, EAX

PUSH 0
PUSH 0
PUSH BM_GETSTATE
PUSH
CALL SendMessageA
TEST EAX, 4
JZ @@L1

PUSH DFCS_BUTTONPUSH OR DFCS_PUSHED OR DFCS_ADJUSTRECT
PUSH DFC_BUTTON
PUSH OFFSET RECT
PUSH
CALL DrawFrameControl
JMP @@L2

@@L1: PUSH DFCS_BUTTONPUSH OR DFCS_ADJUSTRECT
PUSH DFC_BUTTON
PUSH OFFSET RECT
PUSH
CALL DrawFrameControl

@@L2: PUSH 0040FF00h
CALL CreateSolidBrush

PUSH EAX

PUSH EAX
PUSH OFFSET RECT
PUSH
CALL FillRect

CALL DeleteObject

PUSH 0
PUSH 0
PUSH WM_GETFONT
PUSH
CALL SendMessageA

PUSH EAX
PUSH
CALL SelectObject

PUSH OFFSET BUFFER
PUSH 256
PUSH WM_GETTEXT
PUSH
CALL SendMessageA
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MOV? ? ? ? ?, AL

PUSH OFFSET SZ
PUSH EAX
PUSH OFFSET BUFFER
PUSH
CALL GetTextExtentPoint32A

MOV EAX,
SUB EAX,
SHR EAX, 1
MOV , EAX
SUB , EAX

MOV EAX,
SUB EAX,
SHR EAX, 1
MOV , EAX
SUB , EAX

MOV EAX,
TEST EAX, ODS_SELECTED
JZ @@L3

SUB , 2
SUB , 2

@@L3: PUSH COLOR_BTNTEXT
CALL GetSysColor

PUSH EAX
PUSH
CALL SetTextColor

PUSH TRANSPARENT
PUSH
CALL SetBkMode

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? PUSH? ? ? ? ?DWORD PTR
PUSH OFFSET BUFFER
PUSH
PUSH
PUSH
CALL TextOutA

MOV EBX, EDI
? ? ? ? ? ? ? ? ADD? ? ?EBX, DRAWITEMSTRUCT.rcItemLeft

PUSH SRCCOPY
PUSH
PUSH
PUSH
PUSH
PUSH
PUSH
PUSH
PUSH
CALL BitBlt

PUSH ESI
PUSH
CALL SelectObject

PUSH EAX
CALL DeleteObject

PUSH
CALL DeleteDC

XOR EAX, EAX
INC EAX
RET

;---WM_DESTROY------------------------

@@MSG_3: CMP DWORD PTR , 2
JNE @@RESTO

PUSH 0
CALL PostQuitMessage
RET

;---PROCESSAMENTO PADR?O--------------

@@RESTO: PUSH
PUSH
PUSH
PUSH
CALL DefWindowProcA
RET
WNDPROC ENDP
;------------------------------------------------------------------------------------------FIM---

END MAIN




#define DLGPRINC 10
#define IDC_BTN1 100
DLGPRINC DIALOGEX 6,5,206,67
CAPTION "Color"
FONT 8,"MS Sans Serif"
CLASS "JANELA_1"
STYLE 0x10C80800
EXSTYLE 0x00000000
BEGIN
? CONTROL "IDC_BTN",IDC_BTN1,"Button",0x5001000B,8,12,188,39,0x00000000
END
Posted on 2005-03-26 16:13:01 by Marginais
You can always upload a zipped archive of all the files including source code on www.rapidshare.de. :)
Posted on 2005-03-26 17:12:04 by JimmyClif
The USES directive HAS TO BE before the ARG directive !

That is why it is crashing, and that is old TASM style code :P
You could easy use extended CALL syntax instead of all that pushing and Calling ...

And you should use @@ in front of arguments and LOCAL variables also not only for the labels

Question: Why are you using TASM if you do not know what you are doing?


Posted on 2005-03-27 00:19:50 by BogdanOntanu
My other applications work fine with TASM. The problem is the ownerdraw thing.
Posted on 2005-03-27 12:04:59 by Marginais
Well, i did not say that you can not write applications using TASM -- after all I also useing TASM! ;)
I was just warning you that there are tips/tricks/bugs in TASM that require you to have more knowledge to overcome them... compared with MASM that is. So if you already know this then TASM is just fine, otherwise you are asking for trouble...

Posted on 2005-03-27 21:39:29 by BogdanOntanu