在网上搜到CreatePolygonRgn可以创建热点,但是好像只能创建一个,如何才能创建多个热点呢?
请各位大侠给小弟一个思路~

解决方案 »

  1.   


    'Example Name:Polygons
    Private Type COORD
        x As Long
        y As Long
    End Type
    Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long
    Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As Any, ByVal nCount As Long) As Long
    Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long
    Private Declare Function GetStockObject Lib "gdi32" (ByVal nIndex As Long) As Long
    Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    Const ALTERNATE = 1 ' ALTERNATE and WINDING are
    Const WINDING = 2 ' constants for FillMode.
    Const BLACKBRUSH = 4 ' Constant for brush type.
    Private Sub Form_Paint()
        'KPD-Team 1999
        'URL: http://www.allapi.net/
        'E-Mail: [email protected]
        Dim poly(1 To 3) As COORD, NumCoords As Long, hBrush As Long, hRgn As Long
        Me.Cls
        ' Number of vertices in polygon.
        NumCoords = 3
        ' Set scalemode to pixels to set up points of triangle.
        Me.ScaleMode = vbPixels
        ' Assign values to points.
        poly(1).x = Form1.ScaleWidth / 2
        poly(1).y = Form1.ScaleHeight / 2
        poly(2).x = Form1.ScaleWidth / 4
        poly(2).y = 3 * Form1.ScaleHeight / 4
        poly(3).x = 3 * Form1.ScaleWidth / 4
        poly(3).y = 3 * Form1.ScaleHeight / 4
        ' Polygon function creates unfilled polygon on screen.
        ' Re FillRgn statement to see results.
        Polygon Me.hdc, poly(1), NumCoords
        ' Gets stock black brush.
        hBrush = GetStockObject(BLACKBRUSH)
        ' Creates region to fill with color.
        hRgn = CreatePolygonRgn(poly(1), NumCoords, ALTERNATE)
        ' If the creation of the region was successful then color.
        If hRgn Then FillRgn Me.hdc, hRgn, hBrush
        DeleteObject hRgn
    End Sub
    Private Sub Form_Resize()
        Form_Paint
    End Sub
      

  2.   

    使用CreatePolygonRgn创建多个Region,交Region的句柄保存到数组中,然后在鼠标移动时使用PtInRegion遍历hRgn数组即可。
      

  3.   

    小弟想实现一个功能,不知道思路是否正确,待各位大侠指正~
    功能要求:
    1、通过图片显示船从一个港口到另一个港口的在途情况;
    2、图片上显示港口、航线、和船(船当然不止一艘);
    3、港口是通过坐标定位显示的,船是在航线上行驶的;
    4、鼠标点击港口和船会显示相应信息;
    5、说的简单点,就有点像游戏大航海时代中那些地图信息有些类似。目前我是通过BitBlt和GdiTransparentBlt将港口透明图片绘画到地图上,按我的理解需要创建热点才能激发鼠标点击港口的事件。小弟今年初学VB,专业术语和口述能力都不强,期待各位大侠指正~
      

  4.   


    目前所需功能已经实现!
    谢谢各位!
    回2L,我需要的是多个热点区域,DeleteObject应该不需要用
    结合你的,还有函数PtInRegion就能实现多个热点区域并激活
    想必目前性能不行,但所幸功能已经满足
    慢慢来吧
    再次感谢各位!