问三个问题?

Puto 2003-08-23 09:52:16
第一个,PB制作异形窗口该怎么办? VC的实例我有,可惜,我的C++学的不太好,也没看懂,大概就是图片的黑色部分(边缘吧)与对话框相重叠的地方用windowRGN()变成透明,我也没搞懂怎么弄的,请教高手如何在PB里实现。

第二个问题,如何屏蔽双击标题栏就最大化的事件?

第三个问题,如何使一个main类型的窗口本身的垂直滚动条支持鼠标滚轮?
...全文
56 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
runsoft 2003-08-26
  • 打赏
  • 举报
回复
UP
欣萱好米 2003-08-26
  • 打赏
  • 举报
回复
我不會﹗關注研究﹗
xuxutj 2003-08-26
  • 打赏
  • 举报
回复
Function ulong CreatePolygonRgn (ref tagPOINT lppt[], int cPoints, int fnPolyFillMode ) Library "gdi32.dll"
这样声明在pb里过不去呀
jdsnhan 2003-08-26
  • 打赏
  • 举报
回复
2,那窗口的最大话还要吗
xuxutj 2003-08-26
  • 打赏
  • 举报
回复
第二个问题,可以将窗口属性中的maximize box去掉
其他那两个,关注一下
pbsql 2003-08-26
  • 打赏
  • 举报
回复
问题一:(一个比较简单的)

首先在窗口定义下列局部外部函数(Local External Functions...):
Function ulong CreatePolygonRgn (ref tagPOINT lppt[], int cPoints, int fnPolyFillMode ) Library "gdi32.dll"
FUNCTION ulong SetWindowRgn(ulong hWnd,ulong hRgn,boolean bRedraw) LIBRARY "user32.dll"

在窗口上定义:
Structure
tagpoint
{ long x
long y}

在窗口的open事件中加上:
long hrgn
long lres
tagPOINT l_pointapi[]

l_pointapi[1].x = 173
l_pointapi[1].y = 112

l_pointapi[2].x = 412
l_pointapi[2].y = 66

l_pointapi[3].x = 478
l_pointapi[3].y = 240

l_pointapi[4].x = 338
l_pointapi[4].y = 340 //多边形各个顶点坐标值

hrgn = CreatePolygonRgn(l_pointapi[],4,1)
//其中第 1 个参数为多边形各个顶点坐标值的数组
//其中第 2 个参数为多边形边数,可修改,配合数组值
//其中第 3 个参数为填充模式 ALTERNATE /WINDING
lres=setwindowRgn(handle(this),hrgn,true)

jdsnhan 2003-08-26
  • 打赏
  • 举报
回复
第一个问题,前人种树,后人乘凉:
发现PB甚至于其它编程工具都没有提供这样的控件,
不知各位可有创建任意形状的可视控件的办法,比如一个圆形的,多边形的等
这个控件必须像窗口一样有自己的属性、方法,事件就无所谓,但属性就一定要有。
---------------------------------------------------------------

我以前有过不规则按纽的例子,很好玩,你在到网上去找找吧。
---------------------------------------------------------------

pb里的图形框就是有不规则形状啊,只是没事件,因为他们的祖先就不是一个类继承过来的。感兴趣可以自己去做一个控件,用BCB应该很容易
---------------------------------------------------------------

在PB下实现圆形的窗口:

首先在窗口定义下列局部外部函数(Local External Functions...):

FUNCTION ulong CreateEllipticRgn(ulong X1,ulong Y1,ulong X2,ulong Y2) LIBRARY
"gdi32.dll"
FUNCTION ulong SetWindowRgn(ulong hWnd,ulong hRgn,boolean bRedraw) LIBRARY
"user32.dll"

在窗口的open事件中加上:

long hrgn
long lres

hrgn=createellipticrgn(20,20,400,400)//其中参数为左上到右下的坐标值,可修改。
lres=setwindowRgn(handle(this),hrgn,true)
//记得在窗口中放置一个按钮关闭窗口,要不然……
---------------------------------------------------------------

我有源代码

long ll_handle
ws_position lws_pointapi[]
// 图形2

lws_pointapi[1].xpos = 1
lws_pointapi[1].ypos = 1

lws_pointapi[2].xpos = 800
lws_pointapi[2].ypos = 1

lws_pointapi[3].xpos = 800
lws_pointapi[3].ypos = 41

lws_pointapi[4].xpos = 1
lws_pointapi[4].ypos = 41

lws_pointapi[5].xpos = 1
lws_pointapi[5].ypos = 610

lws_pointapi[6].xpos = 830
lws_pointapi[6].ypos = 610

lws_pointapi[7].xpos = 830
lws_pointapi[7].ypos = 75

lws_pointapi[8].xpos = 35
lws_pointapi[8].ypos = 75

lws_pointapi[9].xpos = 35
lws_pointapi[9].ypos = 586

lws_pointapi[10].xpos = 1
lws_pointapi[10].ypos = 586 //多边形各个顶点坐标值

ll_handle = CreatePolygonRgn(lws_pointapi[], 10, 1)
//其中第 1 个参数为多边形各个顶点坐标值的数组
//其中第 2 个参数为多边形边数,可修改,配合数组值
//其中第 3 个参数为填充模式 ALTERNATE /WINDING
SetwindowRgn(handle(this), ll_handle, true)

放在你的控件中,你的控件就变成了多边形

函数声明为
Function ulong CreatePolygonRgn (ref ws_position lppt[], int cPoints, int fnPolyFillMode ) Library "gdi32.dll"

FUNCTION ulong SetWindowRgn(ulong hWnd,ulong hRgn,boolean bRedraw) LIBRARY "user32.dll"

代码能不能看懂,看不懂给我发短消息

---------------------------------------------------------------

楼上的说的都很不错啊,把这几个API函数配合起来使用,就可以做任意形状的窗口了。
CombineRgn
CreateEllipticRgn
CreateEllipticRgnIndirect
CreatePolygonRgn
CreatePolyPolygonRgn
CreateRectRgn
CreateRectRgnIndirect
CreateRoundRectRgn
SetWindowRgn

---------------------------------------------------------------

楼上:
有没有办法修改按钮(CommandButton)的背景色啊?
我不想使用DW、BMP等变通的办法
就想如何才能直接修改按钮的背景色

不知道是不是要用到OWNER_DRAW

---------------------------------------------------------------

楼上:
没问题呀,有handle的控件,都可以的。
---------------------------------------------------------------

使用OWNERDRAW(这里针对按钮,其他类似)
1。设置控件的ownerdraw属性
ll = GetWindowULong( handle( cb_1 ), GWL_STYLE )
SetWindowULong( handle( this ), GWL_STYLE, ll + BS_OWNERDRAW )
2。在窗口的 pbm_measureitem 中
设置按钮的宽和高
3。在窗口的 pbm_drawitem 事件中
绘制按钮, 这是一段代码:
DRAWITEMSTRUCT ldis

MoveMemory( ldis, drawitemstruct, DRAWITEMSTRUCT_SIZE )
if ldis.ctltype <> ODT_BUTTON then return 0
if ldis.ctlid <> g_api.GetWindowULong( handle( this ), g_api.GWL_ID ) then return 0
ib_selected = mod( ldis.itemstate, ODS_SELECTED * 2 ) >= ODS_SELECTED
ib_focus = mod( ldis.itemstate, ODS_FOCUS * 2 ) >= ODS_FOCUS
of_draw( ldis.hdc )
里面 drawitemstruct 是个指向 DRAWITEMSTRUCT结构的指针。
4。ok了。
aty283 2003-08-26
  • 打赏
  • 举报
回复
up
eltoro 2003-08-24
  • 打赏
  • 举报
回复
关注。特别是第一,能讲详细点吗?PB可以用类似的方法来做出圆角的窗口吗?
dotnba 2003-08-24
  • 打赏
  • 举报
回复
我不会:(
polugen 2003-08-24
  • 打赏
  • 举报
回复
1。你可以找一个VB的代码,一样 的
2。在RESIZE里面,你可以判断窗口状态参数resizetype
3.你想干什么
Puto 2003-08-24
  • 打赏
  • 举报
回复
以上是一本书上的实例,有几个问题:

声明外部函数时第一行GetPixel(ulong hdc,ulong x,ulong y)在PB9.0里会有警告信息,说x,y与已有的冲突什么的

p_1的事件列表里没有lbuttondown事件,我自定义了一个,可以使用

然后关键问题就是点击show按钮后程序反应迟钝,要大约一分钟后才可以显示出处理后的不规则窗口

请高手帮忙分析一下.
Puto 2003-08-24
  • 打赏
  • 举报
回复
声明外部函数:
PUBLIC FUNCTION ulong GetPixel(ulong hdc,ulong x,ulong y) LIBRARY "gdi32.dll"
PUBLIC FUNCTION ulong SetWindowRgn(ulong hWnd,ulong hRgn,boolean bRedraw) LIBRARY "user32.dll"
PUBLIC FUNCTION ulong CreateRectRgn(ulong X1,ulong Y1,ulong X2,ulong Y2) LIBRARY "gdi32.dll"
PUBLIC FUNCTION ulong CombineRgn(ulong hDestRgn,ulong hSrcRgn1,ulong hSrcRgn2,ulong nCombineMode) LIBRARY "gdi32.dll"
PUBLIC FUNCTION ulong SendMessage(ulong hwnd,ulong wMsg,ulong wParam,ulong lParam) LIBRARY "user32.dll" ALIAS FOR "SendMessageA"
PUBLIC FUNCTION ulong ReleaseCapture() LIBRARY "user32.dll"
PUBLIC FUNCTION ulong DeleteObject(ulong hObject) LIBRARY "gdi32.dll"
PUBLIC FUNCTION ulong GetDC(ulong hwnd) LIBRARY "user32.dll"

函数说明:
GetPixel(ulong hdc,ulong a,ulong b)用来获得像素
SetWindowRgn(ulong hWnd,ulong hRgn,boolean bRedraw)用来重画窗口
CreateRectRgn(ulong X1,ulong Y1,ulong X2,ulong Y2)创建一个矩形区域成功后返回句柄,结合SetWindowRgn来进行窗口重画
CombineRgn(ulong hDestRgn,ulong hSrcRgn1,ulong hSrcRgn2,ulong nCombineMode)用于进行区域图形重组
SendMessage(ulong hwnd,ulong wMsg,ulong wParam,ulong lParam)用于向Windows发消息
DeleteObject(ulong hObject)用于释放对象占用的内存空间
GetDC(ulong hwnd)用于获得设备列表



定义一个W_1窗口,其上有一个图片控件p_1和一个按钮cb_1

w_1为popup类型,无标题,无maxBox和MinBox,无Border

cb_1的text写为show


在cb_1的clicked事件添加以下脚本:

if this.text = "Close" Then halt

uLong Xxx,Yyy,StartLineX
ulong FullRegion,LineRegion
uLong TransparentColor
Boolean InFirstRegion
Boolean InLine
uLong hDC,pix,ty
uLong PicWidth
uLong PicHeight



hDC = GetDC(handle(p_1))
PicWidth = UnitsToPixels(p_1.Width, XUnitsToPixels!)
PicHeight = UnitsToPixels(p_1.Height, YUnitsToPixels!)

InFirstRegion = True
InLine = False
Xxx = 0
Yyy = 0
StartLineX = 0


TransparentColor = GetPixel(hDC, 0, 0)

For Yyy = 0 To PicHeight
For Xxx = 0 To PicWidth

If GetPixel(hDC, Xxx, Yyy) = TransparentColor Or Xxx = PicWidth Then

If InLine Then
InLine = False
LineRegion = CreateRectRgn(StartLineX, Yyy, Xxx+1, Yyy + 1)

If InFirstRegion Then
FullRegion = LineRegion
InFirstRegion = False
Else
CombineRgn(FullRegion, FullRegion, LineRegion, 2)

DeleteObject(LineRegion)
End If
End If
Else

If Not InLine Then
InLine = True
StartLineX = Xxx
End If
End If
Next
Next


SetWindowRgn(handle(w_1), FullRegion, True)

this.text = "Close"


在P_1的lbuttondown事件添加以下脚本(便于无标题窗口可以移动)

//ReleaseCapture()

ulong handle

handle = handle(w_1)

SendMessage(handle,161 , 2, 0)

680

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder API 调用
社区管理员
  • API 调用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧