$ filename "Demo2.exe"

'uses rtl32
'uses rtl64

uses WinUtil
uses autosizing


sys Button_TR, Button_BL, Button_BLBR, Button_BR, MleText_TLBM, MleText_TMBR

enum  Control_ids
   ID_Button_TR=1001
   ID_Button_BL
   ID_Button_BLBR
   ID_Button_BR
   ID_MleText_TLBM
   ID_MleText_TMBR   
end enum

% Btn_Style    = WS_CHILD|WS_VISIBLE|WS_TABSTOP
% Btn_ExtStyle = WS_EX_STATICEDGE
% Mle_Style    = WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_VSCROLL|WS_BORDER|ES_LEFT|ES_MULTILINE
% Mle_ExtStyle = WS_EX_CLIENTEDGE

sys hInstance=inst
MainWindow 410,340,WS_OVERLAPPEDWINDOW

function createControl(string ctlclass, string Text, sys hwnd, int id, x,y,w,h, int Style, optional ExStyle=0) as sys
   sys hCtrl
   hCtrl=CreateWindowEx(ExStyle, ctlclass, Text, Style, x,y,w,h,  hWnd, id, hInstance, null)
   if hCtrl=null then mbox "Error: Cannot create " ctlclass
   return hCtrl
end function

function WndProc(sys hwnd, uint uMsg, sys wParam, lParam) as sys callback

    select uMsg

        case WM_CREATE
           SetWindowText(hwnd, "Autosize Demo 2")
           Button_TR = CreateControl("Button","TR",hwnd,ID_Button_TR, 296, 8, 88, 24, Btn_Style, Btn_ExtStyle)
           Button_BL = CreateControl("Button","BL",hwnd,ID_Button_BL, 8, 272, 88, 24, Btn_Style, Btn_ExtStyle) 
           Button_BLBR = CreateControl("Button","BLBR",hwnd,ID_Button_BLBR, 152, 272, 88, 24, Btn_Style, Btn_ExtStyle)
           Button_BR = CreateControl("Button","BR",hwnd,ID_Button_BR, 296, 272, 88, 24, Btn_Style, Btn_ExtStyle)
           MleText_TLBM = CreateControl("Edit","Top left attached to top left corner, bottom right attached to bottom middle (TL, BM)",hwnd,ID_MleText_TLBM, 8, 8, 232, 256, Mle_Style, Mle_ExtStyle)
           MleText_TMBR = CreateControl("Edit","Top left attached to top middle, bottom right attached to bottom right corner (TM, BR)",hwnd,ID_MleText_TMBR, 248, 48, 136, 216, Mle_Style, Mle_ExtStyle)

           pinCtl(Button_TR, hwnd, "TR")
           pinCtl(Button_BL, hwnd, "BL")
           pinCtl(Button_BLBR, hwnd, "BL","BR")
           pinCtl(Button_BR, hwnd, "BR")
           pinCtl(MleText_TLBM, hwnd, "TL","BM" )
           pinCtl(MleText_TMBR, hwnd, "TM","BR" )

        case WM_COMMAND

        case WM_GETMINMAXINFO
           'setMinSize 360,180
           unpinCtl(MleText_TLBM, hwnd, 370,245)
           
        case WM_SIZE
           resizeControls(hwnd)

        case WM_CLOSE
           DestroyWindow(hwnd)

        case WM_DESTROY
           PostQuitMessage(0)

        case else
           return DefWindowProc(hwnd, uMsg, wParam, lParam)
            
    end select

    return 0
end function
