The MASM Forum

General => The Workshop => Topic started by: zedd151 on September 21, 2022, 03:59:58 AM

Title: WM_PAINT test piece
Post by: zedd151 on September 21, 2022, 03:59:58 AM

I think I've got this coded correctly... :biggrin:
Code: [Select]
      .elseif uMsg == WM_PAINT
        invoke BeginPaint, hWin, addr ps
        mov hDC, eax
       
        invoke CreateCompatibleDC, hDC
        mov mDC, eax
       
        invoke CreateCompatibleBitmap, hDC, cwidth, cheight
        mov hBmp, eax
       
        invoke SelectObject, mDC, hBmp
        mov hOld, eax


        ;; this is the part that I usually miss... :P
        invoke BitBlt, mDC, 0, 0, cwidth, cheight, hDC, 0, 0, SRCCOPY
       
        ;; drawing functions called here
        ;; ----------------------------


        invoke FillRect, mDC, addr back_rect, hBlackBr ;; draw grid background
        invoke FillRect, mDC, addr innr_rect, hWhiteBr ;; used only for demo
       
        ;; ----------------------------
        invoke BitBlt, hDC, 0, 0, cwidth, cheight, mDC, 0, 0, SRCCOPY

        invoke DeleteObject, hBmp               

        invoke SelectObject, mDC, hOld
       
        invoke DeleteDC, mDC
       
        invoke EndPaint, hWin, addr ps
I usually miss a detail  :rolleyes: here in WM_PAINT but I think I've nailed it here. :cool: If I've missed any steps, lemme know.

edit = change the attachment gdi bug, now fixed
Title: Re: WM_PAINT test piece
Post by: TimoVJL on September 21, 2022, 04:17:55 AM
I prefer to keep WM_PAINT minimal, so only BitBlt bitmap and update bitmap outside WM_PAINT

Title: Re: WM_PAINT test piece
Post by: zedd151 on September 21, 2022, 05:48:30 AM

I prefer to keep WM_PAINT minimal
Me too, and WndProc in general as well. The code example posted was only for others to verify that I had not missed any steps in WM_PAINT.
Quote from: TimoVJL
so only BitBlt bitmap and update bitmap outside WM_PAINT
Good plan.
But attaching C code? :tongue: NoCforMeEither lol.
Luckily translation from C to ASM not so difficult. I got the gist of what the code was doing, and I checked in olly to be sure.
Title: Re: WM_PAINT test piece
Post by: NoCforMe on September 21, 2022, 06:16:55 AM
Luckily translation from C to ASM not so difficult.

C--> ASM not hard at all. C++ difficult or impossible (without a set of "flat" functions).
Title: Re: WM_PAINT test piece
Post by: zedd151 on September 21, 2022, 11:57:40 AM
The original test piece was flawed. Must have been a copy/paste (variable) error on my part. jj discovered the gdi leak bug in the sudoku thread. Good thing it was found, as this would have been the basis for my Basic Window template code. (without the sudoku related code of course, but including the base WM_PAINT code) If that happened it would have propagated through my next ??? number of projects.  :toothy:  Thanks, jj
Title: Re: WM_PAINT test piece
Post by: TimoVJL on September 21, 2022, 01:06:46 PM
Some info
http://winprog.org/tutorial/bitmaps.html