News:

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

How to keep the Device Context unchanged?

Started by xandaz, July 26, 2011, 04:33:25 PM

Previous topic - Next topic

xandaz

   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

qWord

Create your drawing in an memory DC. While handling WM_PAINT, you can then copy this DC to the screen(-DC).
FPU in a trice: SmplMath
It's that simple!

xandaz

   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

xandaz

   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

qWord

FPU in a trice: SmplMath
It's that simple!

xandaz

    Thanks Q.... thanks a lot. Bye and laters

xandaz

    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

qWord

#7
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
FPU in a trice: SmplMath
It's that simple!

xandaz

    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....!!!

xandaz

    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

qWord

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]
FPU in a trice: SmplMath
It's that simple!

xandaz

   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.

qWord

you need to replace hMemDC in line 255 with hDC.
I've seen, that you do not delete object returned by SelectObject().
FPU in a trice: SmplMath
It's that simple!

xandaz

    right .... that works . ty qw. I wonder if i'm ever going to fully understand this stuff. thanks

qWord

I've played a bit with you code -  maybe it helps you.

qWord
FPU in a trice: SmplMath
It's that simple!