找回密码
 加入
搜索
查看: 8935|回复: 8

[GUI管理] 单横线的input输入框(已解决)

  [复制链接]
发表于 2010-10-16 15:42:10 | 显示全部楼层 |阅读模式
本帖最后由 gto250 于 2010-10-16 19:07 编辑



见图,制作了一个单横线的input输入框,最小化然后还原,横线还在,但是做成UDF后,最小化后还原,横线就不见了,请各位看看,哪里出错了

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 208, 120, 121, 15, -1, 0)
GUICtrlSetBkColor(-1, _WinAPI_GetSysColor($COLOR_BTNFACE))

_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND(WinGetHandle("Form1"))
$hPen = _GDIPlus_PenCreate()
_GDIPlus_GraphicsDrawLine($hGraphic, 208, 141, 329, 141, $hPen)
GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
GUISetState(@SW_SHOW)



While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        _GDIPlus_PenDispose($hPen)
                        _GDIPlus_GraphicsDispose($hGraphic)
                        _GDIPlus_Shutdown()
                        Exit

        EndSwitch
WEnd



Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
        _WinAPI_RedrawWindow($Form1, 0, 0, $RDW_UPDATENOW)
        _GDIPlus_GraphicsDrawLine($hGraphic, 208, 135, 329, 135, $hPen)
        _WinAPI_RedrawWindow($Form1, 0, 0, $RDW_VALIDATE)
        Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_PAINT




#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
Global $_input_line_id[1] = [0], $MY_f_hwnd
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 473, 267, 192, 124)
$Input1 = My_Input_Create("Input1", 152, 48, 121, 21)
$Input1 = My_Input_Create("456", 20, 70, 121, 21, "", "", "", 0)
$Input1 = My_Input_Create("456", 20, 100, 121, 21, "", "", "", 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd

Func My_Input_Create($text = "MY input", $left = 0, $top = 0, $width = 121, $height = 20, $font_name = "MS Sans Serif", $font_size = 8, $font_color = 0x000000, $styles = -1) ;$style 样式 默认为正常 ,0为password 1为只输入数字
        Switch $styles
                Case -1
                        $style = -1
                Case 0
                        $style = 32
                Case 1
                        $style = 8192
        EndSwitch
        $new_id = GUICtrlCreateInput($text, $left, $top, $width, $font_size * 2 - 1, $style, 0)
        GUICtrlSetFont(-1, $font_size, 400, 0, $font_name)
        GUICtrlSetColor(-1, $font_color)
        _GDIPlus_Startup()
        GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
        GUICtrlSetBkColor(-1, _WinAPI_GetSysColor($COLOR_BTNFACE))
        Local $iUBound = UBound($_input_line_id)
        ReDim $_input_line_id[$iUBound + 1]
        $_input_line_id[$iUBound] = $new_id
        Return $new_id
EndFunc   ;==>My_Input_Create


Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
        If UBound($_input_line_id) > 1 Then
                If $MY_f_hwnd = "" Then
                        $var = WinList()
                        For $i = 1 To $var[0][0]
                                ; 只显示带有标题的可见窗口
                                If WinGetProcess($var[$i][0]) = @AutoItPID Then
                                        $MY_f_hwnd = WinGetHandle($var[$i][0])
                                EndIf
                        Next
                EndIf

                $hGraphic = _GDIPlus_GraphicsCreateFromHWND($MY_f_hwnd)
                $hPen = _GDIPlus_PenCreate()
                For $i = 1 To UBound($_input_line_id) - 1
                        $tRect = ControlGetPos($MY_f_hwnd, "", $_input_line_id[$i])
                        $lf = $tRect[0]
                        $top = $tRect[1]
                        $rt = $tRect[2]
                        $bottom = $tRect[3]
                        _GDIPlus_GraphicsDrawLine($hGraphic, $lf, $top + $bottom, $lf + $rt, $top + $bottom, $hPen)
                Next
                _WinAPI_RedrawWindow($MY_f_hwnd, 0, 0, $RDW_UPDATENOW)
        EndIf
        Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_PAINT

本帖子中包含更多资源

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

×

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-10-16 16:30:16 | 显示全部楼层
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
Global $_input_line_id[1] = [0], $MY_f_hwnd
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 473, 267, 192, 124)
$Input1 = My_Input_Create("Input1", 152, 48, 121, 21)
$Input1 = My_Input_Create("456", 20, 70, 121, 21, "", "", "", 0)
$Input1 = My_Input_Create("456", 20, 100, 121, 21, "", "", "", 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
 
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
 
        EndSwitch
WEnd
 
Func My_Input_Create($text = "MY input", $left = 0, $top = 0, $width = 121, $height = 20, $font_name = "MS Sans Serif", $font_size = 8, $font_color = 0x000000, $styles = -1) ;$style 样式 默认为正常 ,0为password 1为只输入数字
        Switch $styles
                Case -1
                        $style = -1
                Case 0
                        $style = 32
                Case 1
                        $style = 8192
        EndSwitch
        $new_id = GUICtrlCreateInput($text, $left, $top, $width, $font_size * 2 - 1, $style, 0)
        GUICtrlSetFont(-1, $font_size, 400, 0, $font_name)
        GUICtrlSetColor(-1, $font_color)
        _GDIPlus_Startup()
        GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
        GUICtrlSetBkColor(-1, _WinAPI_GetSysColor($COLOR_BTNFACE))
        Local $iUBound = UBound($_input_line_id)
        ReDim $_input_line_id[$iUBound + 1]
        $_input_line_id[$iUBound] = $new_id
        Return $new_id
EndFunc   ;==>My_Input_Create
 
 
Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
        _WinAPI_RedrawWindow($Form1, 0, 0, $RDW_UPDATENOW)
        _WinAPI_RedrawWindow($Form1, 0, 0, $RDW_VALIDATE)
        If UBound($_input_line_id) > 1 Then
                If $MY_f_hwnd = "" Then
                        $var = WinList()
                        For $i = 1 To $var[0][0]
                                ; 只显示带有标题的可见窗口
                                If WinGetProcess($var[$i][0]) = @AutoItPID Then
                                        $MY_f_hwnd = WinGetHandle($var[$i][0])
                                EndIf
                        Next
                EndIf
 
                $hGraphic = _GDIPlus_GraphicsCreateFromHWND($MY_f_hwnd)
                $hPen = _GDIPlus_PenCreate()
                For $i = 1 To UBound($_input_line_id) - 1
                        $tRect = ControlGetPos($MY_f_hwnd, "", $_input_line_id[$i])
                        $lf = $tRect[0]
                        $top = $tRect[1]
                        $rt = $tRect[2]
                        $bottom = $tRect[3]
                        _GDIPlus_GraphicsDrawLine($hGraphic, $lf, $top + $bottom, $lf + $rt, $top + $bottom, $hPen)
                Next
                _WinAPI_RedrawWindow($MY_f_hwnd, 0, 0, $RDW_UPDATENOW)
        EndIf
        Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_PAINT
你试试上面的代码看看。
我添加如下代码上就行了:
     _WinAPI_RedrawWindow($Form1, 0, 0, $RDW_UPDATENOW)
        _WinAPI_RedrawWindow($Form1, 0, 0, $RDW_VALIDATE)

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2010-10-16 19:07:04 | 显示全部楼层
谢谢提醒,原来是少了一句

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
Global $_input_line_id[1] = [0], $MY_f_hwnd
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 473, 267, 192, 124)
$Input1 = My_Input_Create("Input1", 152, 48, 121, 21)
$Input1 = My_Input_Create("456", 20, 70, 121, 21, "", "", "", 0)
$Input1 = My_Input_Create("456", 20, 100, 121, 21, "", "", "", 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit

        EndSwitch
WEnd










Func My_Input_Create($text = "MY input", $left = 0, $top = 0, $width = 121, $height = 20, $font_name = "MS Sans Serif", $font_size = 8, $font_color = 0x000000, $styles = -1) ;$style 样式 默认为正常 ,0为password 1为只输入数字
        Switch $styles
                Case -1
                        $style = -1
                Case 0
                        $style = 32
                Case 1
                        $style = 8192
        EndSwitch
        $new_id = GUICtrlCreateInput($text, $left, $top, $width, $font_size * 2 - 1, $style, 0)
        GUICtrlSetFont(-1, $font_size, 400, 0, $font_name)
        GUICtrlSetColor(-1, $font_color)
        _GDIPlus_Startup()
        GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
        GUICtrlSetBkColor(-1, _WinAPI_GetSysColor($COLOR_BTNFACE))
        Local $iUBound = UBound($_input_line_id)
        ReDim $_input_line_id[$iUBound + 1]
        $_input_line_id[$iUBound] = $new_id
        Return $new_id
EndFunc   ;==>My_Input_Create


Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
        If UBound($_input_line_id) > 1 Then
                If $MY_f_hwnd = "" Then
                        $var = WinList()
                        For $i = 1 To $var[0][0]
                                ; 只显示带有标题的可见窗口
                                If WinGetProcess($var[$i][0]) = @AutoItPID Then
                                        $MY_f_hwnd = WinGetHandle($var[$i][0])
                                EndIf
                        Next
                EndIf

                $hGraphic = _GDIPlus_GraphicsCreateFromHWND($MY_f_hwnd)
                $hPen = _GDIPlus_PenCreate()
                For $i = 1 To UBound($_input_line_id) - 1
                        $tRect = ControlGetPos($MY_f_hwnd, "", $_input_line_id[$i])
                        $lf = $tRect[0]
                        $top = $tRect[1]
                        $rt = $tRect[2]
                        $bottom = $tRect[3]
                        _WinAPI_RedrawWindow($MY_f_hwnd, 0, 0, $RDW_UPDATENOW)
                        _GDIPlus_GraphicsDrawLine($hGraphic, $lf, $top + $bottom, $lf + $rt, $top + $bottom, $hPen)
                        _WinAPI_RedrawWindow($MY_f_hwnd, 0, 0, $RDW_VALIDATE)

                Next
                
        EndIf
        Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_PAINT
发表于 2010-10-16 19:36:42 | 显示全部楼层
太帅了。。收藏
发表于 2010-10-16 20:06:49 | 显示全部楼层
留着备用,呵呵
发表于 2010-12-11 20:08:36 | 显示全部楼层
不错  有创意   收藏  留着备用
发表于 2012-5-30 00:54:47 | 显示全部楼层
这个效果确实不错,值得收藏!嘿嘿!
发表于 2012-5-30 09:29:43 | 显示全部楼层
学习收藏,以作备用,谢谢!
发表于 2014-4-8 21:31:37 | 显示全部楼层
偶也来一个
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>

$myGUI = GUICreate("Test", 400, 300)
GUICtrlSetDefColor(0x0000FF)
$input = GUICtrlCreateInput("Input here", 60, 60, 120, 18, $ES_AUTOHSCROLL, 0)
GUICtrlSetFont(-1, 9, 600)
GUICtrlCreateLabel("", 56, 78, 130, 1)
GUICtrlSetBkColor(-1, 0x000000)
GUISetState()

GUICtrlSetBkColor($input, PixelGetColor(20, 20, $myGUI))
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-28 04:41 , Processed in 0.084754 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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