'/////////////////////////////////////////////////////////////////////////////// 
'// 
'// Project Name : QPicture Demo for RapidQ 
'// Version      : 1.04.2006.19 
'// Author       : Don67geo@Yahoo.com 
'// Date         : April 19th, 2006 
'// 
'/////////////////////////////////////////////////////////////////////////////// 
$typecheck on 

$include "QPicture.inc" 

declare sub paintpic 
declare sub appexit 
declare sub openfile 

dim pix as qpicture 
dim fd as qopendialog 
defint dstWidth,dstHeight 
dim rt as qrect 

create me as qform 
    caption        = "QPicture Demo" 
    create mm as qmainmenu 
    create fm as qmenuitem 
      caption      = "&File" 
      create fo as qmenuitem 
        caption    = "&Open a Picture" 
        onclick    = openfile 
      end create 
      create fe as qmenuitem 
        caption    = "E&xit" 
        onclick    = appexit 
      end create 
    end create 
    end create 
    onpaint        = paintpic 
end create 

pix.parent = me.handle 
fd.filter = "Supported Files Types "+_ 
            "(*.bmp;*.gif;*.jpg;*.ico;*.emf;*.wmf)|"+_ 
            "*.bmp;*.gif;*.jpg;*.ico;*.emf;*.wmf|"+_ 
            "Bitmaps (*.bmp)|*.bmp|"+_ 
            "GIF Files (*.gif)|*.gif|"+_ 
            "JPEG Files (*.jpg)|*.jpg|"+_ 
            "Icons (*.ico)|*.ico|"+_ 
            "Enhanced Metafiles (*.emf)|*.emf|"+_ 
            "Windows Metafiles (*.wmf)|*.wmf||" 
me.showmodal 
if pix.valid=1 then pix.Free 
end 

sub openfile 
    if fd.execute<>0 then 
       if pix.valid=1 then pix.Free 
       defstr fname=fd.filename 
       pix.LoadFromFile(fname) 
    
       dstWidth  = pix.Width 
       dstHeight = pix.Height 

       me.clientheight = dstHeight 
       me.clientwidth  = dstWidth 
    
       rt.top=0 
       rt.left=0 
       rt.right=me.clientwidth 
       rt.bottom=me.clientheight 
    
       if me.top+me.height>screen.height then me.height=screen.height-me.top 
       if me.left+me.width>screen.width then me.width=screen.width-me.left 

       me.caption = "QPicture Demo - "+fname 
       me.repaint 
    end if 
end sub 

sub paintpic 
    me.fillrect(0,0,me.clientwidth,me.clientheight,&hFFFFFF) 
    if pix.valid=1 then pix.Render(me.handle,0,0,dstWidth,dstHeight,rt) 
end sub 

sub appexit 
    me.close 
end sub 
