当前位置: 首页 > news >正文

2016做网站百度应用市场app下载

2016做网站,百度应用市场app下载,横琴人寿保险公司官网,网站跳转怎么做GDI32中用PtInRegion检测坐标是否在图形区域内: 如果画了一个矩形,外边框线条粗细是10像素,检测区域时只能在第6像素开始才能反应,鼠标移动到边框线的1-5像素时,检测鼠标未在矩形区域 您遇到的问题是由于 GDI 中区域 (Region) 的定义与边框 (Stroke) 的渲染方式不同…

GDI32中用PtInRegion检测坐标是否在图形区域内: 如果画了一个矩形,外边框线条粗细是10像素,检测区域时只能在第6像素开始才能反应,鼠标移动到边框线的1-5像素时,检测鼠标未在矩形区域

您遇到的问题是由于 GDI 中区域 (Region) 的定义与边框 (Stroke) 的渲染方式不同导致的。这是 GDI 绘图系统的一个常见特性,需要特别处理。

问题原因分析

  1. 区域 (Region) vs 边框 (Stroke)

    • CreateRectRgn 创建的区域是填充区域,不包含边框
    • 边框是绘制在区域边缘外部的,默认情况下不被视为区域的一部分
  2. 边框宽度的影响

    • 当您设置边框宽度为 10 像素时,这 10 像素是从区域边缘向外扩展的
    • 区域本身的边界并没有改变,因此PtInRegion只检测填充区域
  3. 坐标系统差异

    • 区域使用整数坐标,而边框渲染可能使用亚像素精度
    • 这种差异可能导致视觉上的边框与实际区域边界不一致

解决方案

方法一:创建包含边框的扩展区域vb
' API声明
Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function PtInRegion Lib "gdi32" (ByVal hRgn As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As LongPrivate Const RGN_OR = 2  ' 区域合并操作Private Sub CreateExtendedRegion(ByVal left As Long, ByVal top As Long, ByVal right As Long, ByVal bottom As Long, ByVal borderWidth As Long, ByRef hRegion As Long)Dim hFillRgn As LongDim hBorderRgn As Long' 创建填充区域hFillRgn = CreateRectRgn(left, top, right, bottom)' 创建扩展区域(包含边框)hBorderRgn = CreateRectRgn(left - borderWidth, top - borderWidth, _right + borderWidth, bottom + borderWidth)' 合并两个区域hRegion = CreateRectRgn(0, 0, 1, 1)  ' 创建临时区域CombineRgn hRegion, hFillRgn, hBorderRgn, RGN_OR' 释放临时区域DeleteObject hFillRgnDeleteObject hBorderRgn
End Sub' 使用示例
Private Sub Form_Load()Dim hRegion As LongDim borderWidth As LongborderWidth = 10' 创建包含10像素边框的区域CreateExtendedRegion 100, 100, 300, 200, borderWidth, hRegion' 现在可以使用这个区域进行鼠标检测' PtInRegion(hRegion, x, y) 将包含边框区域
End Sub
方法二:分别检测填充区域和边框区域vb
Private Sub MouseInBorderOrFill(ByVal x As Long, ByVal y As Long, ByVal left As Long, ByVal top As Long, ByVal right As Long, ByVal bottom As Long, ByVal borderWidth As Long, ByRef inBorder As Boolean, ByRef inFill As Boolean)' 检测是否在填充区域内inFill = (x >= left And x <= right And y >= top And y <= bottom)' 检测是否在边框区域内If Not inFill TheninBorder = (x >= left - borderWidth And x <= right + borderWidth And _y >= top - borderWidth And y <= bottom + borderWidth) And _Not inFillElseinBorder = FalseEnd If
End Sub' 使用示例
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)Dim pixelX As Long, pixelY As LongDim inBorder As Boolean, inFill As BooleanpixelX = X / Screen.TwipsPerPixelXpixelY = Y / Screen.TwipsPerPixelY' 检测鼠标是否在矩形(100,100,300,200)的填充区域或边框(宽度10)内MouseInBorderOrFill pixelX, pixelY, 100, 100, 300, 200, 10, inBorder, inFillIf inFill ThenMe.Caption = "鼠标在填充区域内"ElseIf inBorder ThenMe.Caption = "鼠标在边框区域内"ElseMe.Caption = "鼠标在区域外"End If
End Sub

方法三:使用 GDI + 进行精确检测

GDI + 提供了更精确的区域检测功能,可以直接包含边框:

' GDI+ API声明
Private Declare Function GdipCreateFromHDC Lib "gdiplus" (ByVal hdc As Long, ByRef graphics As Long) As Long
Private Declare Function GdipDeleteGraphics Lib "gdiplus" (ByVal graphics As Long) As Long
Private Declare Function GdipCreatePen1 Lib "gdiplus" (ByVal color As Long, ByVal width As Single, ByVal unit As Long, ByRef pen As Long) As Long
Private Declare Function GdipCreatePath Lib "gdiplus" (ByVal fillMode As Long, ByRef path As Long) As Long
Private Declare Function GdipAddPathRectangle Lib "gdiplus" (ByVal path As Long, ByVal x As Single, ByVal y As Single, ByVal width As Single, ByVal height As Single) As Long
Private Declare Function GdipIsVisiblePathPoint Lib "gdiplus" (ByVal x As Single, ByVal y As Single, ByVal path As Long, ByVal pen As Long, ByVal graphics As Long) As Long
Private Declare Function GdipDisposePath Lib "gdiplus" (ByVal path As Long) As Long
Private Declare Function GdipDisposePen Lib "gdiplus" (ByVal pen As Long) As LongPrivate Const UnitPixel As Long = 2Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)Dim pixelX As Single, pixelY As SingleDim hGraphics As LongDim hPath As LongDim hPen As LongDim isVisible As LongpixelX = X / Screen.TwipsPerPixelXpixelY = Y / Screen.TwipsPerPixelY' 创建GDI+图形对象GdipCreateFromHDC Me.hdc, hGraphics' 创建路径和笔GdipCreatePath 0, hPath  ' 0 = FillModeAlternateGdipCreatePen1 &HFF0000, 10, UnitPixel, hPen  ' 10像素宽的笔' 添加矩形到路径GdipAddPathRectangle hPath, 100, 100, 200, 100' 检测点是否在路径(包括边框)上isVisible = GdipIsVisiblePathPoint(pixelX, pixelY, hPath, hPen, hGraphics)If isVisible <> 0 ThenMe.Caption = "鼠标在矩形(包括边框)内"ElseMe.Caption = "鼠标在矩形外"End If' 释放资源GdipDisposePath hPathGdipDisposePen hPenGdipDeleteGraphics hGraphics
End Sub

性能考虑

  1. 扩展区域方法:性能较高,但需要额外管理区域对象
  2. 分别检测方法:简单直接,适合小型应用
  3. GDI + 方法:最精确,但性能开销较大,适合对精度要求高的场景

根据您的具体需求选择合适的方法,可以有效解决边框检测问题。

http://www.mmbaike.com/news/27630.html

相关文章:

  • 搭建公司网站多少钱seo查询seo
  • 网站设计行业背景如何解决网站只收录首页的一些办法
  • 动态网站开发考试答案网站优化策略分析
  • 联合创始人网站怎么做游戏推广员是做什么的
  • 服务器上如何做网站免费crm客户管理系统
  • 如何做网站详细步骤图网络营销推广公司简介
  • 深圳建设网站个人如何注册一个域名
  • 深圳市做门窗网站有哪些推广公司产品推广方案
  • 2022腾讯云网站建设方案书搜索引擎优化技巧
  • thinkphp做的教育网站淄博百度推广
  • 做网站需学什么网站怎样被百度收录
  • 青岛手机建站价格百度网盘搜索入口
  • 基于iview的网站开发模板站长工具seo下载
  • 网站建设服务收费百度营销是什么
  • 党建设计素材网站谷歌浏览器下载安装2022最新版
  • 莱芜融媒体中心网站福州seo
  • 国内哪些公司做商城型网站靠谱吗百度推广的步骤
  • wordpress 主题 后门百度seo怎么关闭
  • 网站建设后备案多少钱东莞seo排名收费
  • 汽配网站源码推广品牌的方法
  • 书本翻页 网站模板网站建设公司排名
  • 建设一个网站多钱2021年十大热点事件
  • 网站建设套餐报价网店运营与推广
  • 北京网站建苏州旺道seo
  • 上海哪里可以做网站如何做网站设计
  • 58同城做网站的电话百度下载安装2022最新版
  • wordpress fla插件网站优化的主要内容
  • 东莞路桥公司是国企吗武汉seo公司
  • 网站建设的7种流程昆明seo关键字推广
  • 网络公司开发网站网站设计与建设的公司