'====================================================================
' Icon as Application Icon and Bitmap from resource, modal dialog as main.
'
' Resources must be kept in a .rc file e.g.
' 1000 Icon   "..\..\..\tools\oxicon.ico"
' 1001 BITMAP DISCARDABLE "kurbis.bmp"
'
' The compiled .res file can be linked with LinkRes.exe
' or directlly with co2.exe / co2m64.exe by adding the Name.res file   
'====================================================================

#compact

$ filename "AppIcon.exe"

uses dialogs

% IDI_APPICON=1000
% IDB_BITMAP =1001

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

'MAIN CODE
=============================================
 
sys hInstance = GetModuleHandle(NULL)


function DialogProc( sys hDlg, uint uMsg, sys wParam, lParam ) as int callback
  select case uMsg
  
    case WM_INITDIALOG
       sys AppIcon = LoadIcon(hInstance, IDI_APPICON)
       'Set Icon to Main Window
       SendMessage(hDlg, WM_SETICON, ICON_BIG, AppIcon)
       return true

    case WM_COMMAND
       select case loword(wParam)
         case IDCANCEL
            EndDialog( hDlg, null )
       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 )

  Control("",100, "STATIC",SS_BITMAP, 0, 0, 0, 0, , 1001)

  CreateModalDialog( null, @DialogProc, 0 )
end sub

winmain()
