Unfortunately, there are some very strange offsets when trying to read a screen pixel (using GetPixel). Perhaps you can make sense of it.
uses corewin
% ID_Timer 3000
% Interval 100
dim cmdline as asciiz ptr,inst as sys
&cmdline=GetCommandLine
inst=GetModuleHandle 0
'
'
function WndProc (sys hWnd,wMsg,wParam,lparam) as sys callback
==============================================================
static as sys hdc, htimer
static as String txt
static as RECT crect
static as PAINTSTRUCT Paintst
static as POINT p
static as int pix
'==========
select wMsg
'==========
case WM_CREATE
static sys hDCs=GetDC 0
hTimer = SetTimer (hWnd, ID_Timer, 100, 0)
GetClientRect hWnd,&cRect
case WM_TIMER
GetCursorPos @p
pix=GetPixel(hDCs,p.x, p.y)
InvalidateRect hwnd,&crect, 1
case WM_DESTROY
ReleaseDC hDCs
KillTimer(hWnd,ID_TIMER)
PostQuitMessage 0
case WM_PAINT
hDC=BeginPaint hWnd,&Paintst
GetClientRect hWnd,&cRect
'style
'0x20 DT_SINGLELINE
'0x04 DT_VCENTER
'0x01 DT_CENTER
'0x25
SetBkColor hdc,pix
SetTextColor hdc,0
txt="x y color " str(p.x) " , " str(p.y) " , " hex(pix,4)
DrawText hDC,strptr txt,-1,&cRect,0x25
EndPaint hWnd,&Paintst
ValidateRect hwnd,&crect
case WM_KEYDOWN
Select wParam
Case 27 : SendMessage hwnd, WM_CLOSE, 0, 0 'ESCAPE
End Select
'
InvalidateRect hwnd, &cRect, 1 'FULL SCREEN REFRESH
case else
function=DefWindowProc hWnd,wMsg,wParam,lParam
end select
end function ' WndProc
Function WinMain(sys inst,prevInst,zstring*cmdline,sys show) as sys
===================================================================
WndClass wc
MSG wm
sys hwnd, wwd, wht, wtx, wty, tax
wc.style = CS_HREDRAW or CS_VREDRAW
wc.lpfnWndProc = @WndProc
wc.cbClsExtra =0
wc.cbWndExtra =0
wc.hInstance =inst
wc.hIcon=LoadIcon 0, IDI_APPLICATION
wc.hCursor=LoadCursor 0,IDC_ARROW
wc.hbrBackground = GetStockObject WHITE_BRUSH
wc.lpszMenuName =0
wc.lpszClassName = strptr "Demo"
RegisterClass (&wc)
Wwd = 400 : Wht = 200
Tax = GetSystemMetrics SM_CXSCREEN
Wtx = (Tax - Wwd) /2
Tax = GetSystemMetrics SM_CYSCREEN
Wty = (Tax - Wht) /2
hwnd = CreateWindowEx 0,wc.lpszClassName,"OXYGEN BASIC",WS_OVERLAPPEDWINDOW,Wtx,Wty,Wwd,Wht,0,0,inst,0
ShowWindow hwnd,SW_SHOW
UpdateWindow hwnd
'
sys bRet
'
do while bRet := GetMessage (@wm, 0, 0, 0)
if bret=0
exit while
end if
if bRet = -1
'show an error message
exit while
else
TranslateMessage @wm
DispatchMessage @wm
end if
end while
End Function
WinMain inst,0,cmdline,SW_NORMAL