绝对挑战,其实不是问题的问题,因为没什么实际意义!

hygougou 2004-12-26 02:22:50
捕捉键盘消息或鼠标消息
1,画直线,线条为红色---点一下左键开始拖动然后放开线就有了(和画线一样);
2。画圆,矩形。填充为蓝色
3,跟踪光标的位置

我的sendmessage参数手册资料不齐,能提供手册者(要比较完整),50分
...全文
292 24 打赏 收藏 转发到动态 举报
写回复
用AI写文章
24 条回复
切换为时间正序
请发表友善的回复…
发表回复
fibbery 2005-01-04
  • 打赏
  • 举报
回复
学习学习
hygougou 2005-01-04
  • 打赏
  • 举报
回复
揭贴,感谢各位的帮助与建议

答谢斑竹pt同志的资料,实现诺言给他多加50分
hygougou 2005-01-04
  • 打赏
  • 举报
回复
========================================================================
一、绘制自然线--类似画板中的画笔
========================================================================
//定义global external function
Function ulong GetDC(ulong hwnd) library "user32.dll"
FUNCTION boolean MoveToEx(ulong hwnd,long wx, long wy,ref str_pos prepos2) LIBRARY "Gdi32.dll"
FUNCTION boolean LineTo(ulong hwnd,long wx, long wy) LIBRARY "Gdi32.dll"
FUNCTION ulong SetCapture(ulong hwnd) LIBRARY "user32.dll"
FUNCTION ulong ReleaseCapture() LIBRARY "user32.dll"
FUNCTION boolean DeleteObject(ulong nObjectHandle ) LIBRARY "Gdi32.dll"

//创建结构str_pos
xpos long
ypos long


//新建一个窗体
//窗口中定义实例变量
//起始坐标
ulong il_xstart
ulong il_ystart
//鼠标按下标志
boolean ib_flags

//窗口的mousedown事件
ib_flags = True

SetCapture(handle(This))
//起始坐标
il_xstart = unitstopixels(pointerx(),XUnitsToPixels!)
il_ystart = unitstopixels(pointery(),yUnitsToPixels!)

//窗口的mousemove事件
ulong ul_device
uLong ul_xend
uLong ul_yend
ulong ul_handle
ulong newPen

//取得终止坐标
ul_xend = unitstopixels(pointerx(),XUnitsToPixels!)
ul_yend = unitstopixels(pointery(),YUnitsToPixels!)
//声明数组
str_pos strvar

If ul_xend < This.width And ul_yend < this.height Then
If ib_flags Then
//取得窗口句柄
ul_handle = handle(This)
//获得设备场景
ul_device = GetDC(ul_handle)

//用指定颜色创建一个新画笔
newPen = CreatePen(1,2, rgb(255,0,0))
//为设备场景中描绘的线段指定颜色及样式
SelectObject(ul_device, newPen)
//定位起始坐标
MoveToEx(ul_device, il_xstart, il_ystart, strvar)
//从起始坐标点定位到终止坐标画线
LineTo (ul_device, ul_xend, ul_yend)
//删除画笔
DeleteObject(newPen)
//为下次画线设置起始坐标为当前线的终止坐标
il_xstart = ul_xend
il_ystart = ul_yend
End If
End If

//窗口mouseup事件
ReleaseCapture()
ib_flags = False
//窗口colsequery事件
ulong ul_device
ulong ul_handle

ul_handle = handle(This)
ul_device = GetDC(ul_handle)
//删除场景
DeleteDc(ul_device)
//备注:如果把mousemove事件的代码放到mouseup事件中,则可以绘制一条直线
==================================================================================
二、绘制矩形
//定义global external function
Function ulong GetDC(ulong hwnd) library "user32.dll"
FUNCTION ulong SetCapture(ulong hwnd) LIBRARY "user32.dll"
FUNCTION ulong ReleaseCapture() LIBRARY "user32.dll"
FUNCTION ulong CreatePen(int nPenStyle, int nPenWidth, ulong nColor) LIBRARY "Gdi32.dll"
FUNCTION ulong SelectObject(ulong hdc, ulong nNewObjectHandle) LIBRARY "Gdi32.dll"
FUNCTION boolean DeleteObject(ulong nObjectHandle ) LIBRARY "Gdi32.dll"
FUNCTION ulong Rectangle(ulong hdc,ulong X1,ulong Y1,ulong X2,ulong Y2) LIBRARY "gdi32.dll"
FUNCTION ulong CreateSolidBrush(ulong crColor) LIBRARY "gdi32.dll"
FUNCTION ulong FillRect(ulong hdc,ref str_RECT lpRect,ulong hBrush) LIBRARY "user32.dll"
//删除专用设备场景或信息场景,释放所有相关窗口资源
FUNCTION ulong DeleteDC(ulong hdc) LIBRARY "gdi32.dll"

//创建结构str_rect
left long
top long
right long
buttom long


//创建一窗体
//窗口的实例变量
ulong il_x1
ulong il_y1


boolean ib_flags
//窗口的mousedown事件
ib_flags = True

//设置光标
SetCapture(handle(This))

//记录鼠标起始位置,取得矩形的第一坐标
il_x1 = unitstopixels(pointerx(),XUnitsToPixels!)
il_y1 = unitstopixels(pointery(),yUnitsToPixels!)

//窗口的mousemove事件
ulong l_device
uLong ll_x2
uLong ll_y2
ulong l_handle
ulong hbrush

//取得矩形的第二坐标
ll_x2 = unitstopixels(pointerx(),XUnitsToPixels!)
ll_y2 = unitstopixels(pointery(),YUnitsToPixels!)


If ib_flags Then
//设置光标
SetPointer(Cross!)
l_handle = handle(This)
//指定窗口的设备场景句柄
l_device = GetDC(l_handle)
ulong newPen
//为画笔填充颜色
newPen = CreatePen(1,2, rgb(192,192,192))
newPen = SelectObject(l_device, newPen)
//建立一个虚拟矩形框
Rectangle(l_device,il_x1,il_y1,ll_x2,ll_y2)
//删除画笔
DeleteObject(newpen)
End If


//窗口的mouseup事件
ulong l_device
uLong ll_x2
uLong ll_y2
ulong l_handle
ulong hBrush
ulong newPen

ll_x2 = unitstopixels(pointerx(),XUnitsToPixels!)
ll_y2 = unitstopixels(pointery(),YUnitsToPixels!)


str_rect lstr_rect

lstr_rect.left = il_x1
lstr_rect.top = il_y1
lstr_rect.right = ll_x2
lstr_rect.buttom = ll_y2

If ll_x2 < This.width And ll_y2 < this.height Then
If ib_flags Then
l_handle = handle(This)
l_device = GetDC(l_handle)


//获得设置颜色的刷子句柄
hBrush = CreateSolidBrush(rgb(0,0,255))
//用指定刷子填充指定区域
FillRect(l_device,lstr_rect,hBrush)
//删除刷子句柄
DeleteObject(hBrush)
DeleteDC(l_device)
End If
End If

SetPointer(Arrow!)

ReleaseCapture()

ib_flags = False

//窗口的closequery事件

ulong l_device
ulong l_handle
ulong newpen


l_handle = handle(This)
l_device = GetDC(l_handle)
//删除场景
DeleteDC(l_device)


==================================================================================
三、绘制圆/椭圆
//定义global external function

Function ulong GetDC(ulong hwnd) library "user32.dll"
FUNCTION ulong SetCapture(ulong hwnd) LIBRARY "user32.dll"
FUNCTION ulong ReleaseCapture() LIBRARY "user32.dll"
function ulong CreatePen(int nPenStyle, int nPenWidth, ulong nColor) LIBRARY "Gdi32.dll"
function ulong SelectObject(ulong hdc, ulong nNewObjectHandle) LIBRARY "Gdi32.dll"
function boolean DeleteObject(ulong nObjectHandle ) LIBRARY "Gdi32.dll"
LIBRARY "gdi32.dll"
FUNCTION ulong CreateSolidBrush(ulong crColor) LIBRARY "gdi32.dll"
FUNCTION ulong CreateEllipticRgn(ulong X1,ulong Y1,ulong X2,ulong Y2) LIBRARY "gdi32.dll"
FUNCTION ulong FillRgn(ulong hdc,ulong hRgn,ulong hBrush) LIBRARY "gdi32.dll"
FUNCTION ulong Ellipse(ulong hdc,ulong X1,ulong Y1,ulong X2,ulong Y2) LIBRARY "gdi32.dll"

//创建一窗体
//创建窗口实例变量
ulong il_x1
ulong il_y1


boolean ib_flags


//窗口的mousedown事件
ib_flags = True

SetCapture(handle(This))

//取得椭圆第一坐标
il_x1 = unitstopixels(pointerx(),XUnitsToPixels!)
il_y1 = unitstopixels(pointery(),yUnitsToPixels!)

//窗口的mousemove事件
IF ib_flags Then
SetPointer(Cross!)
End If

//窗口的mouseup事件
ulong l_device
uLong ll_x2
uLong ll_y2
ulong l_handle
ulong hBrush
ulong ul_handle

//取得椭圆第二坐标
ll_x2 = unitstopixels(pointerx(),XUnitsToPixels!)
ll_y2 = unitstopixels(pointery(),YUnitsToPixels!)



If ll_x2 < This.width And ll_y2 < this.height Then
If ib_flags Then
l_handle = handle(This)
l_device = GetDC(l_handle)
ulong newPen
newPen = CreatePen(1,2,rgb(0,0,255))
newPen = SelectObject(l_device, newPen)
//获取设备场景区域
ul_handle = CreateEllipticRgn(il_x1,il_y1,ll_x2,ll_y2)
//绘画圆形框
Ellipse(l_device,il_x1,il_y1,ll_x2,ll_y2)
//为刷子设置颜色
hBrush = CreateSolidBrush(rgb(0,0,255))
//用指定的刷子填充区域
FillRgn(l_device,ul_handle,hBrush)
//删除刷子
DeleteObject(hBrush)
DeleteObject(ul_handle)
//删除画笔
DeleteObject(newPen)
End If
End If


SetPointer(Arrow!)
ReleaseCapture()

ib_flags = False
//窗口的closequery事件
ulong l_device
ulong l_handle
ulong newpen


l_handle = handle(This)
l_device = GetDC(l_handle)
//删除场景
DeleteDC(l_device)

zhangdatou 2004-12-29
  • 打赏
  • 举报
回复
再来看看
handi 2004-12-29
  • 打赏
  • 举报
回复
http://ourmis.com/down_view.asp?id=397


我还是每天都来看看的哈。
klbt 2004-12-29
  • 打赏
  • 举报
回复
我已经解决了,但画矩形没有办法消除我的虚拟框,
=============================================
我是这样解决的,在pbm_dwnlbuttondown中:
this.Modify("r_1.Width = 0")
this.Modify("r_1.Height = 0")
this.Modify("r_1.Visible = 0")
hygougou 2004-12-29
  • 打赏
  • 举报
回复
好,整理整理,明天揭贴,贴出代码
hygougou 2004-12-29
  • 打赏
  • 举报
回复
Function ulong GetDC(ulong hwnd) library "user32.dll"
FUNCTION boolean MoveToEx(ulong hwnd,long wx, long wy,ref str_pos prepos2) LIBRARY "Gdi32.dll"
FUNCTION boolean LineTo(ulong hwnd,long wx, long wy) LIBRARY "Gdi32.dll"
balloonman2002 2004-12-29
  • 打赏
  • 举报
回复
狗狗,请将本贴揭贴,以便能将其加入FAQ,造福大家,:)

顺便把:《[分享]结束进程---举IE为例》

http://community.csdn.net/Expert/topic/3648/3648913.xml?temp=.1086084

一并揭贴,加入FAQ,:)
hygougou 2004-12-29
  • 打赏
  • 举报
回复
我已经解决了,但画矩形没有办法消除我的虚拟框,
同意大家的想法,不过大家都想到数据窗口画的?我是直接在窗口调用API画线,各位感兴趣可以试试

FUNCTION ulong SetCapture(ulong hwnd) LIBRARY "user32.dll"
FUNCTION ulong GetCapture() LIBRARY "user32.dll"
FUNCTION ulong ReleaseCapture() LIBRARY "user32.dll"
FUNCTION ulong GetDCBrushColor( ulong hdc ) LIBRARY "Gdi32.dll" //返回当前刷子的颜色0x00bbggrr
FUNCTION ulong SetDCBrushColor( ulong hdc, ulong nColor) LIBRARY "Gdi32.dll"
FUNCTION int ReleaseDC(ulong hwnd, ulong hdc)LIBRARY "Gdi32.dll" //释放DC handle, 必须调用
function ulong CreatePen(int nPenStyle, int nPenWidth, ulong nColor) LIBRARY "Gdi32.dll"
function ulong SelectObject(ulong hdc, ulong nNewObjectHandle) LIBRARY "Gdi32.dll"
function boolean DeleteObject(ulong nObjectHandle ) LIBRARY "Gdi32.dll"
FUNCTION ulong CreateRectRgn(ulong X1,ulong Y1,ulong X2,ulong Y2) LIBRARY "gdi32.dll"
FUNCTION ulong Rectangle(ulong hdc,ulong X1,ulong Y1,ulong X2,ulong Y2) LIBRARY "gdi32.dll"
FUNCTION ulong CreateSolidBrush(ulong crColor) LIBRARY "gdi32.dll"
FUNCTION ulong FillRect(ulong hdc,ref str_RECT lpRect,ulong hBrush) LIBRARY "user32.dll"
FUNCTION ulong PaintRgn(ulong hdc,ulong hRgn) LIBRARY "gdi32.dll"
FUNCTION ulong CreateEllipticRgn(ulong X1,ulong Y1,ulong X2,ulong Y2) LIBRARY "gdi32.dll"

FUNCTION ulong FillRgn(ulong hdc,ulong hRgn,ulong hBrush) LIBRARY "gdi32.dll"
FUNCTION ulong Ellipse(ulong hdc,ulong X1,ulong Y1,ulong X2,ulong Y2) LIBRARY "gdi32.dll"
//删除专用设备场景或信息场景,释放所有相关窗口资源
FUNCTION ulong DeleteDC(ulong hdc) LIBRARY "gdi32.dll"
//校验窗口的全部或部分客户区。这样便可告之windows指定的区域不需要重画
FUNCTION ulong ValidateRect(ulong hwnd,ref str_RECT lpRect) LIBRARY "user32.dll"
//为指定的设备场景设置背景颜色。背景颜色用于填充阴影刷子、虚线画笔以及字符(如背景模式为OPAQUE)中的空隙。也在位图颜色转换期间使用
FUNCTION ulong SetBkColor(ulong hdc,ulong crColor) LIBRARY "gdi32.dll"
FUNCTION ulong SetBkMode(ulong hdc,ulong nBkMode) LIBRARY "gdi32.dll"
balloonman2002 2004-12-29
  • 打赏
  • 举报
回复
同意楼上各位,我作过画矩形的,以便在DW中画一个框选中多个对象,就象在WINDOWS中多选文件的方式类似,如果问题未解决可以再交流,:)
xys2003 2004-12-29
  • 打赏
  • 举报
回复
在mousedown,mousemocev,mouseups三个事件中实现上述三个要求,我基本已经全部实现
klbt 2004-12-29
  • 打赏
  • 举报
回复
pbm_mousemove可以不用,不过这样有些突兀,显示效果不好。
hygougou 2004-12-29
  • 打赏
  • 举报
回复
再放一天我就揭贴
hwh88888 2004-12-28
  • 打赏
  • 举报
回复
帮兄弟顶一下
bunnysky 2004-12-28
  • 打赏
  • 举报
回复
其实两个事件就可以了呀?白兔的pbm_mousemove是不是可以不用?看接拖放。
1、在pbm_dwnlbuttondown中记录下开始坐标
2、在pbm_dwnlbuttonup中记录结束坐标。
3、按照记录下的相关属性画图。
klbt 2004-12-27
  • 打赏
  • 举报
回复
刚刚作过类似的画矩形东东,思路如下:
1、在clicked事件,创建线段,记录起始点、终止点(重合);
2、在pbm_mousemove事件,动态修改终止点的坐标属性;
3、在pbm_dwnlbuttondown事件中,画出线段,并用实例变量停止mousemove。

圆、矩形原理相同。
hygougou 2004-12-27
  • 打赏
  • 举报
回复
跟踪光标是啥意思呀?
今天怎么犯糊涂?
hygougou 2004-12-26
  • 打赏
  • 举报
回复
谢谢斑竹,可发给我,hygougou@163.com
上述的几个问题都要求sendmessage函数实现哦,呵呵~
WorldMobile 2004-12-26
  • 打赏
  • 举报
回复
捕捉键盘消息或鼠标消息
1,画直线,线条为红色---点一下左键开始拖动然后放开线就有了(和画线一样);
2。画圆,矩形。填充为蓝色
3,跟踪光标的位置

我的sendmessage参数手册资料不齐,能提供手册者(要比较完整),50分

----------------------------------------------------------------------------
1.在mousemove事件里,不要画,用line控件,动态改变位置即可,改X1、Y1和X2、Y2
2.画圆也在mousemove事件里做,用oval控件,动态改变位置和大小即可实现
3.至于跟踪光标位置,你在mousemove里写也没什么问题,你可以需要用到两个API函数
SetCapture和ReleaseCapture

不知道你说的sendmessage里的参数,是不是指的消息,如果是消息的话,我这里有
如果是参数的话,我也有,呵呵,在QQ里发给你吧
加载更多回复(4)

1,075

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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