News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

TEXTOUT Question

Started by 44mag, April 03, 2012, 06:16:41 AM

Previous topic - Next topic

MichaelW

The problem is with partial redraws and the location of the code that exchanges the values. If I move the code that exchanges the values to WM_KEYDOWN handler then the values don't get exchanged during the partial redraws and the problem goes away. Compile this as a console app:

;==============================================================================
    include \masm32\include\masm32rt.inc
;==============================================================================
    .data
        XX      dd          123456789
        YY      dd          12
        ps      PAINTSTRUCT <>
    .data?
        buffer  db          128 dup(?)
    .code
;==============================================================================

DlgProc proc uses ebx hwndDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

    SWITCH uMsg

      CASE WM_PAINT

        invoke BeginPaint, hwndDlg, ADDR ps
        printf("%d\t",ps.rcPaint.left)
        printf("%d\t",ps.rcPaint.top)
        printf("%d\t",ps.rcPaint.right)
        printf("%d\n",ps.rcPaint.bottom)
        invoke dwtoa,XX,ADDR buffer
        invoke TextOut,ps.hdc,10,100,ADDR buffer,len(ADDR buffer)
        invoke dwtoa,YY,ADDR buffer
        invoke TextOut,ps.hdc,10,200,ADDR buffer,len(ADDR buffer)
        invoke EndPaint, hwndDlg, ADDR ps

      CASE WM_KEYDOWN

        mov eax, XX
        mov edx, YY
        mov XX, edx
        mov YY, eax

        invoke InvalidateRect,hwndDlg,NULL,TRUE
        invoke UpdateWindow,hwndDlg

      CASE WM_CTLCOLORDLG

        invoke GetStockObject, WHITE_BRUSH
        return eax

      CASE WM_COMMAND

        SWITCH wParam

          CASE IDCANCEL

            invoke EndDialog, hwndDlg, 0

        ENDSW

      CASE WM_CLOSE

        invoke EndDialog, hwndDlg, 0

    ENDSW

    return FALSE

DlgProc endp

;==============================================================================
start:
;==============================================================================

    Dialog "Test", "MS Sans Serif",10, \
           WS_OVERLAPPEDWINDOW or DS_CENTER, \
           0,0,0,200,150,1024

    invoke GetModuleHandle, NULL

    CallModalDialog eax,0,DlgProc,NULL

    exit

;==============================================================================
end start

eschew obfuscation

dedndave

in the code i posted earlier, i also put the dwtoa calls in the key handler
no need for that overhead in paint

44mag

Wow I think I like that len(addr buffer) trick, seems to work better now, thanks MichaelW!