'====================================================================
' Simple modeless dialog as main.
'====================================================================

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

'% review

uses dialogs

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

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


function DlgProc( sys hDlg, uint uMsg, sys wParam, lParam ) as int callback
   select case uMsg
  
     case WM_INITDIALOG
        ShowWindow(hDlg, SW_NORMAL)

     case WM_COMMAND
        select case loword(wParam)
          case IDCANCEL
             DestroyWindow( hDlg )
        end select
      
     case WM_CLOSE
        DestroyWindow( hDlg )

     case WM_DESTROY
        PostQuitMessage( null )
                
   end select

   return 0
end function


sub winmain()

   sys hDlg, bRet
   MSG Msg

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

   hDlg = CreateModelessDialog( null, @DlgProc, 0)

   while bRet := GetMessage(&Msg, NULL, 0, 0)
     if bRet = -1 then
       'show an error message
       print "Error in Message Loop"
       end
     else
       if not IsDialogMessage(hDlg, &Msg) then
         TranslateMessage(&Msg)
         DispatchMessage(&Msg)
       end if
     end if
   wend

end sub

winmain()

