

  'http://msdn.microsoft.com/en-us/library/ms632598(VS.85).aspx

  $ filename "t.exe"
  includepath "$/inc/"
  '#include "RTL32.inc"
  '#include "RTL64.inc"
  #include "MinWin.inc"

  % ID_FIRSTCHILD  100 
  % ID_SECONDCHILD 101 
  % ID_THIRDCHILD  102 


  sys hinstance
  sys hWndMain

  '===================================
  
  sys inst=GetModuleHandle 0
  asciiz * cmdline 
  @cmdline=GetCommandLine
  string szAppName="Hello Window"
  string szconfirm="Confirm Quit"

  '===================================
 





  '------------------------------------------------------------ -------
  Function WinMain(sys inst, prevInst, asciiz*cmdline, sys show) as sys
  '====================================================================
                    '
  ; window handle
  
  dim a,b,c,style,hWnd as sys
  dim wc as WndClass
  dim wm as MSG

  with wc                 '
    .style=CS_HREDRAW or CS_VREDRAW
    .lpfnWndProc=@wndproc
    .cbClsExtra=0
    .cbWndExtra=0    
    .hInstance=inst
    .hIcon=LoadIcon 0, IDI_APPLICATION
    .hCursor=LoadCursor 0,IDC_ARROW
    .hbrBackground=GetStockObject WHITE_BRUSH '
    .lpszMenuName=0
    .lpszClassName=@"Wins"
  end with

  hinstance=inst

  if not RegisterClass @wc
    MessageBox 0,`Registration failed`,`Problem`,MB_ICONERROR
    exit function
  end if 


  style=WS_OVERLAPPEDWINDOW
  style=WS_OVERLAPPEDWINDOW | // overlapped window 
        WS_HSCROLL |          // horizontal scroll bar
        WS_VSCROLL            // vertical scroll bar


  // Create the main window. 

   hwndMain = CreateWindowEx( 
    0,                      // no extended styles           
    "Wins",                 // class name                   
    "Main Window",          // window name  
    style,                  //                
    CW_USEDEFAULT,          // default horizontal position  
    CW_USEDEFAULT,          // default vertical position    
    CW_USEDEFAULT,          // default width                
    CW_USEDEFAULT,          // default height               
    NULL,                   // no parent or owner window    
    NULL,                   // class menu used              
    hinstance,              // instance handle              
    NULL);                  // no window creation data      


  // Show the window using the flag specified by the program 
  // that started the application, and send the application 
  // a WM_PAINT message. 

  hwnd=hwndMain
      
  if not hWnd then
    MessageBox 0,`Unable to create window`,`problem`,MB_ICONERROR
    exit function
  end if
                         '
  ShowWindow hWnd,show
  UpdateWindow hWnd
  ' 
  'MESSAGE LOOP
  '
  'do while GetMessage &wm,0,0,0
  '  TranslateMessage &wm
  '  DispatchMessage &wm
  'wend
  '
  sys bRet
  '
  do while bRet := GetMessage (&wm, 0, 0, 0)
    if bRet == -1 then
      'show an error message?
    else
      TranslateMessage &wm
      DispatchMessage &wm
    end if
  wend
  '
  '
  function=wm.wparam

  end function ; end of WinMain



  WinMain inst,0,cmdline,SW_NORMAL
  end



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




  dim cRect   as rect
  dim Paintst as paintstruct

  dim hDC     as sys


  '------------------------------------------------------------------------------------
  function WndProc(dword hwnd, dword uMsg, dword wParam, dword lParam) as long callback
  '====================================================================================
  { 
    RECT rcClient; 
    sys i,w,px,py,lx,ly,id,idmenu,style 
    string sty
 
    select umsg 
 
        case WM_CREATE: // creating main window  
 
            // Create three child windows.

            style=WS_CHILD | WS_BORDER | WS_VISIBLE
            idmenu=0
            py=10 : ly=480
            ;
            for i = 0 to 2
                id=ID_FIRSTCHILD+i

                px=10+i*200 : lx=180
                '
                if i<2 then
                  sty="Edit"
                elseif i=2 then
                  sty="graphic"
                end if
                '
                w=CreateWindowEx(0,*sty, NULL, style, px,py,lx,ly, hwnd, id, inst, NULL);
            next
            return 0; 
 
        case WM_SIZE:   // main window changed size 
 
            // Get the dimensions of the main window's client 
            // area, and enumerate the child windows. Pass the 
            // dimensions to the child windows during enumeration. 
 
            GetClientRect(hwnd, &rcClient); 
            EnumChildWindows(hwnd, & EnumChildProc, &rcClient); 
            return 0; 

        case WM_CLOSE: 
          // Create the message box. If the user clicks 
	  // the Yes button, destroy the main window. 
 
         if (MessageBox(hwnd, *szConfirm, *szAppName, MB_YESNOCANCEL) == IDYES) 
           DestroyWindow(hwndMain); 
         else 
           return 0; 
         end if

         case WM_DESTROY: 
 
         // Post the WM_QUIT message to 
         // quit the application terminate. 
 
         PostQuitMessage(0); 
         return 0;


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

 
  '-------------------------------------------------------------
  function EnumChildProc(sys hwndChild, lParam) as bool callback
  '=============================================================
  { 
    RECT * rcParent; 
    sys i, idChild;
    sys v,w,info
 
    // Retrieve the child-window identifier. Use it to set the 
    // position of the child window. 
    info=GWL_ID
    idChild = GetWindowLong(hwndChild, info)
 
    if idChild == ID_FIRSTCHILD then 
        i = 0; 
    else if (idChild == ID_SECONDCHILD) 
        i = 1; 
    else 
        i = 2; 
    end if

    // Size and position the child window.  
 
    & rcParent = lParam;
    v=rcParent.right/3
    w=v*i
    MoveWindow(hwndChild, w, 0, v, rcParent.bottom, TRUE); 
 
    // Make sure the child window is visible. 
 
    ShowWindow(hwndChild, SW_SHOW); 
 
    return TRUE;
  }
