Problem with gdi function

Posted on 2010-04-01
Medium Priority
Last Modified: 2013-11-20

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?

LRESULT CVideoWindow::OnUpdateVideoPicture(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	HBITMAP hBitmap = (HBITMAP)wParam;
	BITMAP btm;
	GetObject(hBitmap, sizeof(BITMAP), &btm);
		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

Question by:Ocrana
1 Comment
LVL 33

Accepted Solution

pgnatyuk earned 2000 total points
ID: 29430334
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);

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

592 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question