热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

如何在PB中实现透明DATAWINDOW?

1、简单一点的方法,先用一张大背景图放在WINDOW上,再用DW正好遮挡住的那部分图当作DATAWINDOW的背景图,且将该图置在DW的最底层,同时设各列的背景色为透明即可;该方法优点是比较简单

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 透明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 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 普通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 透明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 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 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 c:/qq2000/newskins/雅典奥运/background.bmp"
boolean FocusRectangle=false
end type


推荐阅读
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 先看官方文档TheJavaTutorialshavebeenwrittenforJDK8.Examplesandpracticesdescribedinthispagedontta ... [详细]
  • Java太阳系小游戏分析和源码详解
    本文介绍了一个基于Java的太阳系小游戏的分析和源码详解。通过对面向对象的知识的学习和实践,作者实现了太阳系各行星绕太阳转的效果。文章详细介绍了游戏的设计思路和源码结构,包括工具类、常量、图片加载、面板等。通过这个小游戏的制作,读者可以巩固和应用所学的知识,如类的继承、方法的重载与重写、多态和封装等。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 本文分享了一个关于在C#中使用异步代码的问题,作者在控制台中运行时代码正常工作,但在Windows窗体中却无法正常工作。作者尝试搜索局域网上的主机,但在窗体中计数器没有减少。文章提供了相关的代码和解决思路。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • JavaSE笔试题-接口、抽象类、多态等问题解答
    本文解答了JavaSE笔试题中关于接口、抽象类、多态等问题。包括Math类的取整数方法、接口是否可继承、抽象类是否可实现接口、抽象类是否可继承具体类、抽象类中是否可以有静态main方法等问题。同时介绍了面向对象的特征,以及Java中实现多态的机制。 ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • 个人学习使用:谨慎参考1Client类importcom.thoughtworks.gauge.Step;importcom.thoughtworks.gauge.T ... [详细]
  • springmvc学习笔记(十):控制器业务方法中通过注解实现封装Javabean接收表单提交的数据
    本文介绍了在springmvc学习笔记系列的第十篇中,控制器的业务方法中如何通过注解实现封装Javabean来接收表单提交的数据。同时还讨论了当有多个注册表单且字段完全相同时,如何将其交给同一个控制器处理。 ... [详细]
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
  • 本文介绍了在wepy中运用小顺序页面受权的计划,包含了用户点击作废后的从新受权计划。 ... [详细]
author-avatar
上海蓝色的梦在哪
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有