News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

EndPaint placement

Started by dc, June 09, 2017, 06:26:39 AM

Previous topic - Next topic

dc

if i put the EndPaint at the end of the paint msg handler, i cant paint anymore in later paint msg handling???
if i put it in destroy handler, painting gets slower and slower till it crashes...

msg==Create
LoadBmp's     ;     hBmp[n]...

msg==Paint
BeginPaint   ;    hdc
CreateCompatableDC    ;    hdc1
CreateCompatableDC    ;    hdc2
CreateCompatableBmp    ;   hbmp1
SelectObj hdc1, hbmp1
SelectObj hdc2, hbmp[n]
BitBlt hdc1, hdc2      ;      n times...
bitBlt hdc, hdc1
SelectObj DC's, old
DeleteObj hbmp1
DeleteDC    hdc1
DeleteDC    hdc2
EndPaint

msg==Destroy
DeleteObj's   hBmp[n]

is this the wrong order?

thanx.... been a while.... :)

dc

also the new windows update killed my help system, is there a fix for that?

jj2007



dc

http://masmforum.com/~masm32/board/Smileys/mforum/greenclp.gif
thanx, my world is nomalizing now
except - my main drawing routine still doesn't work
is beginpaint and endpaint not for main bitmap flipping?
thanx again
dc

jimg

Your code doesn't look like any kind of assembly language I am familiar with, so it's hard to say.  BeginPaint and EndPaint have parameters.  Your problem could be with any one of your statements.
Maybe give us some actual code to look at.

dc

ok, here's a little more detail:
WndProc Proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL ps:PAINTSTRUCT
;====================================CREATE========================
    .If uMsg==WM_CREATE
        invoke LoadBmps
;=====================================PAINT==========================
    .ElseIf uMsg==WM_PAINT 
        invoke BeginPaint,hWnd,addr ps
        mov hdc, eax
        invoke CreateCompatibleDC, hdc
        mov hdcCH, eax
        invoke CreateCompatibleDC, hdc
        mov hdcP, eax
        invoke CreateCompatibleBitmap, hdc, wX, wY
        mov hBmpP, eax
        invoke SelectObject, hdcP, hBmpP
        mov oldP, eax
        invoke SelectObject, hdcCH, hBmps[0]
        mov oldCH, eax
;----------------------------start up screen fill--------
        .if !sFlag ; stretchBlt's to memDC and
            invoke NewBoard ; bitblt to windowDC
;------------------------------------flop--------------------------
        .elseif flop
            invoke Flop, hWnd ; stretchBlt's to windowDC
        .endif
;---------------------------------clean up-----------------------
        invoke EndPaint,hWnd,addr ps
        invoke SelectObject, hdcCH, oldCH
        invoke DeleteDC, hdcCH
        invoke SelectObject, hdcP, oldP
        invoke DeleteDC, hdcP
        invoke DeleteObject, hBmpP
;==========================================MOUSE CLICK======================================
    .ElseIf uMsg==WM_LBUTTONUP
        mov eax, lParam
        mov loWd, ax    ;   x
        shr eax, 16     ;   hiWd    y
        div sXY
        mov nsY, eax    ;   current sqare Y
        mul twentyfour
        mov temp, eax
        mov ax, loWd
        div sXY
        mov nsX, eax    ;   current square X
        add eax, temp   ;   new current index (XY)
        .if nsX !=0 && nsX !=23 && nsY !=0 && nsY !=17   ;   on edge?
            mov edx, eax
            shl edx, 2
            mov eax, brd[edx]
            and eax, 1
            jne @F
            mov brd[edx], 1
            m2m flip.hBMP, hBmps[00100b]
            jmp dun
    @@:     mov brd[edx], 0
            m2m flip.hBMP, hBmps[00b]
    dun:    mov eax, nsY
            mul sXY
            mov flip.Y, eax
            mov eax, nsX
            mul sXY
            mov flip.X, eax
            mov eax, temp
            mov eax, brd[eax]
            mov flop, 1     ;   flag tells PAINT to change a square
            invoke SendMessage, hWnd, WM_PAINT, 0, 0    ;   trigger PAINT
        .endif
;==============================================DESTROY===================================
    .ElseIf uMsg==WM_DESTROY
        invoke DeleteObject,hBmpe00
        invoke DeleteObject,hBmpe01
        invoke DeleteObject,hBmpe10
        invoke DeleteObject,hBmpe11
        invoke DeleteObject,hBmpc1
        invoke DeleteObject,hBmpc2
        invoke DeleteObject,hBmpc3
        invoke DeleteObject,hBmpc4
        mov ebx, 0
        .while ebx < 400h
        .if hBmps[ebx]
            invoke DeleteObject,hBmps[ebx]
        .endif
            add ebx, 4
        .endw
       
        invoke PostQuitMessage,NULL


jimg

I don't see anything obvious, but then I haven't done any of this type of stuff for many years.  Perhaps someone else will have an idea.

aw27

Quote from: dc on June 10, 2017, 02:27:08 AM
ok, here's a little more detail:
It is the best approach, just on a need to know base, otherwise someone can steal our hard work  :lol:

dc

once the endPaint happens, i cant paint anymore????
if I put it in the destroy it works till it crashes, slower and slower tho

hutch--

Time to learn your basic architecture, it has worked the same way since Win3.?

    .elseif uMsg == WM_PAINT
        invoke BeginPaint,hWin,ADDR Ps
          mov hDC, eax
        ; ----------------------------------------
          ; do what you need to do here.

          ;;;; invoke Paint_Proc,hWin,hDC


        ; ----------------------------------------
        invoke EndPaint,hWin,ADDR Ps
        return 0

jj2007

Strange, Hutch, what you posted looks almost exactly like that paragraph in the Petzold book ::)

avcaballero

It is not strictelly necessary to paint inside WM_PAINT, but it is the standard way, and you can meet some inconveniences if you don't do in this way. In OSs before W7 the Client Area would be automatically cleaned (invalidated) when you minimize or overlap your window with other, for example.

The example attached runs ok in my W7 64 bits, but who knows in another one ??

Here is another example that paints over the desktop with no callback WndProc at all in the program, to exit from it you would open the task manager and kill the process if you run it, BE WARNED named something like "CalW?01".

hutch--

 :biggrin:

> Strange, Hutch, what you posted looks almost exactly like that paragraph in the Petzold book

He probably got it from the same place that I did, the original SDK help file for WM_PAINT and BeginPaint and EndPaint. Many things in software are creative but OS functions are not, either do it the right way or it won't work properly. Still, you can't tell 'em so let it explode in their face so they learn the hard way.  :badgrin:

dc

in this code, it goes through the code but after the first draw, it wont anymore
thanx again,
dc