找回密码
 加入
搜索
查看: 9573|回复: 15

[GUI管理] (已解决,谢谢netegg)gdi使用中问题

  [复制链接]
发表于 2014-10-30 15:26:47 | 显示全部楼层 |阅读模式
本帖最后由 续缘8003 于 2014-11-3 19:23 编辑

摘自本论坛的代码绘制了曲线图,如下代码
现在的问题是如果中间的一段缺数了,如何画出曲线图形
即代码中曲线为1到200,其中50到80缺数(也可能是40到50),如何画出来图形


#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>

Opt('MustDeclareVars', 1)
Global $hGUI, $hWnd, $hGraphic,$WM_PAINT

GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")

_Main()

Func _Main()
        Local $hBrush, $hAsymPen, $hFormat, $hFamily, $hFont, $tLayout, $hPen
        Local $aPoint[10000][3], $aPoint2[10000][3], $j = 1

        ; 创建界面
        ;$hGUI = GUICreate("Parabola", 400, 300)
        ;$hWnd = WinGetHandle("Parabola")
                $hGUI = GUICreate("", 350, 350)
                ;GUICreate()
        $hWnd = WinGetHandle($hGUI)
        GUISetState()
        
        _GDIPlus_Startup()
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
                $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
        $hFormat = _GDIPlus_StringFormatCreate()
        $hFamily = _GDIPlus_FontFamilyCreate("Arial")
        $hFont = _GDIPlus_FontCreate($hFamily, 8, 2)
                _GDIPlus_GraphicsDrawLine($hGraphic, 60, 350, 200, 350, $hPen)
        $tLayout = _GDIPlus_RectFCreate(200, 150, 50, 20)
        _GDIPlus_GraphicsDrawStringEx($hGraphic, 'O(0,0)', $hFont, $tLayout, $hFormat, $hBrush)
        $tLayout = _GDIPlus_RectFCreate(20, 20, 200, 20)
        _GDIPlus_GraphicsDrawStringEx($hGraphic, '', $hFont, $tLayout, $hFormat, $hBrush)
        $tLayout = _GDIPlus_RectFCreate(100, 150, 50, 20)
        _GDIPlus_GraphicsDrawStringEx($hGraphic, '-1', $hFont, $tLayout, $hFormat, $hBrush)
        $tLayout = _GDIPlus_RectFCreate(300, 150, 50, 20)
        _GDIPlus_GraphicsDrawStringEx($hGraphic, '1', $hFont, $tLayout, $hFormat, $hBrush)
        $hPen = _GDIPlus_PenCreate()
        _GDIPlus_GraphicsDrawLine($hGraphic, 0, 150, 400, 150, $hPen)
                         ;   _GDIPlus_GraphicsDrawLine($hGraphic, 60, 20, 60, 600, $hPen);60  横坐标,600纵坐标
                                ;        _GDIPlus_GraphicsDrawLine($hGraphic, 60, 600, 400, 600, $hPen)
        _GDIPlus_GraphicsDrawLine($hGraphic, 200, 0, 200, 300, $hPen)
        $hAsymPen = _GDIPlus_PenCreate()
        _GDIPlus_PenSetDashStyle($hAsymPen, $GDIP_DASHSTYLEDASH)
        _GDIPlus_GraphicsDrawLine($hGraphic, 100, 0, 100, 300, $hAsymPen)
        _GDIPlus_GraphicsDrawLine($hGraphic, 300, 0, 300, 300, $hAsymPen)

        $aPoint[0][0] = 200
        $aPoint2[0][0] = 200
        For $i = 0 To 200 Step 1
                $aPoint[$j][0] = $i * 3 + 0
                $aPoint[$j][1] = 150 - Sqrt($i * 5)
                $aPoint2[$j][0] = $i * 3 + 0
                $aPoint2[$j][1] = 150 + Sqrt($i * 5)
                $j += 1
        Next
        _GDIPlus_GraphicsDrawCurve($hGraphic, $aPoint)
        _GDIPlus_GraphicsDrawCurve($hGraphic, $aPoint2)
        
        ; 循环至用户退出
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        ; 清除资源
        _GDIPlus_PenDispose($hPen)
        _GDIPlus_PenDispose($hAsymPen)
        _GDIPlus_FontDispose($hFont)
        _GDIPlus_FontFamilyDispose($hFamily)
        _GDIPlus_StringFormatDispose($hFormat)
        _GDIPlus_BrushDispose($hBrush)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()

EndFunc   ;==>_Main
Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
   
        _GDIPlus_GraphicsDrawEllipse ($hGraphic, 130, 100, 140, 70)
        
    Return $GUI_RUNDEFMSG
EndFunc
 楼主| 发表于 2014-10-30 18:36:45 | 显示全部楼层
再顶一下
我的意思就是如何画一条有断点的曲线

发表于 2014-11-2 18:33:57 | 显示全部楼层
不懂……帮顶…
发表于 2014-11-2 19:27:43 | 显示全部楼层
本帖最后由 netegg 于 2014-11-2 19:47 编辑

设置好取样点的范围就行了
另外一种方式,设置有线的地方,笔色为黑色,非范围内的地方,把笔删掉
 楼主| 发表于 2014-11-2 19:59:07 | 显示全部楼层
谢谢 netegg的指导,采用如下语句画线
_GDIPlus_GraphicsDrawCurve($hGraphic, $aPoint)
如果是较少的数据还可以分段取点,数据多了也不固定在某段,很难设置取样点
设置有线的笔为黑色,非范围内的删掉,能否举个例子
我试了多次,画完图后,再原图基础上再往回画图就不行了
请 netegg元老继续指导
发表于 2014-11-2 20:40:16 | 显示全部楼层
不考虑断点的情况下,曲线是连续的吗
发表于 2014-11-2 20:43:17 | 显示全部楼层
本帖最后由 netegg 于 2014-11-2 20:45 编辑

[au3]#include <Math.au3>
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
        Local $hGUI, $hWnd, $hGraphic, $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $hPen, $hPen1
        Local $aPoint1[301][2],$aPoint2[301][2] , $m =1, $j=1, $hAsymPen


        ; 创建界面
        $hGUI = GUICreate("Inverse Secant", 400, 300)
        $hWnd = WinGetHandle("Inverse Secant")
        GUISetState()

        ; 绘制字符串
        _GDIPlus_Startup()
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
        $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
        $hFormat = _GDIPlus_StringFormatCreate()
        $hFamily = _GDIPlus_FontFamilyCreate("Arial")
        $hFont = _GDIPlus_FontCreate($hFamily, 8, 2)
        $tLayout = _GDIPlus_RectFCreate(200, 150, 50, 20)
        _GDIPlus_GraphicsDrawStringEx($hGraphic, 'O(0,0)', $hFont, $tLayout, $hFormat, $hBrush)
        $tLayout = _GDIPlus_RectFCreate(20, 20, 200, 20)
        _GDIPlus_GraphicsDrawStringEx($hGraphic, 'Inverse Secant', $hFont, $tLayout, $hFormat, $hBrush)
        $tLayout = _GDIPlus_RectFCreate(244, 150, 20, 20)
        _GDIPlus_GraphicsDrawStringEx($hGraphic, '1', $hFont, $tLayout, $hFormat, $hBrush)
        $tLayout = _GDIPlus_RectFCreate(150, 150, 20, 20)
        _GDIPlus_GraphicsDrawStringEx($hGraphic, '-1', $hFont, $tLayout, $hFormat, $hBrush)
        $hPen = _GDIPlus_PenCreate()
        _GDIPlus_GraphicsDrawLine($hGraphic, 0, 150, 248, 150, $hPen)
        _GDIPlus_GraphicsDrawLine($hGraphic, 252, 150, 400, 150, $hPen)
        _GDIPlus_GraphicsDrawLine($hGraphic, 200, 0, 200, 300, $hPen)
        _GDIPlus_GraphicsDrawEllipse($hGraphic, 248, 148, 4, 4)

        $aPoint1[0][0] = 299
        $aPoint2[0][0] = 299
        For $i = -4 To -1.01 Step 0.01
                $aPoint1[$m][0] = $i * 50 + 200
                $aPoint1[$m][1] = 150 - _ASec($i) * 30
                $m += 1
        Next
        _GDIPlus_GraphicsDrawCurve($hGraphic, $aPoint1)
        For $i = 1.01 To 4 Step 0.01
                $aPoint2[$j][0] = $i * 50 + 200
                $aPoint2[$j][1] = 150 - _ASec($i) * 30
                $j += 1
        Next
        _GDIPlus_GraphicsDrawCurve($hGraphic, $aPoint2)
        _GDIPlus_GraphicsDrawEllipse($hGraphic, $aPoint1[$m-1][0] -1, $aPoint1[$m-1][1]-1, 4, 4)
        $hAsymPen = _GDIPlus_PenCreate()
        _GDIPlus_PenSetDashStyle($hAsymPen, $GDIP_DASHSTYLEDOT)
        _GDIPlus_GraphicsDrawLine($hGraphic, 150, 0, 150, $aPoint1[$m-1][1]-1, $hAsymPen)
        _GDIPlus_GraphicsDrawLine($hGraphic, 150, $aPoint1[$m-1][1]+3, 150, 300, $hAsymPen)
        _GDIPlus_GraphicsDrawLine($hGraphic, 0, ($aPoint1[1][1]+$aPoint2[$j-1][1])/2, 400, ($aPoint1[1][1]+$aPoint2[$j-1][1])/2, $hAsymPen)
        $tLayout = _GDIPlus_RectFCreate(200, ($aPoint1[1][1]+$aPoint2[$j-1][1])/2 - 15, 40, 20)
        _GDIPlus_GraphicsDrawStringEx($hGraphic, 'π/2', $hFont, $tLayout, $hFormat, $hBrush)
       
        ; 循环至用户退出
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        ; 清除资源
        _GDIPlus_PenDispose($hPen)
        _GDIPlus_PenDispose($hAsymPen)
        _GDIPlus_FontDispose($hFont)
        _GDIPlus_FontFamilyDispose($hFamily)
        _GDIPlus_StringFormatDispose($hFormat)
        _GDIPlus_BrushDispose($hBrush)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()

EndFunc   ;==>_Main
[/au3]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2014-11-2 20:52:58 | 显示全部楼层
[au3]#include <Math.au3>
#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
        Local $hGUI, $hWnd, $hGraphic, $hBrush, $tLayout1, $hFormat, $hFamily, $hFont, $tLayout, $hPen, $hDashPen
        Dim $aPoint[802][2], $j = 0, $w = 1
        ; 创建界面
        $hGUI = GUICreate("Tangent", 400, 300)
        $hWnd = WinGetHandle("Tangent")
        GUISetState()

        ; 绘制字符串
        _GDIPlus_Startup()
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
        $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
        $hFormat = _GDIPlus_StringFormatCreate()
        $hFamily = _GDIPlus_FontFamilyCreate("Arial")
        $hFont = _GDIPlus_FontCreate($hFamily, 8, 2)
        $tLayout = _GDIPlus_RectFCreate(200, 150, 20, 20)
        _GDIPlus_GraphicsDrawStringEx($hGraphic, 'O', $hFont, $tLayout, $hFormat, $hBrush)
        $tLayout = _GDIPlus_RectFCreate(20, 20, 200, 1000)
        _GDIPlus_GraphicsDrawStringEx($hGraphic, 'Tangent', $hFont, $tLayout, $hFormat, $hBrush)
        $hPen = _GDIPlus_PenCreate()
        _GDIPlus_GraphicsDrawLine($hGraphic, 0, 150, 400, 150, $hPen)
        _GDIPlus_GraphicsDrawLine($hGraphic, 200, 0, 200, 300, $hPen)
        $hDashPen = _GDIPlus_PenCreate()
        _GDIPlus_PenSetDashStyle($hDashPen, $GDIP_DASHSTYLEDOT)

       
        $aPoint[0][0] = 801
        For $i = -8 To 8 Step 0.01
                $aPoint[$j][0] = $i * 50 + 200
                $aPoint[$j][1] = 150 - _Tan($i * $pi) * 50
                If $j Then
                        If $j > 2 Then
                                Dim $a0 = 150 - $aPoint[$j][1]
                                Dim $a1 = 150 - $aPoint[$j - 1][1]
                                Dim $a2 = 150 - $aPoint[$j - 2][1]
                                If (150 - $a0) * (150 - $a2) < 0 Then
                                        $w += 1
                                        _GDIPlus_GraphicsDrawLine($hGraphic, $aPoint[$j - 1][0] + 4, 0, $aPoint[$j - 1][0] + 4, 300, $hDashPen)
                                        $tLayout = _GDIPlus_RectFCreate($aPoint[$j - 1][0] + 4, 150, 70, 40)
                                        _GDIPlus_GraphicsDrawStringEx($hGraphic, ($w * 2 - 19) & 'π/2', $hFont, $tLayout, $hFormat, $hBrush)
                                EndIf
                        EndIf

                        If $aPoint[$j][1] * $aPoint[$j - 1][1] < 0 Then
                                ReDim $aPoint[$j+1][2]
                                $aPoint[0][0] = $j
                                _GDIPlus_GraphicsDrawCurve($hGraphic, $aPoint)
                                $aPoint[0][0] = 0
                                ReDim $aPoint[802][2]
                                $aPoint[0][0] = 801
                                $j = 0
                        EndIf
                EndIf
                $j += 1
        Next

        ; 循环至用户退出
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        ; 清除资源
        _GDIPlus_PenDispose($hPen)
        _GDIPlus_FontDispose($hFont)
        _GDIPlus_FontFamilyDispose($hFamily)
        _GDIPlus_StringFormatDispose($hFormat)
        _GDIPlus_BrushDispose($hBrush)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()

EndFunc   ;==>_Main
[/au3]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2014-11-2 20:58:12 | 显示全部楼层
本帖最后由 续缘8003 于 2014-11-2 21:04 编辑

谢谢netegg 元老的耐心讲解,我正在看您的代码,
我用_GDIPlus_GraphicsDrawLine完成了断点的问题,只是曲线中有不连续的地方,很奇怪
再一次谢谢。
发表于 2014-11-2 21:02:03 | 显示全部楼层
本帖最后由 netegg 于 2014-11-2 21:07 编辑

首先创建两个画笔,一个黑色,一个透明,取点的横坐标,在范围内用黑色,不在范围内不画
 楼主| 发表于 2014-11-2 21:06:44 | 显示全部楼层
好的,我在试一试,我的math.au3中没有 _Tan等,不知为何
发表于 2014-11-2 21:07:42 | 显示全部楼层
那是没有,我加的
发表于 2014-11-2 21:24:32 | 显示全部楼层
[au3]#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>

Opt('MustDeclareVars', 1)
Global $hGUI, $hWnd, $hGraphic;,$WM_PAINT

;GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")

_Main()

Func _Main()
        Local $hBrush, $hAsymPen, $hFormat, $hFamily, $hFont, $tLayout, $hPen
        Local $aPoint[10000][3], $aPoint2[10000][3], $j = 1

        ; 创建界面
        ;$hGUI = GUICreate("Parabola", 400, 300)
        ;$hWnd = WinGetHandle("Parabola")
                $hGUI = GUICreate("", 350, 350)
                ;GUICreate()
        $hWnd = WinGetHandle($hGUI)
        GUISetState()
        
        _GDIPlus_Startup()
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
        $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)

        $aPoint[0][0] = 200
        $aPoint2[0][0] = 200
        For $i = 0 To 200 Step 1
                        If Not($i < 10 or $i<20) and Not($i>100 and $i<180) then
                $aPoint[$j][0] = $i * 3 + 0
                $aPoint[$j][1] = 150 - Sqrt($i * 5)
                $aPoint2[$j][0] = $i * 3 + 0
                $aPoint2[$j][1] = 150 + Sqrt($i * 5)
                $j += 1
                        EndIf
        Next
        _GDIPlus_GraphicsDrawCurve($hGraphic, $aPoint)
        _GDIPlus_GraphicsDrawCurve($hGraphic, $aPoint2)
        
        ; 循环至用户退出
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        ; 清除资源
        _GDIPlus_PenDispose($hPen)
        _GDIPlus_PenDispose($hAsymPen)
        _GDIPlus_FontDispose($hFont)
        _GDIPlus_FontFamilyDispose($hFamily)
        _GDIPlus_StringFormatDispose($hFormat)
        _GDIPlus_BrushDispose($hBrush)
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_Shutdown()

EndFunc   ;==>_Main
#cs
Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
   
        _GDIPlus_GraphicsDrawEllipse ($hGraphic, 130, 100, 140, 70)
        
    Return $GUI_RUNDEFMSG
EndFunc
#ce
[/au3]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2014-11-2 22:07:07 | 显示全部楼层
谢谢netegg元老,您的热心是大家的榜样
上图中需要表达的意思是1到200曲线是连续的
但我想人为让150到160之间缺数,就是用白色的透明画笔画出来,
其他的数据依旧用黑色的画笔画出,看着好像曲线缺了一部分,
看了您的代码,我再多试试
发表于 2014-11-2 22:22:08 | 显示全部楼层
If $i >150 and $i<160 then
创建个白色的笔,一样画
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-18 14:40 , Processed in 0.084336 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表