您的位置:首页 > 其它

如何在PB中实现透明DATAWINDOW?

2005-06-22 20:46 495 查看
1、简单一点的方法,先用一张大背景图放在WINDOW上,再用DW正好遮挡住的那部分图当作DATAWINDOW的背景图,且将该图置在DW的最底层,同时设各列的背景色为透明即可;
该方法优点是比较简单,缺点是只适用于DW,其他控件不适用,如:LABEL、TEXT、COMMANDBUTTON等;
2、麻烦一点的方法,用API的BITBLT,缺点是比较麻烦,优点是适用于绝大部分控件,效果图见:
http://blog.csdn.net/balloonman2002/gallery/image/63164.aspx
本方法调整后可以轻松适用其他控件,如按钮,如图:
http://blog.csdn.net/balloonman2002/gallery/image/63218.aspx
本文重在举例演示,里面有诸多具体细节未尽考虑,如需改进请自行实施,相关原理参考:
http://blog.csdn.net/balloonman2002/archive/2004/06/28/28706.aspx
**************************************************************
方法二具体代码如下:
$PBExportHeader$w_trans.srw
forward
global type w_trans from Window
end type
type p_2 from picture within w_trans
end type
type st_2 from statictext within w_trans
end type
type st_1 from statictext within w_trans
end type
type dw_2 from datawindow within w_trans
end type
type dw_1 from datawindow within w_trans
end type
type p_1 from picture within w_trans
end type
end forward
global type w_trans from Window
int X=1056
int Y=480
int Width=2574
int Height=1700
boolean TitleBar=true
string Title="透明DW测试"
long BackColor=15780518
boolean ControlMenu=true
boolean MinBox=true
boolean MaxBox=true
boolean Resizable=true
event ue_paint pbm_paint
event ue_1024 pbm_custom01
p_2 p_2
st_2 st_2
st_1 st_1
dw_2 dw_2
dw_1 dw_1
p_1 p_1
end type
global w_trans w_trans
type prototypes
function long BitBlt ( long hdcdest, long xdest, long ydest, long nwidth,long nheight,long hdcsrc, long xsrc, long ysrc, long dwrop ) library "gdi32"
function long CreateBitmap ( long nwidth, long nheight, long nplanes, long nbitcount, long lpbits ) library "gdi32"
function long SetBkColor ( long hdc, long crcolor ) library "gdi32"
function long SelectObject ( long hdc, long hobject ) library "gdi32"
function long CreateCompatibleBitmap ( long hdc, long nwidth, long nheight ) library "gdi32"
function long CreateCompatibleDC ( long hdc ) library "gdi32"
function long DeleteDC ( long hdc ) library "gdi32"
function long DeleteObject ( long hobject ) library "gdi32"
function long GetDC ( long hwnd ) library "user32"
function Integer ReleaseDC ( long hwnd, long hdc ) library "user32"
end prototypes
type variables
Long il_SrcDC, il_DstDC,il_MapDstDC_Old,il_MapDstHandle, il_OldMapDstHandle,il_SrcWidth,il_SrcHeight,il_color
constant long SRCCOPY = 13369376
constant long NOTSRCCOPY = 3342344
constant long SRCAND = 8913094
constant long SRCINVERT = 6684742
dragobject io_obj
long il_count
OLEObject demo
end variables
forward prototypes
public subroutine wf_maketrans ()
public subroutine wf_makedc ()
public subroutine wf_maketrans ()
public subroutine wf_makedc ()
end prototypes
event ue_paint;//post wf_formbak()
end event
event ue_1024;messagebox("demo","demo")
end event
public subroutine wf_maketrans ();long ll_oldBackGround
Long ll_MapSrcDc,ll_MapDstDC
Long ll_MapSrcHandle, ll_OldMapSrcHandle,ll_MapDstHandle,ll_OldMapDstHandle
Long ll_maskDC, ll_InvertDC, ll_maskHandle, ll_InvertHandle, ll_oldMaskHandle, ll_OldInvertHandle
ll_maskDc = CreateCompatibleDC(il_SrcDC)
ll_maskHandle = CreateBitmap(il_SrcWidth, il_SrcHeight, 1, 1, 0)
ll_OldMaskHandle = SelectObject(ll_MaskDC, ll_MaskHandle)
ll_InvertDC = CreateCompatibleDC(ll_maskDc)
ll_InvertHandle = CreateBitmap(il_SrcWidth, il_SrcHeight, 1, 1, 0)
ll_OldInvertHandle = SelectObject(ll_InvertDC, ll_InvertHandle)
ll_oldBackGround = SetBkColor(il_SrcDC, il_color)
BitBlt(ll_maskDc, 0, 0, il_SrcWidth, il_SrcHeight, il_SrcDC, 0, 0, SRCCOPY)
SetBkColor(il_SrcDC, ll_oldBackGround)
BitBlt( ll_invertDC, 0, 0,il_SrcWidth, il_SrcHeight, ll_maskDC, 0, 0, NOTSRCCOPY)
 
ll_MapDstDC = CreateCompatibleDC(il_mapdstdc_old)
ll_MapDstHandle = CreateCompatibleBitmap(il_mapdstdc_old, il_SrcWidth, il_SrcHeight)
ll_OldMapDstHandle = SelectObject(ll_MapDstDC, ll_MapDstHandle)
ll_MapSrcDC = CreateCompatibleDC(il_SrcDC)
ll_MapSrcHandle = CreateCompatibleBitmap(il_SrcDC, il_SrcWidth, il_SrcHeight)
ll_OldMapSrcHandle = SelectObject(ll_MapSrcDC, ll_MapSrcHandle)
BitBlt(ll_MapSrcDC, 0, 0, il_SrcWidth, il_SrcHeight, il_SrcDC, 0, 0, SRCCOPY)
BitBlt(ll_MapSrcDc, 0, 0, il_SrcWidth, il_SrcHeight, ll_InvertDC, 0, 0, SRCAND)
BitBlt(ll_MapDstDC, 0, 0, il_SrcWidth, il_SrcHeight, il_MapDstDC_Old, 0,0, SRCCOPY)
BitBlt(ll_MapDstDC, 0, 0, il_SrcWidth, il_SrcHeight, ll_MaskDC, 0, 0 ,SRCAND)
BitBlt(ll_MapDstDC, 0, 0, il_SrcWidth, il_SrcHeight, ll_MapSrcDC, 0 ,0 , SRCINVERT)
BitBlt(il_SrcDC,0,0,il_SrcWidth,il_SrcHeight,ll_MapDstDC,0,0, SRCCOPY)
ll_MaskHandle = SelectObject(ll_MaskDC, ll_OldMaskHandle)
DeleteObject(ll_MaskHandle)
DeleteDC(ll_MaskDC)
ll_Inverthandle = SelectObject(ll_InvertDC, ll_OldInvertHandle)
DeleteObject(ll_InvertHandle)
DeleteDC(ll_InvertDC)
ll_MapSrcHandle = SelectObject(ll_MapSrcDC, ll_OldMapSrcHandle)
DeleteObject(ll_MapSrchandle)
DeleteDC(ll_MapSrcDC)
ll_MapDstHandle = SelectObject(ll_MapDstDC, ll_OldMapDstHandle)
DeleteObject(ll_MapDsthandle)
DeleteDC(ll_MapDstDC)
end subroutine
public subroutine wf_makedc ();Integer DRAWX, DRAWY
il_SrcWidth = UnitsToPixels(io_obj.Width, XUnitsToPixels!)
il_SrcHeight = UnitsToPixels(io_obj.Height, YUnitsToPixels!)
DRAWX = UnitsToPixels(io_obj.X, XUnitsToPixels!)
DRAWY = UnitsToPixels(io_obj.Y, YUnitsToPixels!)
il_MapDstDC_Old = CreateCompatibleDC(il_DstDC)
il_MapDstHandle = CreateCompatibleBitmap(il_DstDC, il_SrcWidth, il_SrcHeight)
il_OldMapDstHandle = SelectObject(il_MapDstDC_Old, il_MapDstHandle)
io_obj.Hide()
p_1.setredraw(true)
BitBlt(il_MapDstDC_Old, 0, 0, il_SrcWidth, il_SrcHeight, il_DstDC, DRAWX, DRAWY, SRCCOPY)
io_obj.show()
end subroutine
on w_trans.create
this.p_2=create p_2
this.st_2=create st_2
this.st_1=create st_1
this.dw_2=create dw_2
this.dw_1=create dw_1
this.p_1=create p_1
this.Control[]={this.p_2,&
this.st_2,&
this.st_1,&
this.dw_2,&
this.dw_1,&
this.p_1}
end on
on w_trans.destroy
destroy(this.p_2)
destroy(this.st_2)
destroy(this.st_1)
destroy(this.dw_2)
destroy(this.dw_1)
destroy(this.p_1)
end on
event open;io_obj = dw_1
il_color = rgb(255,255,255)
il_DstDC = GetDC(Handle(io_obj.Getparent()))
il_SrcDC = GetDC(Handle(io_obj))
dw_1.insertrow(0)
dw_2.insertrow(0)
post wf_makedc()
end event
event close;ReleaseDC(handle(this),il_DstDC)
ReleaseDC(handle(this),il_SrcDC)
il_MapDstHandle = SelectObject(il_MapDstDC_Old, il_OldMapDstHandle)
DeleteObject(il_MapDstHandle)
DeleteDC(il_MapDstDC_Old)
end event
type p_2 from picture within w_trans
int X=1490
int Y=252
int Width=677
int Height=1216
string PictureName="c:/qq2000/newskins/雅典奥运/background.bmp"
boolean FocusRectangle=false
end type
type st_2 from statictext within w_trans
int X=1326
int Y=80
int Width=928
int Height=96
boolean Enabled=false
string Text="普通DW演示:"
boolean FocusRectangle=false
long TextColor=33554432
long BackColor=15780518
int TextSize=-12
int Weight=400
string FaceName="Arial"
FontCharSet FontCharSet=Ansi!
FontFamily FontFamily=Swiss!
FontPitch FontPitch=Variable!
end type
type st_1 from statictext within w_trans
int X=123
int Y=88
int Width=928
int Height=96
boolean Enabled=false
string Text="透明DW演示:"
boolean FocusRectangle=false
long TextColor=33554432
long BackColor=15780518
int TextSize=-12
int Weight=400
string FaceName="Arial"
FontCharSet FontCharSet=Ansi!
FontFamily FontFamily=Swiss!
FontPitch FontPitch=Variable!
end type
type dw_2 from datawindow within w_trans
int X=1358
int Y=336
int Width=992
int Height=1036
int TabOrder=20
boolean BringToTop=true
string DataObject="demo"
boolean Border=false
boolean HScrollBar=true
boolean VScrollBar=true
boolean LiveScroll=true
end type
type dw_1 from datawindow within w_trans
event lbuttondown pbm_lbuttondown
event lbuttonup pbm_lbuttonup
event ue_paint pbm_paint
int X=110
int Y=336
int Width=992
int Height=1036
int TabOrder=10
boolean BringToTop=true
string DataObject="demo"
boolean Border=false
boolean HScrollBar=true
boolean VScrollBar=true
boolean LiveScroll=true
end type
event ue_paint;post wf_maketrans()
end event
event rowfocuschanging;//this.visible = false
//this.visible = true
wf_maketrans()
//this.setfocus()
end event
event scrollvertical;wf_maketrans()
end event
type p_1 from picture within w_trans
int X=233
int Y=252
int Width=677
int Height=1216
string PictureName="c:/qq2000/newskins/雅典奥运/background.bmp"
boolean FocusRectangle=false
end type
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息