If color of an object depends on this object's position, can't you simply ask the object what color it has instead of using this hacky WinAPI approach?