How does one maintain the Device Context unchanged when, for example, there is a sizeing operation that covers it? Everything disappears... I tried gdiflush, i tried SaveDC restore DC but nothing...Thanks
Create your drawing in an memory DC. While handling WM_PAINT, you can then copy this DC to the screen(-DC).
i get i qword but does that works with LineTo and Arc and all those drawing functions? dont i need to select the object to bitblt it from a backbuffer? Can you show a small example? Thanks
Qword you mean something like:
.if uMsg==WM_PAINT
push hMemDC´
pop pt.hdc
invoke BeginPaint,hWnd,addr pt
invoke EndPaint,hWnd,addr pt
???? HELP
see attachment
Thanks Q.... thanks a lot. Bye and laters
Q? Does it take all that? Why do you Create a Compatible bitmap then select it , then delete the previous object, then paint the currently selected one? I'm not sure i follow....
thanks
The code creates an new DC and selects a bitmap with the current desktop-bit-depth -> this our memory DC, where the drawing goes.
The DeleteObject() is not really needed because the DC is create with an default 1bpp, 1x1pixel bitmap, which can't be deleted.
WndProc proc uses ebx esi edi hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL ps:PAINTSTRUCT
.if uMsg == WM_CLOSE
invoke PostQuitMessage,NULL
.elseif uMsg == WM_DESTROY
invoke DeleteDC,rv(GetWindowLong,hWnd,WND_DATA.hdc)
.elseif uMsg == WM_CREATE
; create memory DC
mov esi,rv(GetDC,rv(GetDesktopWindow))
mov ebx,rv(CreateCompatibleDC,esi)
mov edi,rv(GetSystemMetrics,SM_CXSCREEN)
invoke SelectObject,ebx,rv(CreateCompatibleBitmap,esi,edi,rv(GetSystemMetrics,SM_CYSCREEN))
invoke ReleaseDC,rv(GetDesktopWindow),esi
invoke SetWindowLong,hWnd,WND_DATA.hdc,ebx
; clear DC
invoke BitBlt,ebx,0,0,10000,10000,ebx,0,0,PATCOPY
; draw to the DC
invoke MoveToEx,ebx,0,0,0
invoke LineTo,ebx,1000,1000
invoke LineTo,ebx,0,1000
invoke LineTo,ebx,1000,0
.elseif uMsg == WM_PAINT
invoke BeginPaint,hWnd,ADDR ps
; copy from memory DC to screen (ps.hdc)
mov ebx,rv(GetWindowLong,hWnd,WND_DATA.hdc)
mov edx,ps.rcPaint.right
sub edx,ps.rcPaint.left
mov ecx,ps.rcPaint.bottom
sub ecx,ps.rcPaint.top
invoke BitBlt,ps.hdc,ps.rcPaint.left,ps.rcPaint.top,edx,ecx,ebx,ps.rcPaint.left,ps.rcPaint.top,SRCCOPY
invoke EndPaint,hWnd,ADDR ps
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.endif
xor eax,eax
ret
WndProc endp
Thanks a lot Q... It worked in my little gismo. I'll post it when i have something decent.... Thanks once more.
All Hail MASM32 Forum....!!!
Actually i came across another problem Qword. The draw comes only in black and white. Can you showme how to fix it? Do i need something instead of PATPAINT when creating the CompatibleBitmap or is it in WM_PAINT? Thanks
Quote from: xandaz on July 31, 2011, 05:32:08 PMThe draw comes only in black and white.
Probably you pass the DC from CreateCompatibleDC() directly to CreateCompatibleBitmap() - this cause creation of a monochrome bitmap. You must use a DC with a higher bit depth (e.g. the desktop DC) -> see my previous example.
[You may show us your code]
This is the drawing gismo im working on qw. I tried using the desktop dc to use a higher depth as in your example but still nothing.
you need to replace hMemDC in line 255 with hDC.
I've seen, that you do not delete object returned by SelectObject().
right .... that works . ty qw. I wonder if i'm ever going to fully understand this stuff. thanks
I've played a bit with you code - maybe it helps you.
qWord
Well thanks qword.... this is what i had done. I see that some of what you added is kind of better than what i did. I counldnt go around the region stuff when it relatesto filled spheres and also your segments work better than mine. You select a standing point and then grow the segement to wherever the mouse is going. Its good. Thanks a lot. See my stuff pls and say what you think.
I'm trying to understand why some of the figures dont stick to the DC. I don't fully understand what you did in xandaz_paint. Why does it take all those DC's. I took what i think to understand of the things you did. I created an alternate DC to draw the figures and then redraw the bitmap so that theres no dragging when a specific figure is growing. look at q.
I'd also like to say that you're pretty good at this Qw.
Thanks and best regards.
hi,
while handling WM_PAINT,you must use TransparentBlt() to draw the preview (hTDC) to the screen. When the right mouse button releases (WM_LBUTTONUP), it is necessary to merge the preview layer hTDC with the memory DC hMemDC - this must also done using TransparentBlt(). After merging, the preview layer hTDC must cleared with the transparent color and the window must be invalidtaed.
Also:
- you do not delete object, if not longer needed (CreatePen)
- the BitBlt,..,10000,... was only example - you should use the bitmap's size.
- genrally: stay away from global variables - especially in context to your MDI stuff.
qWord
Qw... i'm really sorry for being so presistent. What do is to merge the bitmap in hTDC with hMemDC using transparent blt and then the bitmap in hTDC using the transparent color which should be the color actually being used to draw right? I was looking at your example and it is very complicated to understand. Thanks for all the help Q.
Best regards from X. :U
hi,
in the attachment a simpler example with comments.
thanks a lot Qw. I'll check it out. ty ty and nite
well....thanks Q. It was hard to understand but things are finally settling down. Thanks a lot.