Announcement

Collapse
No announcement yet.

Rebar position

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

  • Rebar position

    How do I set the position of a rebar band's gripper bar at runtime?

    By program not by hand.

    I don't know if it helps but heres what I'm trying to do.

    In this project I allow the users to set font, form position, size and LV collum width. This info is saved on exit and duplicated on next execution.

    I now need a new form has two listviews showing related data (but not syncronized). I want to use a rebar to allow the user to set the LV's as they want them.

    Obviously I need to overwrite the designtime position of the bar of the rebar between the two LV's, this where it fails. I've tried storing and reinstating the
    LVs left and right, playing with the bands of the rebar.

    I'd also be happy to use a splitter but I'm left with the same problem, ie how to position it a runtime.


  • #2
    If I get you right...

    To set position, what come to mind is RB_MOVEBAND...
    Code:
    Moved = SendMessage(hRebar, %RB_MOVEBAND, indexFrom, BandIndex)
    To backup rebar position's bands and order, you may use a mix of
    RB_GETBANDCOUNT, RB_GETROWCOUNT, RB_GETBARHEIGHT, RB_GETBANDINFO.

    Comment


    • #3
      Hi Pierre,

      sorry for the unclear explanation, I was so sure this time ...

      I have FixedOrder set so (although I'm not sure why) no gripper on band 0. The leftLV is embedded in band 0 and the right in band 1.

      The user sets the column widths, form size and band 1 gripper postion to suit. The next time this form is displayed I want it to appear as they closed it.

      But no matter what I do the gripper is always displayed in it's design time position. I have tried saving and retreiving the LV sizes and %RB_GETBANDINFO/%RB_SETBANDINFO but the gripper is displyed in its design time position.

      trbbi.cbSize = SIZEOF(trbbi)
      trbbi.fMask = %RBBIM_SIZE
      lBandIdx = 1
      SendMessage(RebarHandle, %RB_GETBANDINFO, lBandIdx, BYVAL VARPTR(trbbi))

      Click image for larger version

Name:	Image 1.jpg
Views:	91
Size:	76.3 KB
ID:	778652


      Comment


      • #4
        So, you got two report listviews in a rebar in a dialog.
        Assuming a resizable dialog,
        you want to keep the height and width of the dialog
        because RBS_FIXEDORDER listview1 will always be on left and listview2 on right
        you want to keep the witdth of both listview controls
        and all columns width for each listview.
        Is that it?

        Save RebarSetting
        Save ListviewSetting(ListView1)
        Save ListviewSetting(ListView2)
        ...
        Restore RebarSetting
        Restore ListviewSetting(ListView1)
        Restore ListviewSetting(ListView2)


        Not sure about the absense of a grip on band 0, maybe a little glitch in code.

        Comment


        • #5
          Yes the missing gripper is odd, I put it down to FixedOrder but what do I know.

          Save/Restore BebarSetting is what I'm trying to do, the question is how.

          Seem like Rebar is rarly used with Powerbasic, I wonder why.

          Comment


          • #6
            Probably because it is a little bit trickier and not as primordial as some other controls.

            So to save and restore rebar setting the answer in my first post apply.
            If you want an example, when I got time, I will extract and post partial code from a program I already have that does exactly tris...

            Comment


            • #7
              Click image for larger version

Name:	Rebar.png
Views:	88
Size:	25.5 KB
ID:	778677

              Code:
              #COMPILE EXE '#Win 9.07#
              #DIM ALL
              #REGISTER NONE
              #INCLUDE "Win32Api.inc"
              #INCLUDE "CommCtrl.inc"
              #RESOURCE ".pbr" 'Add a resource
              'or
              '#RESOURCE MANIFEST, 1, "xpTheme.xml"
              
              $AppTitle    = "Rebar - Positions backup and restore"
              
              %Rebar         = 100
              %RebarEditHex  = 101
              %RebarEditDec  = 102
              %RebarEditType = 103
              %RebarEditDesc = 104
              
              %EditInfo      = 201
              %ButtonBackup  = 301
              %ButtonRestore = 302
              
              %SIZE_REBAR_NOTIFY      = 5 '%SIZE_RESTORED
              %WM_REBAR_SET_TAB_ORDER = %WM_APP + 1
              
              GLOBAL hDlg   AS DWORD
              GLOBAL hRebar AS DWORD
              '_____________________________________________________________________________
              
              CALLBACK FUNCTION MainProc
               LOCAL  pNotifyMessageRebarChildSize AS NMREBARCHILDSIZE POINTER
               LOCAL  RebarInf     AS REBARBANDINFO
               STATIC DialogRect   AS RECT
               LOCAL  sBuffer      AS STRING
               LOCAL  hBefore      AS DWORD
               LOCAL  indexFrom    AS DWORD
               LOCAL  hControl     AS DWORD
               STATIC BandCount    AS LONG
               STATIC RowCount     AS LONG
               LOCAL  Moved        AS LONG
               LOCAL  BandIndex    AS LONG
               STATIC ClientX      AS LONG
               STATIC ClientY      AS LONG
               LOCAL  RebarHeight  AS LONG
               LOCAL  ButtonWidth  AS LONG
               LOCAL  ButtonSpacer AS LONG
              
               SELECT CASE CBMSG
              
                 CASE %WM_INITDIALOG
                   SetFocus(GetDlgItem(hDlg, %ButtonBackup))
                   PostMessage(hDlg, %WM_REBAR_SET_TAB_ORDER, 0, 0) 'Set REBAND control's ascending tab order
                   PostMessage(hDlg, %WM_COMMAND, MAKDWD(%ButtonBackup, %BN_CLICKED), 0)
              
                 CASE %WM_REBAR_SET_TAB_ORDER
                   'Set REBAND control's ascending tab order
                   BandCount = SendMessage(hRebar, %RB_GETBANDCOUNT, 0, 0)
                   RebarInf.cbsize = SIZEOF(REBARBANDINFO)
                   RebarInf.fMask  = %RBBIM_CHILD
                   hBefore = %HWND_TOP 'First control in dialog is first in zOrder
                   FOR BandIndex = 0 TO BandCount - 1
                     SendMessage(hRebar, %RB_GETBANDINFO, BandIndex, BYVAL VARPTR(RebarInf))
                     SetWindowPos(RebarInf.hwndChild, hBefore, 0, 0, 0, 0, %SWP_NOSIZE OR %SWP_NOMOVE)
                     hBefore = RebarInf.hwndChild
                   NEXT
              
                 CASE %WM_COMMAND
                   SELECT CASE CBCTL
              
                     CASE %IDCANCEL
                       IF (CBCTLMSG = %BN_CLICKED) OR (CBCTLMSG = 1) THEN
                         DIALOG END hDlg
                       END IF
              
                     CASE %ButtonBackup
                       IF (CBCTLMSG = %BN_CLICKED) OR (CBCTLMSG = 1) THEN
                         SendDlgItemMessage(hDlg, %EditInfo, %WM_SETTEXT, 0, BYVAL 0) 'Clear text
                         GetWindowRect(hDlg, DialogRect) 'Get dialog size
              
                         BandCount = SendMessage(hRebar, %RB_GETBANDCOUNT, 0, 0)
                         RowCount  = SendMessage(hRebar, %RB_GETROWCOUNT, 0, 0)
              
                         sBuffer = " - Backup " & TIME$ & $CRLF & _
                                   "RB_GETBANDCOUNT =" & STR$(BandCount) & $CRLF & _
                                   "RB_GETROWCOUNT ="  & STR$(RowCount)  & $CRLF & _
                                   "RB_GETBARHEIGHT "
                         FOR BandIndex = 0 TO BandCount - 1
                           sBuffer &= "(" & FORMAT$(BandIndex) &  "=" & STR$(SendMessage(hRebar, %RB_GETBARHEIGHT, 0, 0)) & ")  "
                         NEXT : sBuffer &= $CRLF
              
                         REDIM RebarInfoArray(0 TO BandCount - 1)  AS STATIC REBARBANDINFO
                         REDIM zRebarInfoArray(0 TO BandCount - 1) AS STATIC ASCIIZ * 64
                         sBuffer &= "Index "
                         FOR BandIndex = 0 TO BandCount - 1
                           RebarInfoArray(BandIndex).cbSize = SIZEOF(REBARBANDINFO)
                           RebarInfoArray(BandIndex).cch    = SIZEOF(zRebarInfoArray(BandIndex))
                           RebarInfoArray(BandIndex).lpText = VARPTR(zRebarInfoArray(BandIndex))
                           RebarInfoArray(BandIndex).fMask  = %RBBIM_COLORS OR %RBBIM_CHILDSIZE OR %RBBIM_STYLE OR %RBBIM_LPARAM OR _
                                                              %RBBIM_ID OR %RBBIM_SIZE OR %RBBIM_TEXT OR %RBBIM_BACKGROUND
                           SendMessage(hRebar, %RB_GETBANDINFO, BandIndex, BYVAL VARPTR(RebarInfoArray(BandIndex)))
                           sBuffer &= "(" & FORMAT$(BandIndex) &  "= """ & zRebarInfoArray(BandIndex) & """" & _
                                      ", id" & STR$(RebarInfoArray(BandIndex).wID) & ")  "
                         NEXT : sBuffer &= $CRLF
              
                         SendDlgItemMessage(hDlg, %EditInfo, %EM_REPLACESEL, %TRUE, BYVAL STRPTR(sBuffer)) 'Insert string at caret position
                         SendDlgItemMessage(hDlg, %EditInfo, %EM_SETSEL, -2, -2) 'Erase selection
              
                       END IF
              
                     CASE %ButtonRestore
                       IF (CBCTLMSG = %BN_CLICKED) OR (CBCTLMSG = 1) THEN
                         SendDlgItemMessage(hDlg, %EditInfo, %WM_SETTEXT, 0, BYVAL 0) 'Erase all
              
                         SetWindowPos(hDlg, 0, 0, 0, DialogRect.nRight - DialogRect.nLeft, _
                                      DialogRect.nBottom - DialogRect.nTop, %SWP_NOZORDER OR %SWP_NOMOVE)
                         sBuffer = " - Restore " & TIME$ & $CRLF
                         IF BandCount THEN
                           FOR BandIndex = 0 TO BandCount - 1
                             indexFrom = SendMessage(hRebar, %RB_IDTOINDEX, RebarInfoArray(BandIndex).wId, 0) 'Get possibly new position band via wID
                             Moved     = SendMessage(hRebar, %RB_MOVEBAND, indexFrom, BandIndex) 'From -> To, Moved is TRUE if position change
                             IF Moved THEN
                               sBuffer &= "RB_MOVEBAND: " & FORMAT$(BandIndex) & " replaced by " & FORMAT$(indexFrom) & _
                                          " """ & zRebarInfoArray(BandIndex) & """" & $CRLF
                             ELSE
                               sBuffer &= "RB_MOVEBAND: " & FORMAT$(indexFrom) & " No move" & $CRLF
                             END IF
                           NEXT
                           FOR BandIndex = 0 TO BandCount - 1
                             RebarInfoArray(BandIndex).fMask  = %RBBIM_ID OR %RBBIM_STYLE OR %RBBIM_SIZE
                             SendMessage(hRebar, %RB_SETBANDINFO, BandIndex, BYVAL VARPTR(RebarInfoArray(BandIndex)))
                           NEXT
              
                         ELSE 'No backup done yet...
                           PostMessage(hDlg, %WM_COMMAND, MAKDWD(%ButtonBackup, %BN_CLICKED), 0)
                           PostMessage(hDlg, %WM_COMMAND, MAKDWD(%ButtonRestore, %BN_CLICKED), 0)
                         END IF
                         SendDlgItemMessage(hDlg, %EditInfo, %EM_REPLACESEL, %TRUE, BYVAL STRPTR(sBuffer)) 'Insert string at caret position
                         SendDlgItemMessage(hDlg, %EditInfo, %EM_SETSEL, -2, -2) 'Erase selection
                         PostMessage(hDlg, %WM_SIZE, %SIZE_REBAR_NOTIFY, 0) 'Client area may have changed so notify WM_SIZE
                       END IF
              
                   END SELECT
              
                 CASE %WM_NOTIFY 'hdr NMHDR (hwndFrom, idfrom, code), uBand DWORD, wID DWORD,rcChild RECT, rcBand RECT
                   pNotifyMessageRebarChildSize = CBLPARAM
                   IF @pNotifyMessageRebarChildSize.hdr.hwndFrom = hRebar THEN
                     IF  @pNotifyMessageRebarChildSize.hdr.code = %RBN_AUTOSIZE THEN
                         PostMessage(hDlg, %WM_SIZE, %SIZE_REBAR_NOTIFY, 0) 'Client area may have changed so notify WM_SIZE
                         PostMessage(hDlg, %WM_REBAR_SET_TAB_ORDER, 0, 0) 'Set REBAND control's ascending tab order
                     END IF
                   END IF
              
                 CASE %WM_SIZE
                   'CBWPARAM = Resizing requested: SIZE_MAXHIDE SIZE_MAXIMIZED SIZE_MAXSHOW SIZE_MINIMIZED SIZE_RESTORED
                   'LO(WORD, CBLPARAM) is client area width  in pixels, HI(WORD, CBLPARAM) is height.
                   IF CBWPARAM <> %SIZE_MINIMIZED THEN
                     IF CBWPARAM <> %SIZE_REBAR_NOTIFY THEN  'Client area may have changed because of a ReBar's band move
                       ClientX = LO(WORD, CBLPARAM)
                       ClientY = HI(WORD, CBLPARAM)
                       SendMessage(hRebar, %WM_SIZE, CBWPARAM, CBLPARAM)
                     END IF
                     RebarHeight = SendMessage(hRebar, %RB_GETBARHEIGHT, 0, 0)
              
                     ButtonWidth = 220
                     ButtonSpacer = (ClientX - ButtonWidth * 2) / 4
              
                     hControl = GetDlgItem(hDlg, %ButtonBackup)
                     MoveWindow(hControl, ButtonSpacer, RebarHeight + 13, ButtonWidth, 22, %TRUE)
                     InvalidateRect(hControl, BYVAL %NULL, %TRUE) : UpdateWindow(hControl)
              
                     hControl = GetDlgItem(hDlg, %ButtonRestore)
                     MoveWindow(hControl, ButtonSpacer * 2 + ButtonWidth, RebarHeight + 13, ButtonWidth, 22, %TRUE)
                     InvalidateRect(hControl, BYVAL %NULL, %TRUE) : UpdateWindow(hControl)
              
                     hControl = GetDlgItem(hDlg, %EditInfo)
                     MoveWindow(hControl,  003, RebarHeight + 50, ClientX - 6, ClientY - RebarHeight - 53, %TRUE)
                     InvalidateRect(hControl, BYVAL %NULL, %TRUE) : UpdateWindow(hControl)
              
                   END IF
              
               END SELECT
              
              END FUNCTION
              '_____________________________________________________________________________
              
              FUNCTION RebarCreate() AS LONG
               LOCAL RebarInf     AS REBARINFO
               LOCAL RebarBandInf AS REBARBANDINFO
               LOCAL rc           AS RECT
               LOCAL zBuffer      AS ASCIIZ * 255
              
               CONTROL ADD "ReBarWindow32", hDlg, %Rebar, "", 0, 0, 0, 0, _
               %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN OR %RBS_AUTOSIZE OR _
               %RBS_BANDBORDERS OR %RBS_VARHEIGHT OR %CCS_NODIVIDER, %WS_EX_CONTROLPARENT
              
               hRebar = GetDlgItem(hDlg, %Rebar)
              
               RebarInf.cbSize = SIZEOF(REBARINFO)
               SendMessage(hRebar, %RB_SETBARINFO, 0, VARPTR(RebarInf))
              
               RebarBandInf.cbSize    = SIZEOF(REBARBANDINFO)
               RebarBandInf.fMask     = %RBBIM_COLORS    OR _ 'ClrFore and clrBack are valid
                                        %RBBIM_CHILD     OR _ 'HwndChild is valid
                                        %RBBIM_CHILDSIZE OR _ 'CxMinChild and cyMinChild are valid
                                        %RBBIM_STYLE     OR _ 'FStyle is valid
                                        %RBBIM_ID        OR _ 'WID is valid
                                        %RBBIM_SIZE      OR _ 'Cx is valid
                                        %RBBIM_TEXT      OR _ 'LpText is valid
                                        %RBBIM_BACKGROUND     'HbmBack is valid
              
               RebarBandInf.clrFore   = GetSysColor(%COLOR_BTNTEXT)
               RebarBandInf.clrBack   = GetSysColor(%COLOR_BTNFACE)
               RebarBandInf.hbmBack   = 0
               RebarBandInf.fStyle    = %RBBS_NOVERT        OR _ 'Don't show when vertical
                                        %RBBS_CHILDEDGE     OR _ 'Edge around top & bottom of child window
                                        %RBBS_FIXEDBMP      OR _ 'Bitmap doesn't move during band resize
                                        %RBBS_GRIPPERALWAYS OR _ 'Always show the gripper
                                        %RBBS_USECHEVRON         'Show a chevron button if the band is smaller than cxIdeal
              
               CONTROL ADD TEXTBOX, hDlg, %RebarEditHex, "FF", 0, 0, 30, 10, _
               %ES_AUTOHSCROLL OR %ES_LEFT OR %WS_TABSTOP, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT
               GetWindowRect(GetDlgItem(hDlg, %RebarEditHex), rc)
               zBuffer                 = "0x"
               RebarBandInf.lpText     = VARPTR(zBuffer)
               RebarBandInf.hwndChild  = GetDlgItem(hDlg, %RebarEditHex)
               RebarBandInf.wID        = %RebarEditHex
               RebarBandInf.cxMinChild = 60 'Minimum width of the child window, in pixels. The band can't be sized smaller than this value.
               RebarBandInf.cyMinChild = rc.nBottom - rc.nTop 'Minimum height of the child window, in pixels. The band can't be sized smaller than this value.
               RebarBandInf.cx         = 95 'Length of the band, in pixels.
               SendMessage(hRebar, %RB_INSERTBAND, -1, VARPTR(RebarBandInf))
              
               CONTROL ADD TEXTBOX, hDlg, %RebarEditDec, "255", 10, 0, 30, 10, _
               %ES_AUTOHSCROLL OR %ES_LEFT OR %WS_TABSTOP, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT
               GetWindowRect(GetDlgItem(hDlg, %RebarEditDec), rc)
               zBuffer                 = "Dec"
               RebarBandInf.lpText     = VARPTR(zBuffer)
               RebarBandInf.hwndChild  = GetDlgItem(hDlg, %RebarEditDec)
               RebarBandInf.wID        = %RebarEditDec
               RebarBandInf.cxMinChild = 60 'Minimum width of the child window, in pixels. The band can't be sized smaller than this value.
               RebarBandInf.cyMinChild = rc.nBottom - rc.nTop 'Minimum height of the child window, in pixels. The band can't be sized smaller than this value.
               RebarBandInf.cx         = 115 'Length of the band, in pixels.
               SendMessage(hRebar, %RB_INSERTBAND, -1, VARPTR(RebarBandInf))
              
               CONTROL ADD TEXTBOX, hDlg, %RebarEditType, "Byte", 30, 0, 30, 10, _
               %ES_AUTOHSCROLL OR %ES_LEFT OR %WS_TABSTOP, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT
               GetWindowRect(GetDlgItem(hDlg, %RebarEditType), rc)
               zBuffer                 = "Type"
               RebarBandInf.lpText     = VARPTR(zBuffer)
               RebarBandInf.hwndChild  = GetDlgItem(hDlg, %RebarEditType)
               RebarBandInf.wID        = %RebarEditType
               RebarBandInf.cyMinChild = rc.nBottom - rc.nTop 'Minimum height of the child window, in pixels. The band can't be sized smaller than this value.
               RebarBandInf.cxMinChild = 210 'Minimum width of the child window, in pixels. The band can't be sized smaller than this value.
               RebarBandInf.cx         = 210 'Length of the band, in pixels.
               SendMessage(hRebar, %RB_INSERTBAND, -1, VARPTR(RebarBandInf))
              
               CONTROL ADD TEXTBOX, hDlg, %RebarEditDesc, "Two hundred fifty-five", 50, 0, 30, 10, _
               %ES_AUTOHSCROLL OR %ES_LEFT OR %WS_TABSTOP, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT
               GetWindowRect(GetDlgItem(hDlg, %RebarEditDesc), rc)
               zBuffer                 = "Text"
               RebarBandInf.lpText     = VARPTR(zBuffer)
               RebarBandInf.hwndChild  = GetDlgItem(hDlg, %RebarEditDesc)
               RebarBandInf.wID        = %RebarEditDesc
               RebarBandInf.cyMinChild = rc.nBottom - rc.nTop 'Minimum height of the child window, in pixels. The band can't be sized smaller than this value.
               RebarBandInf.cxMinChild = 210 'Minimum width of the child window, in pixels. The band can't be sized smaller than this value.
               RebarBandInf.cx         = 510 'Length of the band, in pixels.
               SendMessage(hRebar, %RB_INSERTBAND, -1, VARPTR(RebarBandInf))
              
              END FUNCTION
              '_____________________________________________________________________________
              
              FUNCTION PBMAIN() AS LONG
               LOCAL hIcon AS DWORD
              
               DIALOG FONT "Segoe UI", 9
               DIALOG NEW %HWND_DESKTOP, $AppTitle, , , 300, 150, _
               %WS_MAXIMIZEBOX OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR %WS_THICKFRAME OR _
               %WS_CLIPCHILDREN OR %WS_CLIPSIBLINGS OR %DS_CENTER, 0 TO hDlg
              
               RebarCreate()
              
               CONTROL ADD BUTTON, hDlg, %ButtonBackup, "Backup rebar's bands positions layout", 10, 40, 50, 10
              
               CONTROL ADD BUTTON, hDlg, %ButtonRestore, "Restore rebar's bands positions layout", 70, 40, 50, 10
              
               CONTROL ADD TEXTBOX, hDlg, %EditInfo, "Rebar", 10, 40, 50, 50, _
               %ES_AUTOHSCROLL OR %ES_LEFT OR %ES_MULTILINE OR %WS_TABSTOP OR _
               %WS_VSCROLL OR %WS_HSCROLL, %WS_EX_CLIENTEDGE OR %WS_EX_LEFT
              
               hIcon = ExtractIcon(GetModuleHandle(""), "Shell32.dll", 294) 'o
               SetClassLong(hDlg, %GCL_HICON, hIcon)
              
               DIALOG SHOW MODAL hDlg CALL MainProc
              
               DestroyIcon(hIcon)
              
              END FUNCTION
              '_____________________________________________________________________________
              '
              Last edited by Pierre Bellisle; 9 Feb 2019, 08:34 PM.

              Comment


              • #8
                Wow, you've gone and dun it agin - not only have you sorted my problem but you catered for multiple rows and a whole bunch of stuff that I don't understand.

                Pierre for president! Thanks a million.

                Comment


                • #9
                  President, nahhhh, part of the "Having fun team", count me in!

                  About the missing grip, did you used RBBS_GRIPPERALWAYS ?


                  Comment


                  • #10
                    About the missing grip, did you used RBBS_GRIPPERALWAYS ?
                    On creation of the Rebar I use %CCS_NORESIZE OR %CCS_NODIVIDER OR %RBS_FIXORDER (actually I should say Phoenix uses) and when the bands are inserted I use %RBBIM_STYLE OR %RBBIM_CHILD OR %RBBIM_CHILDSIZE OR %RBBIM_SIZE OR %RBBIM_ID OR %RBBIM_IDEALSIZE.

                    When I restore the size of the band, I first GetBandInfo just change the size and SetBandInfo, as you showed. I store the widths of the 2 bands in an INI file.

                    In this application, the missing gripper is handy because with two bands that can't change order, it serves no useful purpose. I could zip you the code if you're interested but frankly it's nothing special and you couldn't run it without hardware, the Phoenix sizing SSL and a bunch of files supplied by another compiler.

                    Once again, thanks, I very nearly gave up on what is a very user friendly feature.

                    Edit. I note that RBBS_FIXEDSIZE is defined "The band can't be sized. With this style, the sizing grip is not displayed on the band." although if I set that for either band it screws up.
                    Last edited by James McNab; 11 Feb 2019, 07:28 AM. Reason: old and stupid

                    Comment

                    Working...
                    X