$ filename "Demo4.exe"

'uses rtl32
'uses rtl64

uses WinUtil
uses autosizing

sys hControl[25]

int i
int ctl_id[25]
for i=1 to 25 : ctl_id=1000+i : next

% Mle_Style    = WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_VSCROLL|WS_BORDER|ES_LEFT|ES_MULTILINE|WS_HSCROLL
% Mle_ExtStyle = WS_EX_CLIENTEDGE

sys hInstance=inst
MainWindow 400,420,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 4")

           int i, j, idx
           for i=1 to 5
             for j=1 to 5
                idx+=1
                hControl[idx]=CreateControl("Edit", str(idx), hWnd, ctl_id[idx], (j-1)*75+5, (i-1)*75+5, 75, 75, Mle_Style, Mle_ExtStyle) 
             next j
           next i  

           idx=0
           string p1, p2
           for i=1 to 5
             for j=1 to 5
               idx+=1
               p1=str((j-1)*0.20) ", " str((i-1)*0.20)
               p2=str(j*0.20) "," str(i*0.20)
               pinCtl(hControl[idx], hwnd, p1, p2)
             next j
           next i
           
           unpinCtl(hControl[1],hwnd, 350,350)
           
           string s : getfile "demo4.o2bas", s
           for i=1 to 25
             SetWindowText(hControl[i], s)
           next  
               
        case WM_COMMAND

        case WM_GETMINMAXINFO
           setMinSize 200,200

        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
