Author Topic: Dynamic Moving and Resizing controls  (Read 683 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Dynamic Moving and Resizing controls
« on: September 02, 2020, 02:59:03 AM »
A simple window with 2 edit boxes. when the window is stretched the first box keeps its position but the second adjusts its size to fit the space available.

The position and size of each child window is entirely controlled by MoveWindow calls in the WM_SIZE case. WM_SIZE is always called when the child window is created, so there is no need to specify location and size in WM_CREATE.

Code: [Select]


  '$ filename "t.exe"
  'uses RTL32
  'uses RTL64
  $ EscapeKeyEnd
  uses WinUtil
  MainWindow 640,480,WS_OVERLAPPEDWINDOW



  'STANDARD CHILD WINDOWS STYLES
  '=============================
  '
  'Button button.
  'ComboBox combo box.
  'Edit         edit box.
  'ListBox list box.
  'MDIClient MDI client window.
  'ScrollBar scroll bar.
  'Static static control.



  function WndProc(sys hwnd, uMsg, wParam, lParam) as long callback
  '================================================================
  indexbase 0
  RECT rcClient;
  sys i,id,idmenu,style
  static sys hchw[0x200] 'child windows
  string s,stys
 
  select umsg
 
  case WM_CREATE

    idmenu=0
    '
    SetWindowText hwnd,"Edit Box Dynamic Resize"
    style=WS_CHILD | WS_BORDER | WS_VISIBLE
    stys="edit"
    hchw[0]=CreateWindowEx(0,stys, null, style, 0,0,0,0, hwnd, 100, inst, null)
    hchw[1]=CreateWindowEx(0,stys, null, style, 0,0,0,0, hwnd, 101, inst, null)
    ShowWindow(hchw[i], SW_SHOW)

  case WM_SIZE   // main window changed size

    RECT rc
    GetClientRect(hwnd, &rc)
    'child window, position x,y  size x.y, show
    MoveWindow(hchw[0], 10,10, 200, 40, TRUE)
    MoveWindow(hchw[1], 10,60, rc.right-20, rc.bottom-70, TRUE)

  case WM_DESTROY:
 
    PostQuitMessage 0

  case else

    return DefWindowProc(hwnd, uMsg, wParam, lParam)
  end select
  '
  end function