$ filename "Demo6.exe"

'uses rtl32
'uses rtl64

uses WinUtil
uses autosizing


sys You, Can, Do_, Odd, Things, With_, Autosizing_

enum  Control_ids
   ID_You=1001 
   ID_Can 
   ID_Do_ 
   ID_Odd 
   ID_Things 
   ID_With_ 
   ID_Autosizing_
end enum

% Btn_Style    = WS_CHILD|WS_VISIBLE|WS_TABSTOP
% Btn_ExtStyle = WS_EX_STATICEDGE

sys hInstance=inst
MainWindow 355,70,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 6")
           You = CreateControl("Button","You",hwnd,ID_You,                    5, 5, 40, 20, Btn_Style, Btn_ExtStyle)
           Can = CreateControl("Button","Can",hwnd,ID_Can,                   45, 5, 40, 20, Btn_Style, Btn_ExtStyle)
           Do_ = CreateControl("Button","Do",hwnd,ID_Do_,                    85, 5, 40, 20, Btn_Style, Btn_ExtStyle)
           Odd = CreateControl("Button","Odd",hwnd,ID_Odd,                  125, 5, 40, 20, Btn_Style, Btn_ExtStyle)
           Things = CreateControl("Button","Things",hwnd,ID_Things,         165, 5, 50, 20, Btn_Style, Btn_ExtStyle)
           With_ = CreateControl("Button","With",hwnd,ID_With_,             215, 5, 50, 20, Btn_Style, Btn_ExtStyle)
           Autosizing_ = CreateControl("Button","Autosizing",hwnd,ID_Autosizing_, 265, 5, 70, 20, Btn_Style, Btn_ExtStyle)

           pinCtl(You, hwnd,        "1.3, 0  ")
           pinCtl(Can, hwnd,        "  0, 0.3")
           pinCtl(Do_, hwnd,        "0.5, 0.5")
           pinCtl(Odd, hwnd,        "0.1, 1.0")
           pinCtl(Things, hwnd,     "0.9, 0.1")
           pinCtl(With_, hwnd,      "0.6, 0.8")
           pinCtl(AutoSizing_, hwnd,"0.2, 0.4")                       

        case WM_COMMAND

        case WM_GETMINMAXINFO
        
        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
