Hi Everyone, This is my first try to translate C to ASM. Would somebody please tell me where I'm wrong or right: C source: =======================================================================
 
BOOL CALLBACK OwnDrawProc(HWND hDlg, UINT message, WPARAM wParam, 
                          LPARAM lParam) 
{ 
    HDC hdcMem; 
    LPDRAWITEMSTRUCT lpdis; 
 
    switch (message) 
    { 
        case WM_INITDIALOG: 
 
            // hinst, hbm1 and hbm2 are defined globally. 
            hbm1 = LoadBitmap((HANDLE) hinst, "OwnBit1"); 
            hbm2 = LoadBitmap((HANDLE) hinst, "OwnBit2"); 
            return TRUE; 
 
        case WM_DRAWITEM: 
            lpdis = (LPDRAWITEMSTRUCT) lParam; 
            hdcMem = CreateCompatibleDC(lpdis->hDC); 
 
            if (lpdis->itemState & ODS_SELECTED)  // if selected 
                SelectObject(hdcMem, hbm2); 
            else 
                SelectObject(hdcMem, hbm1); 
 
            // Destination 
            StretchBlt( 
                lpdis->hDC,         // destination DC 
                lpdis->rcItem.left, // x upper left 
                lpdis->rcItem.top,  // y upper left 
 
                // The next two lines specify the width and 
                // height. 
                lpdis->rcItem.right - lpdis->rcItem.left, 
                lpdis->rcItem.bottom - lpdis->rcItem.top, 
                hdcMem,    // source device context 
                0, 0,      // x and y upper left 
                32,        // source bitmap width 
                32,        // source bitmap height 
                SRCCOPY);  // raster operation 
 
            DeleteDC(hdcMem); 
            return TRUE; 
 
        case WM_COMMAND: 
            if (wParam == IDOK 
                || wParam == IDCANCEL) 
            { 
                EndDialog(hDlg, TRUE); 
                return TRUE; 
            } 
            if (HIWORD(wParam) == BN_CLICKED) 
            { 
                switch (LOWORD(wParam)) 
                { 
                    case IDC_OWNERDRAW: 
 
                        // application-defined processing 
 
                        break; 
                } 
            } 
            break; 
 
        case WM_DESTROY: 
            DeleteObject(hbm1);  // delete bitmaps 
            DeleteObject(hbm2); 
 
            break; 
 
    } 
    return FALSE; 
        UNREFERENCED_PARAMETER(lParam); 
} 


ASM source:
=======================================================================
OwnDrawProc proc hDlg :DWORD , message :DWORD, wParam :DWORD, lParam :DWORD

.data?
        lpdis        DRAWITEMSTRUCT           ; owner drawn items

.data

hbm1 dd 0
;hbm2 dd 0

.code
.if message==WM_INITDIALOG

            ; hinst, hbm1 and hbm2 are defined globally. 
    invoke	LoadBitmap , hinst , "OwnBit1" 
	mov hbm1,eax
;    invoke	LoadBitmap , hinst , "OwnBit2"
;	mov hbm2,eax
            return TRUE 

.elseif message== WM_DRAWITEM
    invoke	CreateCompatibleDC,lpdis.hDC
            mov hdcMem,eax
    invoke	SelectObject,hdcMem, hbm1
			;====================
            ; Destination
            ;====================
             
    invoke	StretchBlt, lpdis.hDC,         	; destination DC 
                		lpdis.rcItem.left,  ; x upper left 
                		lpdis.rcItem.top,   ; y upper left 
                		lpdis->rcItem.right - lpdis->rcItem.left, ; width 
                		lpdis->rcItem.bottom - lpdis->rcItem.top, ; height
                		hdcMem,    			; source device context 
                		0, 0,      			; x and y upper left 
                		32,        			; source bitmap width 
                		32,        			; source bitmap height 
                		SRCCOPY  			; raster operation 

    invoke	DeleteDC,hdcMem
            return TRUE

.elseif message== WM_COMMAND
            .if wParam == IDOK || wParam == IDCANCEL 
             
    invoke	EndDialog,hDlg, TRUE
                return TRUE 
            .endif
            
 			.if ax==
Posted on 2001-02-27 18:38:00 by forge
for all comments you need to put a semicolon ";" in front.. just quickly, the last section : elseif message== WM_DESTROY:              DeleteObject,hbm1    delete bitmaps you need an invoke DeleteObject,hbm1 what sort of error messages are you getting??
Posted on 2001-02-27 20:19:00 by mega
Thanks mega, The missing invoke was just typo. I don't know much about C and C++ not at all. This is why I wonder, if I translate C code which I copy from Win32.hlp to Masm I didn't assemble it as yet. This way I want to prevent pages of error messages. Toolbar32.asm - which incorporates a toolbar into our program... Is it possible to have this toolbar in the client area of the window? P.S. Your heading Toolbar32.asm on your page is pointing to Regi. Thanks a lot again. forge
Posted on 2001-02-27 22:07:00 by forge
1) Your translation of lpdis is wrong. lpdis is a pointer, so it does not have the DRAWITEMSTRUCT type. Instead you should use DWORD or DD. It also means you need to break down lpdis->field to at least two instructions with suitable optimizations.

    mov reg,lpdis
    mov reg,(DRAWITEMSTRUCT PTR ).field
(You pick the 32-bit register for reg.) 2) hdcMem and lpdis should be LOCAL, if you want them to act the same as in the C code. Depending on the way WM_DRAWITEM works, it may or may not be necessary. 3) You did not translate

    lpdis = (LPDRAWITEMSTRUCT) lParam;
4) You will need to break down expressions like "lpdis->rcItem.right - lpdis->rcItem.left" into multiple ASM instructions.
Posted on 2001-02-27 23:14:00 by tank
Thanks tank it helps a lot. I tryied very hard and this is what I think shoud be. I know - I'm probably wrong again. I'll be happy for any help and corection.
 
;---------------------------------------

.elseif message== WM_DRAWITEM
            ;lpdis = (LPDRAWITEMSTRUCT) lParam; 
                       mov edi, lParam
                        assume edi:ptr LPDRAWITEMSTRUCT
mov eax,(DRAWITEMSTRUCT PTR ).hDC

mov lpdis,eax                       ;local
 
    invoke  CreateCompatibleDC,lpdis
            mov hdcMem,eax
    invoke  SelectObject,hdcMem, hbm1
            ;====================
            ; Destination
            ;====================

        mov eax,lpdis.rcItem.right 
        mov edx,lpdis->rcItem.left
        sub eax,edx
        mov x_width,eax                 ; local
        mov eax,lpdis.rcItem.bottom
        mov edx,lpdis.rcItem.top
        sub eax,edx
        mov y_height,eax                ; local
           
    invoke  StretchBlt, lpdis.hDC,          ; destination DC 
                        lpdis.rcItem.left,  ; x upper left 
                        lpdis.rcItem.top,   ; y upper left 
                        x_width,            ; width 
                        y_height,           ; height
                        hdcMem,             ; source device context 
                        0, 0,               ; x and y upper left 
                        32,                 ; source bitmap width 
                        32,                 ; source bitmap height 
                        SRCCOPY             ; raster operation 

    invoke  DeleteDC,hdcMem
            return TRUE
;---------------------------------------    
Is it good translation or bad ??? Thanks for any comment. forge This message was edited by forge, on 2/28/2001 5:26:07 AM
Posted on 2001-02-28 01:11:00 by forge