Announcement

Collapse
No announcement yet.

Wanted WS_CLIPSIBLINGS sample

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

  • Wanted WS_CLIPSIBLINGS sample

    Two days ago, I asked, how to draw a frame.
    Lance recommended to use WS_CLIPSIBLINGS.

    I followed (it was under Win2000). All was nice, until I reboot to Windows 95b.
    Here obvious repainting problems.
    The same happends in Windows 98.

    Can anybody post WS_CLIPSIBLINGS sample, which works under 9x?

    In my impression, Windows doesn't invalidate "brothers".

    PS. I changed an order ("frames" - last). Looks that works, but I don't like a repainting process.
    So, sample wanted anyway.

    [This message has been edited by Semen Matusovski (edited April 09, 2001).]

  • #2
    As you noted, overlapped siblings should be drawn in the "right" order to be drawn correctly. What is the problem with the repainting process?

    I've seen similar problems when using %WM_CLIPCHILDREN (with %WS_CLIPSIBLINGS) on child dialogs used in a tab-control dialog.

    When you say "brothers", you really mean "siblings", hence the message %WM_CLIPSIBLINGS.



    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Lance --
      I imitated a situation (note, I am about 9x only).
      Problems, when frame is first. Try to move a window to right side and to return.
      If frame is last, all works, but I don't like repainting process (very well visible in my program, unlike a case, when frame is first).

      To my surprise, with DDT frame ("Button") happends exactly the same: works, if last.

      Code:
         #Compile Exe
         #Dim All
         #Register None
         #Include "Win32Api.INC"
      
         CallBack Function DlgProc
            Select Case CbMsg
               Case %WM_INITDIALOG
                  Control Add Label, CbHndl, 101, "Frame", 220, 10, 180, 110, %WS_CLIPSIBLINGS, %ws_ex_clientedge ' <==============
                '  Control Add Frame, CbHndl, 101, "Frame", 220, 10, 180, 110 ' <=== Also doesn't work ===========
               
                  Control Add Label, CbHndl, 103, "Label", 10, 10, 200, 10, %WS_CHILD Or %WS_VISIBLE
                  Control Add TextBox, CbHndl, 104, "text", 10, 22, 200, 14
                  Control Add Label, CbHndl, 105, "Label", 230, 54, 160, 10, %WS_CHILD Or %WS_VISIBLE
                  Control Add TextBox, CbHndl, 106, "Text", 230, 66, 160, 14
                  Control Add Label, CbHndl, 107, "<------ Label ---->", 230, 82, 160, 10, %WS_CHILD Or %WS_VISIBLE
                  Control Add TextBox, CbHndl, 108, "<-------- Text ----->", 230, 94, 160, 14
                  Control Add Button, CbHndl, 109, "cText12", 320, 135, 80, 15
                  
                  
              End Select
         End Function
      
         Function PbMain
            Local hDlg As Long
            Dialog New 0, "", ,, 410, 200, %WS_CAPTION Or %WS_SYSMENU Or %WS_CLIPCHILDREN Or %WS_CLIPSIBLINGS To hDlg
            Dialog Show Modal hDlg Call DlgProc
         End Function


      ------------------
      E-MAIL: [email protected]

      Comment


      • #4
        Semen,

        Your code doesn't work on my system too (NT4, both statements). I tried to move the CONTROL ADD FRAME to the bottom of the control adds section, and now it seems to work.

        See http://support.microsoft.com/support.../Q182/3/84.ASP - It is about groups (frames) in Windows CE, but I found the following:
        ...group boxes cover and hide any controls that are beneath them in the Z-Order...
        ...To avoid this, the group box must be placed lower in the Z-order than the controls that it contains. You can change the Z-order of the group box by editing the tab stop order so that the group box comes last...
        May be the problem key is the z-order.

        Aldo


        ------------------
        Rgds, Aldo

        Comment


        • #5
          Correct, since drawing the control last places it last in the z-order... that is, the z-order is determined by the order of creation.


          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment


          • #6
            z-order - unf., it's clear. But imagine that it's necessary to add "siblings" on fly.
            Let's return to initial question.

            A control, which depends, of z-order - not serious.
            Any new ideas ? (except creation regions for frame - last, of course, should work anyway)

            ------------------
            E-MAIL: [email protected]

            Comment


            • #7
              Tested on Win/ME
              Code:
                Control Add Frame, CbHndl, 101, "Frame", 220, 10, 180, 110 ,%WS_CHILD,%WS_EX_TRANSPARENT ' <=== DOES WORK ===========
              ----
                Control Add Label, CbHndl, 105, "Label2", 230, 54, 160, 14, %WS_CHILD Or %WS_VISIBLE Or %WS_Border 'Or %WS_CLIPSIBLINGS
                Control Add TextBox, CbHndl, 106, "Text2", 230, 63, 160, 14, %WS_CHILD Or %WS_VISIBLE Or %WS_Border 
              --->use %WS_CLIPSIBLINGS on label. Works as expected (Z-order is enforced)  
                  Initially Label is overlapping textbox, move another window across and
                  label is covering part of textbox
                 
                Dialog New 0, "", ,, 410, 200, %WS_CAPTION Or %WS_SYSMENU Or %WS_CLIPCHILDREN  To hDlg
              --->%WS_CLIPSIBLINGS is for %WS_CHILD-style only!

              ------------------
              Fred
              mailto:[email protected][email protected]</A>
              http://www.oxenby.se



              [This message has been edited by Fred Oxenby (edited April 10, 2001).]
              Fred
              mailto:[email protected][email protected]</A>
              http://www.oxenby.se

              Comment


              • #8
                Semen,

                May be you want to setup your new added controls in a certain tab-stop order. As I understand, tab-stop order and z-order are the same. You can use SetWindowPos, declaring the correct hWndInsertAfter value and using flags like SWP_NOMOVE, SWP_NOSIZE, etc. This way you'll also have the controls inserted before the frame.

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


                [This message has been edited by Aldo Cavini (edited April 10, 2001).]
                Rgds, Aldo

                Comment


                • #9
                  Fred -
                  I tested your variant under 95. Works.
                  But my custom control is mostly "Label" (fills whole client area in BeginPaint).
                  I changed Frame to Label in test sample, and, unf., nothing good.


                  ------------------
                  E-MAIL: [email protected]

                  Comment


                  • #10
                    Semen;

                    Send me your code via email to compile on my win98 OS and I will see if
                    I can find a solution for you. I need to see the visual ill-effects
                    of your code.

                    I spent alot of time with standard Groupbox frame, Static frame and Custom draw frame
                    with my visual forms draw-move-size engine. I ended up using a combination
                    of either transparency / erase background / changing the Z-order of
                    controls to optimize flicker and repaint issues. If you played with the
                    draw-move-size engine executable and dropped some Groupboxes and placed
                    controls inside on the fly, you will see the results.

                    Hope I can help...
                    Regards,
                    Jules

                    --------------------------
                    E-MAIL: [email protected]


                    Best regards
                    Jules
                    www.rpmarchildon.com

                    Comment


                    • #11
                      Custom control is not too big. So I added it to test sample.
                      Code:
                         #Compile Exe
                         #Dim All
                         #Register None
                         #Include "Win32Api.INC"
                      
                         %DlgColor = &HC08040
                      
                         '******************************
                         '*      pbLabel               *
                         '******************************
                         Global pbLabel_Default_ForeColor As Long, pbLabel_Default_BackColor As Long
                         %pbLabel_Frame = 4
                      
                         Function Register_pbLabel As Long
                           Local wc          As WNDCLASS
                           Local szClassName As Asciiz * 8
                           szClassName      = "pbLabel"
                           wc.lpfnWndProc   = CodePtr(pbLabelProc)
                           wc.hInstance     = GetModuleHandle(ByVal 0&)
                           wc.hCursor       = LoadCursor(ByVal 0&, ByVal %IDC_ARROW)
                           wc.hBrBackGround = GetStockObject(%NULL_BRUSH)
                           wc.lpszClassName = VarPtr(szClassName)
                           wc.cbWndExtra    = 8
                           Function = RegisterClass(wc)
                         End Function
                      
                         %pbLabel_ForeColor = 0
                         %pbLabel_BackColor = 4
                      
                         Function pbLabelProc (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
                                  Dim i As Long, j As Long, jj As Long, k As Long, kk As Long
                                  Dim hMemDC As Long, hMemBmp As Long, pBits As Long Ptr
                                  Dim Clr As Long
                                  Static hFont As Long
                                  Dim bmi As BITMAPINFO, bm As BITMAP, ps As PAINTSTRUCT, rc As Rect
                      
                            Select Case wMsg
                               Case %WM_CREATE
                                  ' Defaults
                                  SetWindowLong hWnd, %pbLabel_ForeColor, pbLabel_Default_ForeColor
                                  SetWindowLong hWnd, %pbLabel_BackColor, pbLabel_Default_BackColor
                               Case %WM_SETFONT
                                  hFont = wParam
                      
                               Case %WM_SETTEXT
                                  Function = DefWindowProc(hWnd, wMsg, wParam, lParam)
                                  InvalidateRect hWnd, ByVal 0, 0
                                  UpdateWindow hWnd
                                  Exit Function
                      
                               Case %WM_PAINT
                                  Dim MyClr(2) As Long
                                  MyClr(0) = MakLng(&H0300, 2)
                                  MyClr(1) = GetWindowLong (hWnd, %pbLabel_ForeColor)
                                  MyClr(2) = GetWindowLong (hWnd, %pbLabel_BackColor)
                                  MyClr(0) = CreatePalette (ByVal VarPtr(MyClr(0)))
                      
                                  BeginPaint hWnd, ps
                                  SelectPalette ps.hDC, MyClr(0), %False
                                  RealizePalette ps.hDC
                      
                                  GetClientRect hWnd, rc
                                  hMemDC  = CreateCompatibleDC(ps.hDC)
                                  bmi.bmiHeader.biSize = SizeOf(bmi.bmiHeader)
                                  bmi.bmiHeader.biWidth = rc.nRight - rc.nLeft
                                  bmi.bmiHeader.biHeight = rc.nBottom - rc.nTop
                                  bmi.bmiHeader.biPlanes = 1
                                  bmi.bmiHeader.biBitCount = 32
                                  bmi.bmiHeader.biCompression = %BI_RGB
                                  hMemBmp = CreateDIBSection(hMemDC, bmi, %DIB_RGB_COLORS, 0, 0, 0)
                                  GlobalLock hMemBmp: SelectObject hMemDC, hMemBmp
                                  GetObject hMemBmp, SizeOf(bm), bm
                                  pBits = bm.bmBits
                                  i = GetWindowLong (hWnd, %pbLabel_BackColor)
                                  j = (i And &H00FF0000): Shift Right j, 16
                                  k = (i And &H0000FF00): Shift Right k, 8
                                  i = (i And &HFF)
                                  Clr = Rgb(j, k, i)
                      
                                  For j = rc.nBottom - 1 To rc.nTop Step - 1
                                     For k = rc.nLeft To rc.nRight - 1
                                        @pBits = Clr: pBits = pBits + 4
                                     Next
                                  Next
                      
                                  SetBkMode hMemDC, %OPAQUE
                                  SetBkColor  hMemDC, GetWindowLong (hWnd, %pbLabel_BackColor)
                                  SetTextColor hMemDC, GetWindowLong (hWnd, %pbLabel_ForeColor)
                                  SelectObject hMemDC, hFont
                                  Dim Txt As Asciiz * 100, sz As SIZEL
                                  GetWindowText hWnd, Txt, SizeOf(Txt)
                      
                                  i = GetWindowLong(hWnd, %GWL_STYLE)
                                  If (i And %SS_RIGHT) = %SS_RIGHT   Then j = %SS_RIGHT Else _
                                  If (i And %SS_CENTER) = %SS_CENTER Then j = %SS_CENTER Else _
                                                                          j = %SS_LEFT
                      
                                  GetTextExtentPoint32 hMemDC, Txt, Len(Txt), sz
                                  GetClientRect hWnd, rc
                      
                                  If (i And %pbLabel_FRAME) = %pbLabel_FRAME Then
                                     Select Case j
                                        Case %SS_CENTER: sz.cx = Max(0, (rc.nRight - rc.nLeft - sz.cx) \ 2)
                                        Case %SS_LEFT:   sz.cx = Min(0.05 * (rc.nRight - rc.nLeft), rc.nRight - rc.nLeft - sz.cx)
                                        Case %SS_RIGHT:  sz.cx = Max(0, 0.95 * (rc.nRight - rc.nLeft) - sz.cx)
                                     End Select
                                     pBits = bm.bmBits
                                     i = GetWindowLong (hWnd, %pbLabel_ForeColor)
                                     j = (i And &H00FF0000): Shift Right j, 16
                                     k = (i And &H0000FF00): Shift Right k, 8
                                     i = (i And &HFF)
                                     Clr = Rgb(j, k, i)
                                     If sz.cy = 0 Then GetTextExtentPoint32 hMemDC, " ", 1, sz
                                     For j = rc.nBottom - 1 To rc.nTop Step - 1
                                        For k = rc.nLeft To rc.nRight - 1
                                           If j >= (rc.nTop + sz.cy / 2) Then
                                              If (k = rc.nLeft) Or (k = (rc.nRight - 1)) Or _
                                                 (j = rc.nBottom - 1) Or (j = rc.nTop + sz.cy / 2) Then @pBits = Clr
                                           End If
                                           pBits = pBits + 4
                                        Next
                                     Next
                                     sz.cy = 0
                                  Else
                                     Select Case j
                                        Case %SS_CENTER: sz.cx = Max(0, (rc.nRight - rc.nLeft - sz.cx) \ 2)
                                        Case %SS_LEFT:   sz.cx = 0
                                        Case %SS_RIGHT:  sz.cx = Max(0, (rc.nRight - rc.nLeft - sz.cx))
                                     End Select
                                     sz.cy = Max(0, (rc.nBottom - rc.nTop - sz.cy) \ 2)
                                  End If
                      
                                  TextOut hMemDC, rc.nLeft + sz.cx, rc.nTop + sz.cy, Txt, Len(Txt)
                                  BitBlt ps.hDC, 0, 0, rc.nRight, rc.nBottom, hMemDC, 0, 0, %SRCCOPY
                                  EndPaint hWnd, ps
                                  DeleteDC hMemDC
                                  DeleteObject hMemBmp
                                  DeleteObject MyClr(0)
                                  Exit Function
                      
                            End Select
                      
                            Function = DefWindowProc(hWnd, wMsg, wParam, lParam)
                         End Function
                      
                         CallBack Function DlgProc
                               Dim hFontC10 As Static Long, hDC As Long, i As Long
                            Select Case CbMsg
                               Case %WM_DESTROY
                                  DeleteObject hFontC10
                               Case %WM_INITDIALOG
                                  Register_pbLabel
                                  
                                  pbLabel_Default_ForeColor = %WHITE
                                  pbLabel_Default_BackColor = %DlgColor
                               
                                  hDC = GetDC(%HWND_DESKTOP)
                                  i  = GetDeviceCaps(hDC, %LOGPIXELSY)
                                  ReleaseDC %HWND_DESKTOP, hDC
                      
                                  hFontC10 = CreateFont(0 - MulDiv(10, i, 72), 0, 0, 0, %FW_NORMAL, 0, 0, 0, _
                                     %RUSSIAN_CHARSET, %OUT_TT_PRECIS, %CLIP_DEFAULT_PRECIS, _
                                     %DEFAULT_QUALITY, %FF_DONTCARE, "Courier New")
                      
                        
                                  Control Add "pbLabel", CbHndl, 101, "Frame", 220, 10, 180, 110, %WS_CHILD Or %WS_VISIBLE Or %pbLabel_FRAME Or %SS_CENTER Or %WS_CLIPSIBLINGS ' <==============
                                  Control Add "pbLabel", CbHndl, 103, "Label-103", 10, 10, 200, 10, %WS_CHILD Or %WS_VISIBLE
                                  Control Add TextBox,   CbHndl, 104, "TextBox-102", 10, 22, 200, 14
                                  Control Add "pbLabel", CbHndl, 105, "Label-105", 230, 54, 160, 10, %WS_CHILD Or %WS_VISIBLE
                                  Control Add TextBox,   CbHndl, 106, "TextBox-106", 230, 66, 160, 14
                                  Control Add "pbLabel", CbHndl, 107, "Label-107", 230, 82, 160, 10, %WS_CHILD Or %WS_VISIBLE
                                  Control Add TextBox,   CbHndl, 108, "TextBox-108", 230, 94, 160, 14
                                  Control Add Button,    CbHndl, 109, "Button", 320, 135, 80, 15
                              
                                  For i = 1 To 9
                                     Control Send CbHndl, 100 + i, %WM_SETFONT, hFontC10, 1
                                  Next
                                  
                                '  Setwindowpos GetDlgItem(CbHndl, 101), GetDlgItem(CbHndl, 109), 0, 0, 0, 0, _
                                '     %SWP_NOSIZE Or %SWP_NOMOVE Or %SWP_NOACTIVATE ' Aldo's suggestion
                      
                              End Select
                         End Function
                      
                         Function PbMain
                            Local hDlg As Long
                            Dialog New 0, "", ,, 410, 200, %WS_CAPTION Or %WS_SYSMENU Or %WS_CLIPCHILDREN To hDlg
                            Dialog Show Modal hDlg Call DlgProc
                         End Function
                      ------------------
                      E-MAIL: [email protected]

                      Comment

                      Working...
                      X