moriman
Joined: 01 Apr 2006
Posts: 55
Location: Northern Ireland
|
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
mori
format PE GUI 4.0
entry start
include '%fasminc%\win32a.inc'
section '.code' code readable executable
start:
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
msg_loop:
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
end_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
.wmDEFAULT:
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
jmp .wmBYE
.wmLBUTTONUP: ;left mouse button has been clicked.
mov eax, [hwnd]
call DrawWindows
jmp .wmBYE
.wmCREATE:
invoke CreatePen, PS_SOLID, NULL, 0x00FFFFFF
mov [WhitePen], eax
invoke CreateSolidBrush, 0x00FFFFFF
mov [WhiteBrush], eax
invoke GetClientRect, [hwnd], rect
call GetReRects
jmp .wmBYE
.wmDESTROY:
invoke PostQuitMessage,0
xor eax,eax
.wmPAINT:
mov eax, [hwnd]
call UpdateReIn
jmp .wmDEFAULT
.wmBYE:
pop edi esi ebx
ret
endp
DrawWindows:
push eax
invoke InvalidateRect, eax, rectIn, TRUE
pop eax
invoke UpdateWindow, eax
ret
UpdateReIn:
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
int3
@@:
pop eax
invoke EndPaint, eax, ps
ret
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
ret
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',\
comdlg32,'COMDLG32.DLL',\
advapi32,'ADVAPI32.DLL',\
comctl32,'COMCTL32.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,\
M_MAIN, LANG_ENGLISH + SUBLANG_DEFAULT, main_menu
menu main_menu
menuitem '&File', 0, MFR_POPUP+MFR_END
menuitem '&Start', MI_START, MFR_END
|