透明gif作为listview图标完全透明,放在picture控件里面就不透明了
pb9.03 8836
透明gif作为listview图标完全透明,放在picture控件里面就不透明了,老问题?
可以解决吗?
[解决办法]
$PBExportHeader$w_test.srw
forward
global type w_test from window
end type
type p_1 from picture within w_test
end type
type bitmap from structure within w_test
end type
end forward
global type bitmap from structure
long bmtype
long bmwidth
long bmheight
long bmwidthbytes
long bmplanes
long bmbitspixel
blob bmbits
end type
global type w_test from window
integer width = 2217
integer height = 1428
boolean titlebar = true
string title = "Untitled"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
boolean resizable = true
long backcolor = 67108864
string icon = "AppIcon!"
boolean center = true
event ue_paint pbm_paint
p_1 p_1
end type
global w_test w_test
type prototypes
FUNCTION ulong GetPixel(ulong hdc,ulong px,ulong py) LIBRARY "gdi32.dll"
Function uLong GetDC(uLong hwnd) LIBRARY "user32.dll"
//Function uLong StretchBlt(uLong hdc,uLong xx,uLong yy,uLong nWidth,uLong nHeight,uLong hSrcDC,uLong xSrc,uLong ySrc,uLong nSrcWidth,uLong nSrcHeight,uLong dwRop) LIBRARY "gdi32.dll"
Function uLong DeleteDC(uLong hdc) LIBRARY "gdi32.dll"
Function uLong DeleteObject(uLong hObject) LIBRARY "gdi32.dll"
Function uLong SelectObject(uLong hdc,uLong hObject) LIBRARY "gdi32.dll"
Function uLong GetObjectBitmap( uLong hgdiobj, int cbBuffer, ref bitmap bm ) library "gdi32.dll" alias for GetObjectA
Function uLong LoadImage(uLong hInst,ref String lpsz,uLong un1,uLong n1,uLong n2,uLong un2) LIBRARY "user32.dll" ALIAS FOR "LoadImageA"
Function uLong CreateCompatibleDC(uLong hdc) LIBRARY "gdi32.dll"
FUNCTION ulong ReleaseDC(ulong hwnd,ulong hdc) LIBRARY "user32.dll"
Function uLong SetBkColor(uLong hdc,uLong crColor) LIBRARY "gdi32.dll"
Function long CreateCompatibleBitmap ( long hdc, long nwidth, long nheight ) library "gdi32"
Function long CreateBitmap ( long nwidth, long nheight, long nplanes, long nbitcount, long lpbits ) library "gdi32"
Function uLong BitBlt(uLong hDestDC,uLong xx,uLong yy,uLong nWidth,uLong nHeight,uLong hSrcDC,uLong xSrc,uLong ySrc,uLong dwRop) LIBRARY "gdi32.dll"
FUNCTION ulong SetBkMode(ulong hdc,ulong nBkMode) LIBRARY "gdi32.dll"
end prototypes
type variables
constant long SRCCOPY = 13369376
constant long NOTSRCCOPY = 3342344
constant long SRCAND = 8913094
constant long SRCINVERT = 6684742
uLONG il_memDC,il_old,il_windc,il_outputdc
ulong il_rgb
//需要透明输出的图片,自己定义图片路径
string is_cmenu_pic = 'C:\powerbuilder\SERVER.BMP'
integer ii_bmpwidth,ii_bmpheight
end variables
forward prototypes
public subroutine wf_transparentblt (long dstdc, long srcdc, integer srcx, integer srcy, integer srcw, integer srch, integer dstx, integer dsty, long transcolor)
public subroutine wf_paint ()
end prototypes
event ue_paint;
post wf_paint()
end event
public subroutine wf_transparentblt (long dstdc, long srcdc, integer srcx, integer srcy, integer srcw, integer srch, integer dstx, integer dsty, long transcolor); // DstDC - Device context into image is actually drawn
// SrcDC - Device context of source to be made transparent in color TransColor
// SrcX, SrcY, SrcW, SrcH - Rectangular region of source bitmap in pixels
// DstX, DstY - Coordinates in OutDstDC where the transparent bitmap must go
// TransColor - Transparent color
// 输出透明图像到DstDC
Long nRet,MonoMaskDC,hMonoMask,MonoInvDC,hMonoInv,hResultDst,ResultDstDC
long ResultSrcDC,hResultSrc,hPrevMask,hPrevInv,hPrevSrc,hPrevDst
long OldBC
Integer OldMode
//Create monochrome mask and inverse masks
MonoMaskDC = CreateCompatibleDC(DstDC)
MonoInvDC = CreateCompatibleDC(DstDC)
//Create monochrome bitmaps for the mask-related bitmaps:
hMonoMask = CreateBitmap(SrcW, SrcH, 1, 1, 0)
hMonoInv = CreateBitmap(SrcW, SrcH, 1, 1, 0)
hPrevMask = SelectObject(MonoMaskDC, hMonoMask)
hPrevInv = SelectObject(MonoInvDC, hMonoInv)
// Create keeper DCs and bitmaps
ResultDstDC = CreateCompatibleDC(DstDC)
ResultSrcDC = CreateCompatibleDC(DstDC)
//Create color bitmaps for final result & stored copy of source
hResultDst = CreateCompatibleBitmap(DstDC, SrcW, SrcH)
hResultSrc = CreateCompatibleBitmap(DstDC, SrcW, SrcH)
hPrevDst = SelectObject(ResultDstDC, hResultDst)
hPrevSrc = SelectObject(ResultSrcDC, hResultSrc)
// Copy src to monochrome mask
OldBC = SetBkColor(SrcDC, TransColor)
nRet = BitBlt(MonoMaskDC, 0, 0, SrcW, SrcH, SrcDC,SrcX, SrcY, SrcCopy)
TransColor = SetBkColor(SrcDC, OldBC)
//Create inverse of mask
nRet = BitBlt(MonoInvDC, 0, 0, SrcW, SrcH, MonoMaskDC, 0, 0, NotSrcCopy)
//Copy background bitmap to result & create final transparent bitmap
nRet = BitBlt(ResultDstDC, 0, 0, SrcW, SrcH, DstDC, DstX, DstY, SrcCopy)
//AND mask bitmap w/ result DC to punch hole in the background by
//painting black area for non-transparent portion of source bitmap.
nRet = BitBlt(ResultDstDC, 0, 0, SrcW, SrcH, MonoMaskDC, 0, 0, SrcAnd)
// Get overlapper
nRet = BitBlt(ResultSrcDC, 0, 0, SrcW, SrcH, SrcDC, SrcX, SrcY, SrcCopy)
//AND inverse mask w/ source bitmap to turn off bits associated
//with transparent area of source bitmap by making it black.
nRet = BitBlt(ResultSrcDC, 0, 0, SrcW, SrcH, MonoInvDC, 0, 0, SrcAnd)
//XOR result w/ source bitmap to make background show through.
nRet = BitBlt(ResultDstDC, 0, 0, SrcW, SrcH, ResultSrcDC, 0, 0, SrcInvert)
//Output results
nRet = BitBlt(DstDC, DstX, DstY, SrcW, SrcH, ResultDstDC, 0, 0, SrcCopy)
// Clean up
hMonoMask = SelectObject(MonoMaskDC, hPrevMask)
DeleteObject (hMonoMask)
hMonoInv = SelectObject(MonoInvDC, hPrevInv)
DeleteObject (hMonoInv)
hResultDst = SelectObject(ResultDstDC, hPrevDst)
DeleteObject (hResultDst)
hResultSrc = SelectObject(ResultSrcDC, hPrevSrc)
DeleteObject (hResultSrc)
DeleteDC (MonoMaskDC)
DeleteDC(MonoInvDC)
DeleteDC (ResultDstDC)
DeleteDC (ResultSrcDC)
end subroutine
public subroutine wf_paint ();ulong ll_bmp,ll_new
bitmap lus_bmp
long ll_inst
SetNull(ll_inst)
il_windc = getdc(handle(p_1))
//GetDC(Handle(this))
il_memDC = CreateCompatibleDC(il_windc)
//载入图片
ll_bmp = LoadImage(ll_inst,is_cmenu_pic,0,0,0,16)
if ll_bmp = 0 then return
GetObjectBitmap( ll_bmp, 28, lus_bmp )
ii_bmpwidth= lus_bmp.bmwidth
ii_bmpheight=lus_bmp.bmheight
il_old = SelectObject(il_memDC,ll_bmp)
il_rgb = GetPixel(il_memDC,0,0)//左上角第一点rgb作为透明的rgb
//il_rgb为需要透明的颜色
//p_1.width = PixelsToUnits(ii_bmpwidth, XPixelsToUnits!)
//p_1.height= PixelsToUnits(ii_bmpheight, YPixelsToUnits!)
//100,100为输出的位置
wf_transparentblt(il_windc,il_memDC,0,0,ii_bmpwidth,ii_bmpheight,10,10,il_rgb)
//释放资源
Deleteobject(ll_bmp)
SelectObject(il_memDC,il_old)
DeleteDC(il_memDC)
ReleaseDC(handle(p_1),il_windc)
end subroutine
on w_test.create
this.p_1=create p_1
this.Control[]={this.p_1}
end on
on w_test.destroy
destroy(this.p_1)
end on
event open;//背景图片
p_1.picturename="G:\codepb\网上\Splash.bmp"
post wf_paint()
end event
type p_1 from picture within w_test
event ue_paint pbm_paint
integer width = 4681
integer height = 1920
boolean enabled = false
boolean originalsize = true
boolean focusrectangle = false
end type