aus MSDN :
WM_CTLCOLORBTN bug
WM_CTLCOLORBTN does not perform as intended on Windows XP SP2/SP3 (and others?).
To properly change the foreground and background color of BUTTON types (and others)
Use the WM_CTLCOLORSTATIC message. You DO NOT use the BS_OWNERDRAW style!
Example code (using a BUTTON, with style BS_AUTORADIOBUTTON):
LRESULT CALLBACK WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_CTLCOLORSTATIC: {
if ((HWND)lParam == filterNameOff) {
static HBRUSH hBrushColor;
if (!hBrushColor) {
hBrushColor = CreateSolidBrush(RGB(0xFF, 0xFF, 0xFF)); // White background is returned
SetBkColor((HDC)wParam, RGB(0xFF, 0xFF, 0xFF)); // White background for text
}
// Background color that is used to repaint the control (doesn't affect text background)
return (LRESULT)hBrushColor;
}
}
....
Warum funktioniert dieser Code nicht ?
Set("FastMode",1)
$H windows.ph
$H messages.ph
$I C:\PRFellow\LIB\profalt.inc
Declare brush&
Def GetWindowLong(2) !"USER32","GetWindowLongA"
Def SetWindowLong(3) !"USER32","SetWindowLongA"
Def SetWinPos(7) !"USER32","SetWindowPos"
Proc wSetStyle
Parameters h&,s&,x%
SetWindowLong(h&,x%,Or(GetWindowLong(h&,x%),s&))
SetWinPos(h&,0,0,0,0,0,$023)
EndProc
Proc SetWindowStyles
Parameters h&,s&,x&
WSetStyle h&,s&,-16
WSetStyle h&,x&,-20
EndProc
PROC SetColor
Parameters col&,bk&,wParam&
IF Brush&
~DeleteObject(Brush&)
Endif
Brush& = ~CreateSolidBrush(bk&)
'~SetBkMode(wParam&, ~TRANSPARENT)
~SetBkColor(wparam&, bk&)
~SetTextColor(wParam&,col&)
Return Brush&
Endproc
Proc newcallback
Parameters wnd&,msg&,wparam&,lparam&
IF msg&=~WM_CTLCOLORStatic
If lparam&=static&
Return SetColor(rgb(199,120,000),rgb(199,100,000),wParam&)
EndIf
EndIf
If msg&=~WM_CLOSE
~DeleteObject(brush&)
raus&=1
Endif
RETURN ~CallWindowProc(oldcallback&,wnd&,msg&,wparam&,lparam&)
EndProc
cls
'BS_AUTORADIOBUTTON Style setzen $09
var static&= @Control("Button", "1", $5000000A, 16,16,60,20, %hWnd,0, %hInstance)
var oldcallback&=~SetWindowLong(%hwnd,~GWL_WNDPROC,ProcAddr("newcallback",4))
Var raus&=0
WhileNot raus&
WaitInput
EndWhile
End
Alles anzeigen