guest3456 wrote:
guest3456 wrote:
nitpick request:
i think 'OK' should be displayed green in contrast to red for 'FAIL'
ok, i implemented this, but not sure if its the best way to do it. i didnt see any other way of changing the font color from another function, other than using the build in ahk gui variables. DllCall("CreateFont") and then SendMessage, WM_SETFONT wouldnt work, since CreateFont didnt have a color parameter
some more work to try to avoid using the built in gui global..
SetTextColor directly didn't work either:
Code:
;// does not work
UTest_start( bNoGui = false) {
if !bNoGui
hGui := UTest_CreateGui()
s := UTest_RunTests()
if (hGui){
;Result := UTest("TestsFail") ? "FAIL" : "OK"
ControlGet, texthwnd, hwnd,, Static1, ahk_id %hGui%
hDC := DllCall("user32.dll\GetDC", "UInt", texthwnd)
if UTest("TestsFail") {
Result := "FAIL"
oldcolor := DllCall("gdi32.dll\SetTextColor", "UInt", hDC, "UInt", 0x000000FF)
} else {
Result := "OK"
oldcolor := DllCall("gdi32.dll\SetTextColor", "UInt", hDC, "UInt", 0x0000FF00)
}
DllCall("gdi32.dll\ReleaseDC", "UInt", hGui, "UInt", hDC)
ControlSetText,Static1, %Result%, ahk_id %hGui%
}
return s
}
but this does work:
requires:
CColor from Forms Framework
(
http://www.autohotkey.com/forum/topic53317.html)
GetSysColor
(
http://www.autohotkey.com/forum/topic60215.html)
Code:
#include CColor.ahk
UTest_start( bNoGui = false) {
if !bNoGui
hGui := UTest_CreateGui()
s := UTest_RunTests()
if (hGui){
;Result := UTest("TestsFail") ? "FAIL" : "OK"
ControlGet, texthwnd, hwnd,, Static1, ahk_id %hGui%
bgcolor := GetSysColor(15) ; Window Background color for the current desktop theme
if UTest("TestsFail") {
Result := "FAIL"
CColor(texthwnd, bgcolor, "red")
} else {
Result := "OK"
CColor(texthwnd, bgcolor, "green")
}
ControlSetText,Static1, %Result%, ahk_id %hGui%
}
return s
}
;// http://www.autohotkey.com/forum/topic60215.html
GetSysColor( DisplayElement=1 ) {
VarSetCapacity( HexClr,7,0 ), SClr := DllCall( "GetSysColor", UInt,DisplayElement )
RGB := ( ( ( SClr & 0xFF) << 16 ) | ( SClr & 0xFF00 ) | ( ( SClr & 0xFF0000 ) >> 16 ) )
DllCall( "msvcrt\sprintf", Str,HexClr, Str,"%06X", UInt,RGB )
Return HexClr
}