Announcement

Collapse

Maintenance

The forum could be offline for 30-60 minutes in the very near future for maintenance (said 3pm Pacific). I was behind on getting this notice. I do apologize.
See more
See less

Repainting a window

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

  • Repainting a window

    How does one get a window to be repainted properly?

    This dialog is the top one where the action takes place:

    Style& = %WS_POPUP Or _
    %WS_BORDER Or _
    %DS_NOFAILCREATE Or _
    %WS_VSCROLL 'Or _ %WS_CLIPCHILDREN

    Dialog New hDlg&, "", 7, 45, 407, 240, Style& To sDlg&

    In the sub-class procedure for all textboxes on this dialog, I
    am attempting to cause the ENTER key to move down all controls
    below this point, and then insert a new textbox directly below
    the one with the focus. It works very well, only some of the
    moved-down labels/textboxes get slightly mangled in the process.
    Dragging the thumb of the scrollbar right up and or down to move
    them out of sight and back again does the trick - the bad areas
    are now properly repainted. WNDW is the name of a global RECT.
    (All of this is in a DLL, not an EXE)

    Can someone help, please?

    Case %WM_KEYDOWN
    CtlID&=GetDlgCtrlID(hWnd&)
    nsc&=1

    Select Case wParam&

    Case %VK_RETURN
    If CtlID&<Descr& Then Exit Select
    Array Scan Mva&(1) For mvc&, =CtlID&, To n& 'Mva&() hold the ID's of ALL
    Control Get Size sDlg&, Mva&(n&) To x1&, mvi& 'controls on the dialog
    Control Get Loc sDlg&, Mva&(n&) To x0&, y0& 'Get its coordinates, then
    For i&=mvc& To n&+1 Step -1 'move down all controls below
    Control Get Loc sDlg&, Mva&(i&) To x&, y&
    Control Set Loc sDlg&, Mva&(i&), x&, y&+mvi&
    Next

    m&=NextNo 'Get (next) ID for new textbox
    Control Add TextBox, sDlg&, m&, "Jack-in-the=box", x0&, y0&+mvi&, x1&, mvi&, TbxStyle&
    If mva&(n&)<DptBgn&-1001 Then Control Send sDlg&, m&, %WM_SETFONT, mnFont&, 1
    Incr mvc&
    Array Insert mva&(n&+1), m& 'Insert new item ID in list
    ti&=ti&+mvi&
    iVscrollMax = ti&/15 'Update scrollrange
    Call SetScrollRange (sDlg&, %SB_VERT, 0, iVscrollMax, %TRUE)
    Dialog Get Loc sDlg& To xL&, yT&
    Dialog Get Size sDlg& To xW&, yD& 'Here starts the various efforts
    w&=CreateRectRgn (xL&, yT&, xL&+xW&-1, yT&+yD&-1) 'to force repainting
    Cx&=GetDlgItem (sDlg&, w&)
    wndw.nleft=xL&
    wndw.ntop=yT&
    wndw.nright=xL&+xW&-1
    wndw.nbottom=yT&+yD&
    Call InvalidateRect(sDlg&, wndw, %True)
    ' Call RedrawWindow(sDlg&, wndw, Cx&, %RDW_ERASE Or %RDW_INVALIDATE Or RDW_ALLCHILDREN)
    Call UpdateWindow (sDlg&)



    ------------------

  • #2
    Labels are easy:

    InvalidateRect hWndLabel, ByVal 0&, 0 (or 1)

    You updated the dlg wich might not help?


    ------------------
    [email protected]
    hellobasic

    Comment


    • #3
      Thanks, E.B. -- it does work as you suggest.

      The strange thing here is that in terms of screen appearance and
      speed, it is better to actually END the dialog and REBUILD it as
      amended! This is probably due to characteristics of the Windows
      functions via the API. Not criticism: it is a magnificent
      concept, if not too magnificently implemented (don't know how
      Linux would handle this one).



      ------------------

      Comment


      • #4
        1x thanks is fine by me

        What i use, and it's really perfect! is wm_setredraw like this.

        hWnd = hDlg (!)

        Freeze:
        SendMessage hWnd, %WM_SETREDRAW, 0, ByVal 0&

        Refresh:

        SendMessage hWnd, %WM_SETREDRAW, 1, ByVal 0&
        RedrawWindow hWnd, ByVal 0&, ByVal 0&, %RDW_ERASE Or %RDW_INVALIDATE Or %RDW_ALLCHILDREN




        ------------------
        [email protected]
        hellobasic

        Comment


        • #5
          Edwin, that is sheer magic! Even on my stone age Pentium
          (166 Mhz), it is beautiful! [Thanks x 1000]squared!

          In my code I've left out the FREEZE and my old UPDATEWINDOW, so
          the redraw is addressed to the DIALOG, not the individual
          controls on it. What makes the magic now looks like this:

          Case %WM_KEYDOWN
          CtlID&=GetDlgCtrlID(hWnd&)
          nsc&=1

          Select Case wParam&

          Case %VK_RETURN
          If CtlID&<Descr& Then Exit Select
          Array Scan Mva&(1) For mvc&, =CtlID&, To n&
          Array Scan Mva&(1) For mvc&, =DptBgn&, To d&
          Control Get Size sDlg&, Mva&(n&) To x1&, mvi&
          Control Get Loc sDlg&, Mva&(n&) To x0&, y0&

          For i&=mvc& To n&+1 Step -1
          Control Get Loc sDlg&, Mva&(i&) To x&, y&
          Control Set Loc sDlg&, Mva&(i&), x&, y&+mvi&
          Next
          'Refresh:
          SendMessage sDlg&, %WM_SETREDRAW, 1, ByVal 0
          RedrawWindow sDlg&, ByVal 0, ByVal 0, %RDW_ERASE Or %RDW_INVALIDATE Or %RDW_ALLCHILDREN
          'Freeze:
          ' SendMessage Cx&, %WM_SETREDRAW, 0, ByVal 0

          m&=NextNo
          WTExtras$=WTExtras$+Str$(m&)
          Control Add TextBox, sDlg&, m&, "Jack-in-the-box", x0&, y0&+mvi&, x1&, mvi&, TbxStyle&
          If n&<d& Then Control Send sDlg&, m&, %WM_SETFONT, mnFont&, 1
          Control Handle sDlg&, m& To hCtl&
          dlgWndProc& = SetWindowLong(hCtl&, %GWL_WNDPROC, CodePtr(WtxSubproc))
          Incr mvc&
          Array Insert mva&(n&+1), m&
          Array Scan Mvt&(1) For mmx&, =CtlID&, To o&
          Incr mmx&
          Array Insert mvt&(o&+1), m&
          ti&=ti&+mvi&
          iVscrollMax = ti&/15
          Call SetScrollRange (sDlg&, %SB_VERT, 0, iVscrollMax, %TRUE)
          ' Call UpdateWindow (sDlg&)


          ------------------

          Comment


          • #6
            I noticed that it also improves speed!

            Prob. much less WM_color_static... whatever messages.





            ------------------
            [email protected]
            hellobasic

            Comment

            Working...
            X