'====================================================================
' Bitmap and icons loaded from file, modal dialog as main.
' maybe o2dir must be adapted
'====================================================================

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

'% review

uses dialogs

'maybe must be set to correct path
string o2dir = "..\..\"    '"c:\oxygenbasic\"
string fullname

function DialogProc( sys hDlg, uint uMsg, sys wParam, lParam ) as int callback

  sys hicon,hBitmap
  string names[3]
  sys ids[3]
  string fullname
   
  select case uMsg

    case WM_INITDIALOG
      fullname = o2dir + "tools\oxicon.ico"    'OxideIcon.ico"
      sys hIcon = LoadImage( 0, fullname, IMAGE_ICON,0,0, LR_LOADFROMFILE )
      if hIcon=null then mbox "Cannot load " + fullname +"!"
      SendMessage( hDlg, WM_SETICON, ICON_SMALL, hIcon)

    names[] = {o2dir +"demos\!projB\SDL\bmp\pumpa.bmp",
               o2dir +"demos\!projB\Scintilla\data\rubenX.bmp",
               o2dir +"demos\!projB\SDL\bmp\angel.bmp" }
    ids[] = {1000,1001,1002}
    int x
    for x=1 to 3
      hBitmap = LoadImage( null, names[x] , IMAGE_BITMAP,180,180, LR_LOADFROMFILE)
      if hBitmap=null then mbox names[x] + " missing!"     
      SendMessage (GetDlgItem(hDlg,ids[x]), STM_SETIMAGE, IMAGE_BITMAP, hBitmap)
    next x

    names[] = {o2dir +"tools\oxideIcon.ico",
               o2dir +"tools\oxicon.ico"}
    ids[] = {1005,1006}

    for x=1 to 2
      hBitmap = LoadImage( null, names[x] , IMAGE_ICON,180,180, LR_LOADFROMFILE)
      if hBitmap=null then mbox names[x] + " missing!"     
      SendMessage (GetDlgItem(hDlg,ids[x]), STM_SETIMAGE, IMAGE_ICON, hBitmap)
    next x
                                
    case WM_CLOSE
      EndDialog( hDlg, null )

  end select

  return 0

end function

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

Dialog( 0, 0, 290, 250,"Bitmap and Icon Demo",     'dialog units
        WS_OVERLAPPEDWINDOW or DS_CENTER )

Control( "",1000, "STATIC", SS_BITMAP, 0, 30, 0, 0 )
Bitmap( "", 1001, 100, 30, 0, 0)
Bitmap( "", 1002, 200, 30, 0, 0)

CText ( "Bitmap and icon images adapted, original size:", -1, 0, 10, 250,20 )
LText ( "                 128x128               " &
             "                   80x80                        " &
             "                 256x256", -1, 0, 125,290,20 )
                                   
'Control(  "",1005, "STATIC", SS_ICON, 0, 140 )
Icon( "", 1005,   0, 140)
Icon( "", 1006, 100, 140)
LText ( "                   48x48                 " &
             "                   48x48", -1,  0, 235,290,20 )

CreateModalDialog( null, @DialogProc, 0 )

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