单横线的input输入框(已解决)
本帖最后由 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 = , $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
; 只显示带有标题的可见窗口
If WinGetProcess($var[$i]) = @AutoItPID Then
$MY_f_hwnd = WinGetHandle($var[$i])
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
$top = $tRect
$rt = $tRect
$bottom = $tRect
_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
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
Global $_input_line_id = , $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
; 只显示带有标题的可见窗口
If WinGetProcess($var[$i]) = @AutoItPID Then
$MY_f_hwnd = WinGetHandle($var[$i])
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
$top = $tRect
$rt = $tRect
$bottom = $tRect
_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) 谢谢提醒,原来是少了一句
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
Global $_input_line_id = , $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
; 只显示带有标题的可见窗口
If WinGetProcess($var[$i]) = @AutoItPID Then
$MY_f_hwnd = WinGetHandle($var[$i])
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
$top = $tRect
$rt = $tRect
$bottom = $tRect
_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
太帅了。。收藏 留着备用,呵呵 不错有创意 收藏留着备用 这个效果确实不错,值得收藏!嘿嘿! 学习收藏,以作备用,谢谢! 偶也来一个
#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
页:
[1]