Share via


MTGDI

ms959878(v=msdn.10).md ms959948(v=msdn.10).md ms960020(v=msdn.10).md ms960342(v=msdn.10).md ms915404(v=msdn.10).md ms961483(v=msdn.10).md ms915517(v=msdn.10).md

The MTGDI sample is a demonstration of sharing GDI resources among multiple threads using the framework's single document interface (SDI) support for documents and views.

You can use the menu to add 1, 10, or 25 new threads at a time. Each thread displays either a moving ball, rectangle, or line in a random color.

MTGDI uses a set of CWinThread-derived classes, all of which are implemented in THREADS.CPP. The sample's own CGDIThread is the virtual base class for each of these GDI thread classes (one each for balls, rectangles, and lines). Since GDI resources cannot be shared among threads as MFC objects, this sample also demonstrates how to convert from standard GDI resources to MFC objects and back.

The application creates the desired number of threads when you add new objects to those being displayed by the Thread menu. Each new object displayed is handled in its own thread. Any number of threads can be added to those already in progress.

The threads are shut down all at once from the Thread **** menu, but you have a choice between whether this shutdown is done slowly or quickly. If there are fewer than 100 threads, it is difficult to tell the difference in speed between these two methods for MTGDI.

This sample demonstrates the following keywords:

CArchive::IsStoring CRect::SetRect
CDC::Attach CSingleLock::Unlock
CDC::Detach CString::Format
CDC::Ellipse CString::LoadString
CDC::GetSafeHdc CWinApp::AddDocTemplate
CDC::LineTo CWinApp::OnFileNew
CDC::MoveTo CWinThread::CreateThread
CDC::Rectangle CWinThread::ResumeThread
CDC::SelectObject CWinThread::SetThreadPriority
CDialog::DoModal CWnd::GetClientRect
CGDIObject::Attach CWnd::Invalidate
CGDIObject::Detach CWnd::SetWindowText
CList::AddTail
CList::GetCount
CList::GetHeadPosition
CList::GetNext
CList::IsEmpty
CList::RemoveHead
CObject::AssertValid
CObject::Dump
CRect::OffsetRect