'====================================================================
' Simple modal dialog as main.
'====================================================================

$ filename "Menu3.exe"
'uses rtl32
'uses rtl64

'% review

uses dialogs

==============================================

'MAIN CODE
=============================================
 
'dim nCmdline as asciiz ptr, hInstance as sys
'&nCmdline = GetCommandLine
'hInstance = GetModuleHandle(NULL)


function DialogProc( sys hDlg, uint uMsg, sys wParam, lParam ) as int callback
  select case uMsg
  
    case WM_INITDIALOG
' a la .rc file
'1 MENU
sys hMenu
MENU(hMenu)

BEGIN
  POPUP "&File"
  BEGIN
    POPUP "&New"
    BEGIN
      MENUITEM "&Empty file",1100
      POPUP "By template &file..."
      BEGIN
        MENUITEM "Template 1",1102,CHECKED
        MENUITEM "Template 2",1103
        MENUITEM "Template 3",1104
      ENDMenu
      MENUITEM "SEPARATOR"
      MENUITEM "Empty &window",1105
    ENDMenu
    MENUITEM "&Open..." tab "Ctrl+O",1110
    MENUITEM "&Save" tab "Ctrl+S",1111
    MENUITEM "Save &as..." tab "F12",1112
    MENUITEM "SEPARATOR"
    MENUITEM "E&xit" tab "Alt+F4",1180
  ENDMenu
  POPUP "&Edit"
  BEGIN
    MENUITEM "U&ndo" tab "Ctrl+Z",1200,GRAYED
    MENUITEM "SEPARATOR"
    MENUITEM "&Cut" tab "Ctrl+X",1201,GRAYED
    MENUITEM "C&opy" tab "Ctrl+C",1202,GRAYED
    MENUITEM "&Paste" tab "Ctrl+V",1203
    MENUITEM "SEPARATOR"
    MENUITEM "Select &all" tab "Ctrl+A",1204
  ENDMenu
  MENUITEM "&Compile!",1301
  MENUITEM "&Run!",1302
  POPUP "&Tools"
  BEGIN
    MENUITEM "&Compile" tab "F5",1301
    MENUITEM "&Run" tab "F6",1302
    MENUITEM "SEPARATOR"
    MENUITEM "&Edit Resources" tab "F7",1311
    MENUITEM "SEPARATOR"
    MENUITEM "Code &formatter...",1321
  ENDMenu
  POPUP "&Options"
  BEGIN
    MENUITEM "&Font settings...",1401
    MENUITEM "&General settings...",1402
    MENUITEM "&Project settings...",1403
    MENUITEM "SEPARATOR"
    MENUITEM "Auto &indent",1411
  ENDMenu
  POPUP "&Help"
  BEGIN
    MENUITEM "Help &keyword..." tab "F1",1900
    MENUITEM "&Basic help" tab "Shift+F1",1901
    MENUITEM "&API help" tab "Alt+F1",1902
    MENUITEM "&Editor help" tab "Ctrl+F1",1903
    MENUITEM "SEPARATOR"
    MENUITEM "Ab&out",1909
  ENDMenu
ENDMenu

      SetMenu( hDlg, hMenu )
      'Accelerators not defined
      
      return true

    case WM_COMMAND
      select case loword(wParam)
        case IDCANCEL, 1180
           EndDialog( hDlg, null )
        case 1909
           mbox "Oxgen Menu Template"
        case else
           print loword(wParam) & " clicked!"
              
      end select
      
    case WM_CLOSE
      EndDialog( hDlg, null )
                
  end select

  return 0
end function

sub winmain()

  Dialog( 0, 0, 200, 100, "Memory based modal dialog using OxygenBasic",
          WS_OVERLAPPEDWINDOW or DS_CENTER )
  PushButton( "Close" , IDCANCEL, 80, 70, 40, 12 )

  CreateModalDialog( null, @DialogProc, 0 )
end sub

winmain()


