Announcement

Collapse
No announcement yet.

Control Resize - Richedit for example

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

  • Control Resize - Richedit for example

    I must be missing something, but I have been searching for whatever flags, or routines I would need to grab the edge of a control and drag it to a new size at runtime but I can not find the right words to search for to get a working example.

    Initially I would like to be able to resize a richedit window by dragging its size. From there I am sure I would be able to apply similar techniques to other controls.

    Any help would be greatly appreciated.
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

  • #2
    %WS_SIZEBOX might be a good starting point.
    Rgds, Dave

    Comment


    • #3
      Hey Cliff,

      If you want controls being resized in proportion of other controls
      in a given dialog size then "Splitter bar" may be the word you are searching for.
      Kev Peel did a great example named Demonstrates using a 'splitter' between two controls.

      If you want controls being resized and moved in proportion
      of the dialog size then here is a little example...

      Code:
      #COMPILE EXE '#Win 8.04#
      #DIM ALL
      #REGISTER NONE
      #INCLUDE "Win32Api.inc" '#2005-01-27#]
       
      %Textbox = 101
      %Button  = 201
      %Grip    = 301
      '______________________________________________________________________________
       
      CALLBACK FUNCTION PbCallBack()
       LOCAL  MinMaxPtr    AS MINMAXINFO PTR
       STATIC hGrip        AS DWORD
       STATIC hTextbox     AS DWORD
       STATIC hButton      AS DWORD
       STATIC GripSizeX    AS LONG
       STATIC GripSizeY    AS LONG
       LOCAL  X            AS LONG
       LOCAL  Y            AS LONG
       
       SELECT CASE CBMSG
       
         CASE %WM_INITDIALOG
           hGrip = GetDlgItem(CBHNDL, %Grip)
           hTextbox = GetDlgItem(CBHNDL, %Textbox)
           hButton = GetDlgItem(CBHNDL, %Button)
           GripSizeX = GetSystemMetrics(%SM_CXVSCROLL) 'Get width of grip
           GripSizeY = GetSystemMetrics(%SM_CYHSCROLL) 'Get height of grip
       
         CASE %WM_SIZE 'Windows is being resized...
           X = LOWRD(CBLPARAM) 'New X size is in lo word of CBLPARAM
           Y = HIWRD(CBLPARAM) 'New Y size is in hi word of CBLPARAM
       
           'Using the api MoveWindow and SetWindowPos
           MoveWindow hTextbox, 10, 10, X - 20, Y * 0.5, %TRUE
           MoveWindow hButton, 10, Y * 0.6, X - 20, Y * 0.2, %TRUE
           SetWindowPos hGrip, %NULL, X - GripSizeX, Y - GripSizeY, _
                        GripSizeX, GripSizeY, %SWP_NOZORDER
       
           'Or using DDT
           'DIALOG PIXELS CBHNDL, X, Y TO UNITS X, Y 'Convert to units
           'CONTROL SET LOC CBHNDL, %Textbox, 0.05 * X, 0.05 * Y
           'CONTROL SET SIZE CBHNDL, %Textbox, 0.9 * X, 0.5 * Y
           'CONTROL SET LOC CBHNDL, %Button, 0.05 * X, 0.65 * Y
           'CONTROL SET SIZE CBHNDL, %Button, 0.9 * X, 0.2 * Y
           'CONTROL SET LOC CBHNDL, %Grip, X - 10, Y - 10
       
          CASE %WM_GETMINMAXINFO 'Restrict maximum and/or minimum dialog size
            'UnRem folloing line to restrict dialog size
            'MinMaxPtr = CBLPARAM
            '@MinMaxPtr.ptMinTrackSize.x = 150
            '@MinMaxPtr.ptMinTrackSize.y = 150
            '@MinMaxPtr.ptMaxTrackSize.x = 250
            '@MinMaxPtr.ptMaxTrackSize.y = 250
       
       END SELECT
       
      END FUNCTION
      '______________________________________________________________________________
       
      FUNCTION PBMAIN ()
       LOCAL hDlg AS DWORD
       
       DIALOG NEW %HWND_DESKTOP, "Size me...", , , 120, 100, _
         %WS_THICKFRAME OR %WS_CAPTION OR %WS_MINIMIZEBOX  OR %WS_MAXIMIZEBOX OR %WS_SYSMENU, 0 TO hDlg
       
       'Let's have a nice icon...
       SetClassLong hDlg, %GCL_HICON, LoadIcon(BYVAL %NULL, BYVAL %IDI_INFORMATION)
       
       CONTROL ADD BUTTON, hDlg, %Button, "Button", 0, 0, 0, 0
       
       CONTROL ADD TEXTBOX, hDlg, %Textbox, REPEAT$(5, "Resizable dialog..." & $CRLF), 0, 0, 0, 0, _
         %ES_MULTILINE OR %ES_WANTRETURN OR %WS_VSCROLL OR %WS_HSCROLL OR %WS_BORDER OR %WS_TABSTOP, _
         %WS_EX_CLIENTEDGE OR %WS_EX_LEFT
       
       'Add a grip, see bottom right of dialog...
       CONTROL ADD SCROLLBAR, hDlg, %Grip, "", 110, 90, 10, 10, _
         %WS_CHILD OR %WS_VISIBLE OR %SBS_SIZEGRIP OR %SBS_SIZEBOXBOTTOMRIGHTALIGN
       
       DIALOG SHOW MODAL hDlg, CALL PbCallBack
       
      END FUNCTION
      '______________________________________________________________________________
      Last edited by Pierre Bellisle; 27 Oct 2007, 12:19 PM.

      Comment


      • #4
        Thanx Dave and Pierre,
        I figured it was something as simple as that. :dang: and I just could not find it.

        I got things more or less running (minus a few bugs I have to look at, like my scrollbars disappearing, but that may be just the viewable size and scrollbars are off screen....will have to check)

        The other thing is my area to resize (the edge) is a little off...is this normal? or more likely a bad combination of flags when I create the RichEdit?
        Engineer's Motto: If it aint broke take it apart and fix it

        "If at 1st you don't succeed... call it version 1.0"

        "Half of Programming is coding"....."The other 90% is DEBUGGING"

        "Document my code????" .... "WHYYY??? do you think they call it CODE? "

        Comment


        • #5
          See how you go with this Cliff,
          '
          Code:
          #Include "WIN32API.INC"
          #Include "RICHEDIT.INC"
          '------------------/Includes
          'Subclass Macros                        (TT Colin Schmidt)
          Macro mSC_Set(hDlg, IdCtl, SubProc)
              SETWINDOWLONG GETDLGITEM(hDlg, IdCtl), %GWL_USERDATA, _
                  SETWINDOWLONG(GETDLGITEM(hDlg, IdCtl), %GWL_WNDPROC, CodePtr(SubProc))
          End Macro
           
          Macro mSC_OrgProc
              Function = CALLWINDOWPROC(GETWINDOWLONG(CbHndl, %GWL_USERDATA), CbHndl, CbMsg, CbWParam, CbLParam)
          End Macro
          '------------------/Macros
           
          CallBack Function DIALOGProc()
           Local RichText As String, RTFHeader As String
           Local cr As CHARRANGE
           
            Select Case CbMsg
              Case %WM_INITDIALOG
                Dialog Post CbHndl, %WM_USER + 1000, 0, 0
           
              Case %WM_USER + 1000, 0, 0
                RichText = _
                  "      Click-n-Drag the border of the RichEdit control to resize. \par\par "+ _
                  " Press Ctrl - Left_mouse & Drag inside the control to reposition. \par\par "+ _
                  "Using  style %ES_DISABLENOSCROLL will keep the scrollbar visable ( though "+ _
                  " it will appear 'disabled' if not actually needed ) \par\par "+ _
                  "Hope that helps.. \par\par  :-)"
                RTFHeader = "{\rtf1\ansi\ansicpg1252\deflang1033\deff0"+$CRLF+ _
                  "{\fonttbl{\f0\fswiss\fcharset0 Arial;}}\fs20"
           
                RichText = RTFHeader + RichText + "}"
                Control Set Text CbHndl, 101, RichText
                cr.cpMin = 5 : cr.cpMax = 63
                SendMessage GetDlgItem(CbHndl, 101), %EM_EXSETSEL, 0, VARPTR(cr)
           
              Case %WM_NCACTIVATE
                Static hWndSaveFocus As Dword
                If Isfalse CbWparam Then
                  hWndSaveFocus = GetFocus()
                Elseif hWndSaveFocus Then
                  SetFocus(hWndSaveFocus)
                  hWndSaveFocus = 0
                End If
           
            End Select
          End Function
          '------------------/DialogProc
          'SubClassed Proc for REdit control
          CallBack Function REditProc
           
            Select Case As Long CbMsg
              Case %WM_NCHITTEST
                If (GetAsyncKeyState(%VK_CONTROL) And &H8000) Then
                  Function = %HTCAPTION : Exit Function
                End If
           
          '    Case %WM_MOVE   ' casues flcker but sometimes loose 'resize' cursor w/out this??
          '      Dialog Redraw GetParent(CbHndl)   ' - got to be a better way :)
           
            End Select
           mSC_OrgProc                            ' call original DIALOGproc
          End Function
          '------------------/REditProc
          Function PbMain()
           Local lRslt As Long, hDlg As Dword
           LoadLibrary("RICHED32.DLL")
           
            Dialog New 0, "Resize control", , , 300, 220, %WS_SYSMENU, %WS_EX_TOPMOST To hDlg
            Control Add "RichEdit", hDlg, 101, "", 10, 10, 275, 90, _
              %WS_CHILD Or %WS_SIZEBOX Or %WS_VISIBLE Or %ES_MULTILINE Or %ES_WANTRETURN Or _ 
              %WS_VSCROLL Or %ES_DISABLENOSCROLL, %WS_EX_RIGHTSCROLLBAR
            mSC_Set(hDlg, 101, REditProc)         ' subclass control
           
            Dialog Show Modal hDlg, Call DIALOGProc
           
          End Function
          '------------------/PbMain
          '
          Rgds, Dave

          Comment

          Working...
          X