Author Topic: EndPaint placement  (Read 1170 times)

dc

  • Regular Member
  • *
  • Posts: 18
EndPaint placement
« on: June 09, 2017, 06:26:39 AM »
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

  • Regular Member
  • *
  • Posts: 18
Re: EndPaint placement
« Reply #1 on: June 09, 2017, 06:33:28 AM »
also the new windows update killed my help system, is there a fix for that?

jj2007

  • Member
  • *****
  • Posts: 7558
  • Assembler is fun ;-)
    • MasmBasic
Re: EndPaint placement
« Reply #2 on: June 09, 2017, 06:56:16 AM »

jimg

  • Member
  • **
  • Posts: 191
Re: EndPaint placement
« Reply #3 on: June 09, 2017, 10:29:49 AM »

dc

  • Regular Member
  • *
  • Posts: 18
Re: EndPaint placement
« Reply #4 on: June 10, 2017, 01:32:00 AM »
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

  • Member
  • **
  • Posts: 191
Re: EndPaint placement
« Reply #5 on: June 10, 2017, 01:56:15 AM »
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

  • Regular Member
  • *
  • Posts: 18
Re: EndPaint placement
« Reply #6 on: June 10, 2017, 02:27:08 AM »
ok, here's a little more detail:
Code: [Select]
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

  • Member
  • **
  • Posts: 191
Re: EndPaint placement
« Reply #7 on: June 10, 2017, 11:16:35 AM »
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

  • Member
  • ****
  • Posts: 709
Re: EndPaint placement
« Reply #8 on: June 10, 2017, 02:43:57 PM »
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

  • Regular Member
  • *
  • Posts: 18
Re: EndPaint placement
« Reply #9 on: June 10, 2017, 02:53:41 PM »
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--

  • Administrator
  • Member
  • ******
  • Posts: 4813
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: EndPaint placement
« Reply #10 on: June 10, 2017, 06:28:20 PM »
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
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

jj2007

  • Member
  • *****
  • Posts: 7558
  • Assembler is fun ;-)
    • MasmBasic
Re: EndPaint placement
« Reply #11 on: June 10, 2017, 06:38:45 PM »
Strange, Hutch, what you posted looks almost exactly like that paragraph in the Petzold book ::)

caballero

  • Member
  • ****
  • Posts: 760
    • Abre Ojos Ensamblador
Re: EndPaint placement
« Reply #12 on: June 11, 2017, 01:40:15 AM »
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".
En un lugar de la Mancha de cuyo nombre no quiero acordarme

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4813
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: EndPaint placement
« Reply #13 on: June 11, 2017, 02:38:24 AM »
 :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:
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

dc

  • Regular Member
  • *
  • Posts: 18
Re: EndPaint placement
« Reply #14 on: June 12, 2017, 05:57:56 AM »
in this code, it goes through the code but after the first draw, it wont anymore
thanx again,
dc