Static color
Posted: Sun May 11, 2014 2:55 pm
Hi
Please help, window does not update colors properly.
click test-1 or test-2 than drag window left out of screen and drag it back, colors will be all same (as static-3).
How to fix it ?
thanks
ly
Please help, window does not update colors properly.
click test-1 or test-2 than drag window left out of screen and drag it back, colors will be all same (as static-3).
How to fix it ?
thanks
ly
Code: Select all
Enumeration
#ID_BT1 = 1001
#ID_BT2
#ID_BT3
#ID_ST1
#ID_ST2
#ID_ST3
EndEnumeration
Global.l hInstance
hInstance = GetModuleHandle_( null )
Global.l hSt1,hSt2,hSt3,hBtn1,hBtn2,hBtn3
Global.l ColorText,ColorBkg
Global.l hBrush
Declare WndProc(hWnd, uMsg, wParam, lParam)
Declare XHiWord(a.l)
Declare XLoWord(a.l)
Global Appname.s,Caption.s
Appname = "Win32"
Caption = "Simple Window"
Global wc.WNDCLASS
wc\style = #CS_VREDRAW | #CS_HREDRAW
wc\lpfnWndProc = @WndProc()
wc\cbClsExtra = 0
wc\cbWndExtra = 0
wc\hInstance = hInstance
wc\hIcon = LoadIcon_(hInstance, "#1")
wc\hCursor = LoadCursor_(0, #IDC_ARROW)
wc\hbrBackground = CreateSolidBrush_(GetSysColor_(15))
wc\lpszMenuName = 0
wc\lpszClassName = @Appname
RegisterClass_(wc)
hWnd = CreateWindowEx_(0,Appname,Caption,
#WS_OVERLAPPEDWINDOW | #WS_VISIBLE ,
100, 100, 600, 400,
0,0,wc\hInstance,0)
UpdateWindow_(hWnd)
ShowWindow_(hWnd,#SW_SHOWNORMAL)
SetForegroundWindow_(hWnd)
While GetMessage_(m.MSG, 0, 0, 0)
TranslateMessage_(m)
DispatchMessage_(m)
Wend
Procedure WndProc(hWnd,uMsg,wParam,lParam)
Select uMsg
Case #WM_CREATE
hBtn1 = CreateWindowEx_( 0,
"button", "Exit",
#WS_VISIBLE|#WS_CHILD,
520, 328, 60, 25,
hWnd, #ID_BT1, hInstance, null )
hBtn2 = CreateWindowEx_( 0,
"button", "Test-1",
#WS_VISIBLE|#WS_CHILD,
440, 328, 60, 25,
hWnd,#ID_BT2, hInstance, null )
hBtn3 = CreateWindowEx_( 0,
"button", "Test-2",
#WS_VISIBLE|#WS_CHILD,
360, 328, 60, 25,
hWnd,# ID_BT3, hInstance, null )
hSt1 = CreateWindowEx_( 0,
"static", "st1",
#WS_VISIBLE|#WS_CHILD|#SS_SUNKEN|#SS_NOTIFY,
5, 5, 40, 60,
hWnd, #ID_ST1, hInstance, null )
hSt2 = CreateWindowEx_( 0,
"static", "st2",
#WS_VISIBLE|#WS_CHILD|#SS_SUNKEN|#SS_NOTIFY,
5, 70, 40, 60,
hWnd, #ID_ST2, hInstance, null )
hSt3 = CreateWindowEx_( 0,
"static", "st3",
#WS_VISIBLE|#WS_CHILD|#SS_SUNKEN|#SS_NOTIFY,
5, 135, 40, 60,
hWnd,#ID_ST3, hInstance, null )
Case #WM_COMMAND
Select wParam
Case #BN_CLICKED << 16 | #ID_BT1
PostQuitMessage_(0)
Case #BN_CLICKED << 16 | #ID_BT2
ColorText = RGB(0,255,255)
ColorBkg = RGB(255,0,0)
InvalidateRect_(hSt1,NULL,TRUE)
UpdateWindow_(hSt1)
ColorText = RGB(255,0,255)
ColorBkg = RGB(0,255,0)
InvalidateRect_(hSt2,NULL,TRUE)
UpdateWindow_(hSt2)
ColorText = RGB(255,255,0)
ColorBkg = RGB(0,0,255)
InvalidateRect_(hSt3,NULL,TRUE)
UpdateWindow_(hSt3)
Case #BN_CLICKED << 16 | #ID_BT3
ColorText = RGB(0,0,255)
ColorBkg = RGB(255,255,0)
InvalidateRect_(hSt1,NULL,TRUE)
UpdateWindow_(hSt1)
ColorText = RGB(255,0,0)
ColorBkg = RGB(0,255,255)
InvalidateRect_(hSt2,NULL,TRUE)
UpdateWindow_(hSt2)
ColorText = RGB(0,255,0)
ColorBkg = RGB(255,0,255)
InvalidateRect_(hSt3,NULL,TRUE)
UpdateWindow_(hSt3)
EndSelect
Case #WM_CTLCOLORSTATIC
SetTextColor_(wParam,ColorText)
SetBkColor_(wParam,ColorBkg)
hBrush = CreateSolidBrush_(ColorBkg)
ProcedureReturn hBrush
Case WM_DESTROY
PostQuitMessage_( 0 )
EndSelect
ProcedureReturn DefWindowProc_(hWnd, uMsg, wParam, lParam)
EndProcedure
Procedure XHiWord(a.l)
ProcedureReturn Int(a / $10000)
EndProcedure
Procedure XLoWord(a.l)
ProcedureReturn Int(a - (Int(a/$10000)*$10000))
EndProcedure