2004/6/20公開
2004/7/13更新

;*****************************************************
;       ○画像の読み込み
;       LoadPicture p1
;       p1:画像ファイル名(packfile・memfile可)
;       p2:画面の初期化モード(0=初期化する,1=初期化しない)
;
;       現在のウインドウに画像(BMP,JPEG,GIF,ICO)を読み込みます。
;       p2を0にすると画面を初期化してから画像を読み込みます。
;       p2を1にした場合は初期化せずに、現在位置(pos命令で指定)に画像を読み込みます。
;       p2に0を指定して、透過画像を読み込む場合にはcolor命令で指定されている色を透過色に割り当てます。
;       成功した場合statに0がセットされます。
;
;       初期状態のWin95ではJPEGとGIFは読めないかもしれません(win95+IE5.0で動作確認)
;---------------------------------------------------
#module
        #define SETUUID(%1,%2,%3,%4,%5,%6) ll_bin %1,"%5 %6":%1.3=%1,%1.1:%1.1=$%2,$%4<<16|$%3:ll_getptr %1.1:ll_ret %1
        #define LOGPIXELSX      $00000058
        #define LOGPIXELSY      $0000005A
        #define GMEM_MOVEABLE   $00000002
        #define GMEM_NODISCARD  $00000020
        #define HIMETRIC_INCH   2540
        #define PICTURE_TRANSPARENT     $00000002
        #define Release 2       ;IUnknown's method
        #define get_Width 6     ;IPicture's method
        #define get_Height 7
        #define Render 8
        #define get_Attributes 16
#deffunc LoadPicture str,int
        mref picfile,32
        mref mode,1
        mref _stat,64
        mref bm,67
        ll_libload hOle,"ole32.dll"
        ll_libload hOleaut,"oleaut32.dll"
        ll_libload hKernel,"kernel32.dll"
        ll_libload hGdi,"gdi32.dll"
        ll_getproc pGlobalAlloc,"GlobalAlloc",hKernel
        ll_getproc pGlobalLock,"GlobalLock",hKernel
        ll_getproc pGlobalUnlock,"GlobalUnlock",hKernel
        ll_getproc pCreateStreamOnHGlobal,"CreateStreamOnHGlobal",hOle
        ll_getproc pOleLoadPicture,"OleLoadPicture",hOleaut
        ll_getproc pGetDeviceCaps,"GetDeviceCaps",hGdi

        SETUUID IID_IPicture,7BF80980,BF32,101A,8BBB,00AA00300CAB
        exist picfile :fsize=strsize
        if strsize<0:stt=1:goto *fin
        sdim buf,fsize:  bload picfile,buf
        prm=GMEM_MOVEABLE|GMEM_NODISCARD,fsize: ll_callfunc prm,2,pGlobalAlloc: ll_ret hImage
        if hImage==0:stt=2:goto *fin
        ll_callfunc hImage,1,pGlobalLock: ll_ret pImage
        ll_poke buf,pImage,fsize: sdim buf,1: ll_callfunc hImage,1,pGlobalUnlock
        prm=hImage,1: ll_getptr pIStream: ll_ret prm.2
        ll_callfunc prm,3,pCreateStreamOnHGlobal: ll_ret result: if result:stt=3:goto *fin
        ll_peek4 pvtbl,pIStream : ll_peek stmtbl,pvtbl,3*4
        prm=pIStream,fsize,1,IID_IPicture: ll_getptr pIPicture: ll_ret prm.4
        ll_callfunc prm,5,pOleLoadPicture: ll_ret result: if result:stt=4:goto *fin
        ll_peek4 pvtbl,pIPicture: dim pictbl,17: ll_peek pictbl,pvtbl,17*4
        prm=pIPicture:ll_getptr hx:ll_ret prm.1: ll_callfunc prm,2,pictbl.get_Width
        prm=pIPicture:ll_getptr hy:ll_ret prm.1: ll_callfunc prm,2,pictbl.get_Height
        prm=bm.4,LOGPIXELSX: ll_callfunc prm,2,pGetDeviceCaps: ll_ret cxPerInch
        prm=bm.4,LOGPIXELSY: ll_callfunc prm,2,pGetDeviceCaps: ll_ret cyPerInch
        px=hx*cxPerInch+(HIMETRIC_INCH/2)/HIMETRIC_INCH :py=hy*cyPerInch+(HIMETRIC_INCH/2)/HIMETRIC_INCH
        if mode==0{
                initcolor=bm.40
                if bm.17==1{
                        buffer bm.18,px,py,0
                }else{if bm.17==2{
                        bgscr bm.18,px,py,0
                }else{
                        screen bm.18,px,py,0
                }}
                cx=0:cy=0
                prm=pIPicture:ll_getptr attr:ll_ret prm.1: ll_callfunc prm,2,pictbl.get_Attributes
                if attr==PICTURE_TRANSPARENT{
                        redraw 0
                        color initcolor&$ff,initcolor>>8&$ff,initcolor>>16&$ff
                        boxf 0,0,px,py
                        color
                }
        }else{
                cx=bm.27:cy=bm.28
        }
        mref bm,67
        prm=pIPicture,bm.4,cx,cy,px,py,0,hy,hx,-hy,0: ll_callfunc prm,11,pictbl.Render: ll_ret result
        if result:stt=5:goto *fin
        redraw 1
        stt=0
        *fin
        if pIPicture:ll_callfunc pIPicture,1,pictbl.Release: pIPicture=0
        if pIStream:ll_callfunc pIStream,1,stmtbl.Release: pIStream=0
        ll_libfree hOle
        ll_libfree hOleaut
        ll_libfree hKernel
        ll_libfree hGdi
        _stat=stt
        return
#global
;*****************************************************

;以下使用例
dialog "bmp;*.jpg;*.gif;*.ico",16
if stat==0:end
LoadPicture refstr
if stat:mes "エラー"
stop



戻る