Announcement

Collapse
No announcement yet.

WM_PAINT for single control in DDT callback

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • WM_PAINT for single control in DDT callback

    i am drawing graphics on a static control in a ddt dialog, which has other controls
    that are looked after by ddt itself. what is the correct way to process the wm_paint
    message in the dialog's callback procedure?

    pseudocode:
    Code:
    callback function mydlgproc
      
      select case cbmsg
        ...
        case %wm_paint
          control handle cbhndl, %idstatic to hstatic
          hdc=beginpaint(hstatic,lppaint)
              ....   gdi drawing commands using hdc
          endpaint hstatic,lppaint
          function=???
    
      end select
    end function
    in lance's example at:
    http://www.powerbasic.com/support/pb...ead.php?t=1625

    he puts function=1 to stop ddt doing its own wm_paint processing, but in that
    example he has updated the whole dialog - there are no other controls.
    in my case, function=1 stops ddt from drawing its own buttons.

    the problem i get is that sometimes my graphics control comes out plain grey
    (particularly after a screen save). this is probably because ddt has done its
    screen update first and has validated the entire dialog area, leaving my beginpaint
    routine no remaining unvalidated areas on which to draw. conversely, if i get
    to draw first, my endpaint validates my static control, usually preventing ddt
    from painting over it.

    how do i get my wm_paint to run before ddt paints the remainder of the dialog?
    should i use getdc in place of beginpaint?

    regards, simon

  • #2
    Simon,

    You should subclass the static control and allow it to paint itself.
    By doing it the above method, you will need to add some additional styles
    to the Parent and child controls, like %WS_CLIPCHILDREN, %WS_CLIPSIBLINGS.
    This sets some clipping regions for you when you use the above wm_paint
    handler. If that doesn't work using the above method, they you will need
    to refresh each control by doing a SetWindowPos with the NOMOVE flag.
    I think it would be much cleaner if you subclass the static control.

    HTH
    Regards,
    Jules


    Best regards
    Jules
    www.rpmarchildon.com

    Comment


    • #3
      Thanks, Jules

      I already had %WS_CLIPCHILDREN in the style of the static control used for drawing,
      but adding this to the style in the DIALOG NEW statement has cured the
      probem most of the time. Sometimes DDT doesn't update the remainder of the dialog
      properly, presumably because my BeginPaint/EndPaint has validated the entire dialog,
      so DDT and Windows think it has all been done.

      I guess I have to subclass to do the job properly, as you suggest.

      Regards, Simon

      Comment


      • #4
        In case anyone is interested, the following (pseudo)code seems to work:
        Code:
        CALLBACK FUNCTION MyDlgProc
          SELECT CASE CBMSG
            ...    
            CASE %WM_PAINT
              RedrawWindow CBHNDL, BYVAL %Null, BYVAL %Null, _
                %RDW_NOINTERNALREPAINT OR %RDW_VALIDATE OR %RDW_UPDATENOW
                'redraw and validate whole dialog without generating a fresh WM_PAINT message   
              CONTROL HANDLE CBHNDL, %IDstatic TO hStatic
              hDC=GetDC (hStatic)  
                 'redraw my picture control
                  ....   GDI drawing commands using hDC
              ReleaseDC hStatic,hDC
              FUNCTION=%True   'tell DDT not to do its own repaint
          END SELECT
        END FUNCTION
        This is rather messy, so sub-classing would probably be better as Jules says.

        This must be quite a common requirement (a GDI picture on a DDT dialog). Has
        anyone got any better code?

        Regards, Simon


        P.S. The above code does not work in all circumstances. I do not recommend
        using it (and neither does Lance ).


        [This message has been edited by Simon Morgan (edited June 04, 2001).]

        Comment

        Working...
        X