本帖最后由 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
|