flat assembler
Message board for the users of flat assembler.

Index > Windows > Having difficulty understanding invalidation and painting

Thread Post new topic Reply to topic

Joined: 01 Apr 2006
Posts: 55
Location: Northern Ireland
moriman 03 Aug 2006, 21:16
I am trying to understand how the WM_PAINT supplies the update area.

If my reading is correct, then when BeginPaint is called, eax is the DC for the window and the PAINTSTRUCT should contain the update area in the [PAINTSTRUCT.rcPaint] RECT.

I assumed that if I call InvalidateRect then the [PAINTSTRUCT.rcPaint] rectangle should be the same as that passed by the Invalidate call. The code below seems to show that this isn't the case.

What the code below does is create a window and calculate the RECTs for 2 internal rectangles. When the mouse is clicked within the client area, a subroutine invalidates the first of these rectangles. However, when I check the PAINTSTRUCT after BeginPaint, it doesn't contain the coordinates set by InvalidateRect.

Any insight into what I am doing wrong or misunderstanding would be greatly appreciated.

many thanks


format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

section '.code' code readable executable

        invoke  GetModuleHandle,0
        mov     [wc.hInstance],eax
        invoke  RegisterClass, wc
        invoke  CreateWindowEx,0,myClass,myTitle,WS_VISIBLE+WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, 700, 400, NULL, NULL, [wc.hInstance],NULL
        mov     [hWndMain], eax
        invoke  InitCommonControls
        invoke  GetCurrentProcess
        mov     [hProcess], eax
        invoke  GetMessage,msg,NULL,0,0
        or      eax,eax
        jz      end_loop
        invoke  TranslateAccelerator, [hWndMain], [hAccel], msg
        or      eax, eax
        jnz     msg_loop
        invoke  IsDialogMessage, [hWndMain], msg
        or      eax, eax
        jnz     msg_loop
        invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
        jmp     msg_loop
        invoke  ExitProcess,[msg.wParam]

proc wndProc hwnd,wmsg,wparam,lparam
        push    ebx esi edi
        cmp     [wmsg],WM_DESTROY
        je      .wmDESTROY
        cmp     [wmsg],WM_CREATE
        je      .wmCREATE
        cmp     [wmsg], WM_PAINT
        je      .wmPAINT
        cmp     [wmsg], WM_LBUTTONUP
        je      .wmLBUTTONUP
        invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
        jmp     .wmBYE
    .wmLBUTTONUP:       ;left mouse button has been clicked.
        mov     eax, [hwnd]
        call    DrawWindows
        jmp     .wmBYE
        invoke  CreatePen, PS_SOLID, NULL, 0x00FFFFFF
        mov     [WhitePen], eax
        invoke  CreateSolidBrush, 0x00FFFFFF
        mov     [WhiteBrush], eax
        invoke  GetClientRect, [hwnd], rect
        call    GetReRects
        jmp     .wmBYE
        invoke  PostQuitMessage,0
        xor     eax,eax
        mov     eax, [hwnd]
        call    UpdateReIn
        jmp     .wmDEFAULT
        pop     edi esi ebx

        push    eax
        invoke  InvalidateRect, eax, rectIn, TRUE
        pop     eax
        invoke  UpdateWindow, eax

        push    eax
        invoke  BeginPaint, eax, ps
        mov     [myDC], eax
        invoke  EqualRect, rectIn, [ps.rcPaint] ;check if update region is rectIn
        or      eax, eax
        jz      @f
        pop     eax
        invoke  EndPaint, eax, ps

GetReRects:                     ;calculates co-ords of 2 rectangles within client region.
                                ;rect is the client area
                                ;rectIn is same height as rect but half the width - 2 pixels left side starting at [rect.left]
                                ;rectOut is same height and width as rectIn with left side starting at [rectIn.right]+4
        push    eax ecx edi esi
        mov     edi, rectIn
        mov     esi, rect
        mov     ecx, 4
        rep     movsd
        shr     [rectIn.right], 1
        sub     [rectIn.right], 2
        push    [rectIn.right]
        pop     [rectOut.left]
        add     [rectOut.left], 4
        push    [rectIn.top]
        pop     [rectOut.top]
        push    [rect.right]
        pop     [rectOut.right]
        push    [rect.bottom]
        pop     [rectOut.bottom]
        pop     esi edi ecx eax

section '.data' data readable writeable

myDC                    dd ?
ps                      PAINTSTRUCT
WhiteBrush              dd ?
WhitePen                dd ?
hWndMain                dd ?
hProcess                dd ?
hAccel                  dd ?
wc                      WNDCLASS 0, wndProc, 0, 0, NULL, NULL, NULL, COLOR_BTNFACE+1, M_MAIN, myClass
ErrStrBuff              dd ?
myClass                 db 'Test', 0
myTitle                 db 'Test', 0
M_MAIN                  = 2000
MI_START                = 2001
rect                    RECT
rectIn                  RECT
rectOut                 RECT
msg                     MSG

section '.idata' import data readable writeable

library kernel32,'KERNEL32.DLL',\
        user32,  'USER32.DLL',\
        gdi32,   'GDI32.DLL',\

include '%fasminc%\apia\Kernel32.inc'
include '%fasminc%\apia\User32.inc'
include '%fasminc%\apia\Gdi32.inc'
include '%fasminc%\apia\Comdlg32.inc'
include '%fasminc%\apia\Advapi32.inc'
include '%fasminc%\apia\Comctl32.inc'

section '.rsrc' resource data readable
directory \
        RT_MENU, menus

resource menus,\

menu main_menu
     menuitem  '&File', 0, MFR_POPUP+MFR_END
     menuitem           '&Start', MI_START, MFR_END
Post 03 Aug 2006, 21:16
View user's profile Send private message Reply with quote

Joined: 05 Nov 2005
Posts: 86
daluca 21 Aug 2006, 00:58
Hi, I don't know much about this topic but i saw the EqualRect documentation
and it takes two pointers to RECT structures and you:

        push    eax 
        invoke  BeginPaint, eax, ps 
        mov     [myDC], eax 
        invoke  EqualRect, rectIn, [ps.rcPaint] ;check if update region is rectIn 
        or      eax, eax 
        jz      @f 

provide a pointer to one:rectIn and the contents of the other:[ps.rcPaint]
I think it should be just:
invoke  EqualRect, rectIn, ps.rcPaint

I don't know if this solves anything.
Post 21 Aug 2006, 00:58
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.