Problem with gdi function

Hello,

I use attached function to paint a video frame. But on Windows7 and sometimes on Vista I get only 16 color images on the dialog, on XP it worked well. Maybe it only occour on 64bit.

Anybody has an idea why soemtimes only 16 colors are painted and not the full colors?

Ocrana
LRESULT CVideoWindow::OnUpdateVideoPicture(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	HBITMAP hBitmap = (HBITMAP)wParam;
	BITMAP btm;
	GetObject(hBitmap, sizeof(BITMAP), &btm);
	if(!m_hDC)
	{
		m_hDC = GetDC();
	}
	if(!m_hMemDC && m_hDC)
	{
		m_hMemDC = CreateCompatibleDC(m_hDC);
	}
		
	SelectObject(m_hMemDC, hBitmap);

	RECT rect; 
	GetClientRect(&rect); // rectangle for the primary surface

	if(btm.bmWidth < rect.right || btm.bmHeight < rect.bottom) SetStretchBltMode(m_hDC, COLORONCOLOR);
	else													   SetStretchBltMode(m_hDC, HALFTONE);

	StretchBlt(m_hDC, rect.left, 0, rect.right, rect.bottom, m_hMemDC, 0, 0, btm.bmWidth, btm.bmHeight, SRCCOPY);

	return 0;
}

Open in new window

OcranaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pgnatyukCommented:
I've answered in your second thread (didn't know that you opened this question).

m_hDC = GetDC(); // in the end of the function you need to call ReleaseDC.

m_hMemDC = CreateCompatibleDC(m_hDC); //in the end of the function you need to call DeleteDC

SelectObject(m_hMemDC, hBitmap); // ERROR. should be
HGDIOBJ hOld = SelectObject(m_hMemDC, hBitmap);
and in the end of the function, before these two lines you should select this hOld.

So in the end of the function you have to add something like that:
SelectObject(m_hMemDC, hOld);
DeleteDC(m_hMemDC);
ReleaseDC(m_hDC);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.