This is what I am currently doing:
GetWindowDC
CreateCompatibleDC
GetPixel
on my compatible DCUnfortunately, all of my GetPixel calls are returning CLR_INVALID
. Here is my code.
bool Gameboard::Refresh()
{
bool ret = false;
HDC context, localContext;
context = GetWindowDC(m_window);
if (context != NULL)
{
localContext = CreateCompatibleDC(context);
if (localContext != NULL)
{
if (BitBlt(localContext, 0, 0, GameboardInfo::BoardWidth, GameboardInfo::BoardHeight,
context, GameboardInfo::TopLeft.x, GameboardInfo::TopLeft.y, SRCCOPY))
{
ret = true;
// several calls to GetPixel which all return CLR_INVALID
}
DeleteDC(localContext);
}
ReleaseDC(m_window, context);
}
return ret;
}
Any ideas?
I believe you need to select a bitmap into your device context.
"A bitmap must be selected within the device context, otherwise, CLR_INVALID is returned on all pixels." - GetPixel()
bool Gameboard::Refresh()
{
bool ret = false;
HDC context, localContext;
HGDIOBJ origHandle;
context = GetWindowDC(m_window);
if (context != NULL)
{
localContext = CreateCompatibleDC(context);
origHandle = SelectObject(localcontext,CreateCompatibleBitmap(context, GameboardInfo::BoardWidth, GameboardInfo::BoardHeight));
if (localContext != NULL)
{
if (BitBlt(localContext, 0, 0, GameboardInfo::BoardWidth, GameboardInfo::BoardHeight,
context, GameboardInfo::TopLeft.x, GameboardInfo::TopLeft.y, SRCCOPY))
{
ret = true;
// several calls to GetPixel which all return CLR_INVALID
}
SelectObject(localcontext, origHandle);
DeleteDC(localContext);
}
ReleaseDC(m_window, context);
}
return ret;
}