(已解决)如何返回指定控件的背景颜色代码
本帖最后由 suifeng123 于 2010-8-7 16:35 编辑如何返回指定控件的背景颜色啊???我查帮助文档查了一晚上也没查到,,,请高手指点一下啊。。。
谢谢!!! 我也没找着,帮顶一下
要不然再找一晚上吧{:face (280):} 既然有 GUICtrlSetBkColor(),怎么没有反向的函数呢??? 不知道你要获得什么控件的背景色呢?
_GUICtrlRebar_GetBKColor?
_GUICtrlListView_GetBkColor?
_GUIToolTip_GetTipBkColor?
_GUICtrlTreeView_GetBkColor?
_GUICtrlRichEdit_GetBkColor? 既然有SetBkColor,当然就有GetBkColor了! 是GUICtrlCreateInput() 或GUICtrlCreateEdit() 的 学习了,谢谢。 本帖最后由 suifeng123 于 2010-8-7 12:02 编辑
难道没有办法可以解决吗?
我的想法是: 输入或编辑框的文字是变颜色的,当变成白色时由于白色背景,文字就看不出来了,所以检测输入框或编辑框的背景颜色,当文字颜色变的很浅时,自动改变背景的颜色为深色的。当文字颜色变得很深时,改变背景为白色。请高手帮忙看如何解决。 #include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Global $WINDOW_TO_QUERY, $___RGBTC, $___RGBBGC
GUIRegisterMsg($WM_CTLCOLORSTATIC, "MY_CTLCOLOR")
GUIRegisterMsg($WM_CTLCOLOREDIT, "MY_CTLCOLOR")
GUIRegisterMsg($WM_CTLCOLORBTN, "MY_CTLCOLOR")
$hGui = GUICreate('Test', 200, 200)
GUISetBkColor(0xABCDEF)
$hButton = GUICtrlCreateButton("change", 20, 160, 40, 20)
$hButton_1 = GUICtrlCreateButton("msg", 120, 160, 40, 20)
$Input = GUICtrlCreateInput('Simple text', 20, 20, 160, 20)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetBkColor(-1, 0x0000FF)
GUISetState()
$Z = 1
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $hButton
;$color=0xABCDEF
If $Z = 1 Then
GUICtrlSetBkColor($Input, 0xABCDEF)
$Z = 0
Else
GUICtrlSetBkColor($Input, 0xADEFAC)
$Z = 1
EndIf
Case $msg = $hButton_1
MsgBox(0, 'Colours in RGB format', 'Text colour input = : 0x' & Hex(_WinAPI_GetTextColor($Input, 1), 6) & @CRLF & _
'BackGnd colour input = : 0x' & Hex(_WinAPI_GetTextColor($Input), 6) & @CRLF & _
'BackGnd colour GUI = : 0x' & Hex(_WinAPI_GetBkColor($hGui), 6) & @CRLF)
EndSelect
WEnd
; $BGC_TC = 0 for background colour,$BGC_TC <> 0 for text colour
Func _WinAPI_GetTextColor($hWnd, $BGC_TC = 0)
; Prog@ndy
Global $___RGBTC = -1, $___RGBBGC = -1
If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
$WINDOW_TO_QUERY = $hWnd
_WinAPI_RedrawWindow($hWnd, 0, 0, $RDW_INVALIDATE + $RDW_UPDATENOW)
Do
Sleep(10)
Until $___RGBTC <> -1 And $___RGBBGC <> -1
If $BGC_TC = 0 Then
Return $___RGBBGC
Else
Return $___RGBTC
EndIf
EndFunc ;==>_WinAPI_GetTextColor
Func MY_CTLCOLOR($hWnd, $uMsg, $wParam, $lParam)
; Prog@ndy
If $lParam = $WINDOW_TO_QUERY Then
Local $RGB = DllCall('gdi32.dll', 'int', 'GetTextColor', 'ptr', $wParam)
If Not @error Then
Global $___RGBTC = "0x" & StringRegExpReplace(Hex($RGB, 6), "(.{2})(.{2})(.{2})", "\3\2\1")
Else
Global $___RGBTC = -2
EndIf
Local $___RGBBGC = DllCall('gdi32.dll', 'int', 'GetBkColor', 'ptr', $wParam)
If Not @error Then
Global $___RGBBGC = "0x" & StringRegExpReplace(Hex($___RGBBGC, 6), "(.{2})(.{2})(.{2})", "\3\2\1")
Else
Global $___RGBBGC = -2
EndIf
EndIf
Return 'GUI_RUNDEFMSG'
EndFunc ;==>MY_CTLCOLOR
; Get background colour of GUI window, NOT a control.
Func _WinAPI_GetBkColor($hWnd)
; Not Prog@ndy
Local $aResult, $hDC, $Res
If Not IsHWnd($hWnd) Then $hWnd = ControlGetHandle("", "", $hWnd)
$hDC = _WinAPI_GetDC($hWnd)
$aResult = DllCall("GDI32.dll", "int", "GetBkColor", "hwnd", $hDC)
ConsoleWrite("Hex($aResult, 6) = " & Hex($aResult, 6) & @CRLF)
$Res = "0x" & StringRegExpReplace(Hex($aResult, 6), "(.{2})(.{2})(.{2})", "\3\2\1")
_WinAPI_ReleaseDC($hWnd, $hDC)
Return $Res
EndFunc ;==>_WinAPI_GetBkColor 3mile 真厉害!!!多谢 学习了,谢谢。 學習了.哈哈剛剛接觸AU3,壇力牛人還是很多嗎~~ 学习了,谢谢 这个很好,大部分规范的控件都可以.可惜有些控件还是找不到.
页:
[1]