News:

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

Graphics, Coordinate systems, etc. questions

Started by Jimg, May 07, 2007, 04:53:49 PM

Previous topic - Next topic

Jimg

Thank you for your time and patience, Tedd, that helped a lot.


"mov mctrlhDC,eax  ;** you should release a DC you didn't create once you've finished with it - they can change!"

Well, I certainly misread that one.  The first line of the description of GetDC says -
"The GetDC function retrieves a handle of a display device context (DC) for the client area of the specified window."
Which I took to mean I was just getting the handle of THE existing DC, not creating one.
So, can I create one CompatibleDC that will be valid throughout the lifetime of the control, or is this compatibility going to change also?

"
    mov eax,lParam  ;**
    mov edx,eax     ;**
    and eax,0ffffh  ;** width
    shr edx,16      ;** height
    ;movzx eax,word ptr lParam       ; get the new size of the control to make a new bitmap
    mov mctrlWidth,eax
    ;movzx eax,word ptr [lParam+2]
    mov mctrlHeight,edx ;**
"
Gee, when I realized I could access these word values directly this way, I thought it was really "neat".


"    ;** seems like a long way to do it - create the new one, select it in, then delete the old one that's returned"
yeah, I was just trying to avoid having both in existence at once.


Got it for the bitblt-
        inv GetDC,hCurGrid     ; get the DC of the control
        mov mctrlhDC,eax       ; get temp handle to control
        inv BitBlt,mctrlhDC, X1, Y1, eax, edx, mhDC, X1, Y1, SRCCOPY  ; copy directly to parent screen
          inv ReleaseDC,hCurGrid,mctrlhDC

Anyway, once I see that the handle to the control dc is transitory, everything else is obvious.  Thanks again Tedd--




Tedd

Quote from: Jimg on May 24, 2007, 02:55:09 PM
Thank you for your time and patience, Tedd, that helped a lot.
No problem, that's what we're here for :bg

Quote
"mov mctrlhDC,eax  ;** you should release a DC you didn't create once you've finished with it - they can change!"

Well, I certainly misread that one.  The first line of the description of GetDC says -
"The GetDC function retrieves a handle of a display device context (DC) for the client area of the specified window."
Which I took to mean I was just getting the handle of THE existing DC, not creating one.
So, can I create one CompatibleDC that will be valid throughout the lifetime of the control, or is this compatibility going to change also?
Nooo, you had it right - GetDC does return the DC of the window you asked for. "you should release a DC you didn't create, once you've finished with it"
But the point is: it's not your DC, you don't have control of it, so you shouldn't assume anything about it - including how long it will last, and therefore how long you can hold onto it. So you should release it once you're finished with it (because it's not yours to 'keep.') Window DCs do appear to change for some reason, probably as part of the GDI managing its resources.
On the other hand, the Compatible-DC that you actually create is yours to do with as you wish (it's a 'memory DC' not a 'window DC') - keep it as long as you like (the 'compatible' part just means it has the same colour-depth and attributes as the other one, but apart from that you don't really need the other one.) So yes, you create your own DC (that's compatible with that window's one - so it looks okay when you bitblt to it) and just keep it as a block of memory, until you throw it away at the end of your program.

Quote
"    mov eax,lParam  ;**
    mov edx,eax     ;**
    and eax,0ffffh  ;** width
    shr edx,16      ;** height
    ;movzx eax,word ptr lParam       ; get the new size of the control to make a new bitmap
    mov mctrlWidth,eax
    ;movzx eax,word ptr [lParam+2]
    mov mctrlHeight,edx ;**
"
Gee, when I realized I could access these word values directly this way, I thought it was really "neat".
Well yes, it is :wink But a 32-bit machine treats 16-bit operations as awkward - it actually has to get the dword twice and then mask off the bits you don't want (behind the scenes) - so it's best to just get the whole thing in one go and separate them yourself.
No snowflake in an avalanche feels responsible.

Jimg

QuoteBut a 32-bit machine treats 16-bit operations as awkward - it actually has to get the dword twice and then mask off the bits you don't want (behind the scenes) - so it's best to just get the whole thing in one go and separate them yourself.
Yeah, 4 and a half times slower on my computer---

And I'm amazed at how much faster it is to use fillrect with a brush rather than drawing with a pen.  And using fillrect, you don't need to keep doing selectobjects.  So if you only need simple vertical or horizontal lines like I do, it's much better to use fillrect!



[attachment deleted by admin]