A guide to getting started with Windows graphics applications for the very first time. The Windows Graphics Device Interface (GDI) forms the basis of drawing lines and objects, and from this device contexts. I will not go into any detail about these concepts in this post. I just want to show a simple means of getting started with things like the drawing of lines and objects in Windows applications. There is nothing stopping you from reading further on the subject to increase your understanding.
(more…)
Tag: Device Context
-
Getting started with Windows GDI graphics applications in C++
-
‘Blitting’ a Bitmap Image to the Screen.
I recently needed to revisit this to create simple monochrome bitmaps representing the sets of nozzles turned off/on on a Xaar microarrayer printhead.
Sample code here. Essential steps are outlined in the following code
// 1. Create the uninitialized bitmap, that is compatible // with the the specified device context CPaintDC dc( this ); CBitmap bitmap; bitmap.CreateCompatibleBitmap( &dc, 20, 20 ); // 2. Create memory device context, that is compatible // with the specified device (dc in this case) CDC dcMem; dcMem.CreateCompatibleDC( &dc ); // 3. Obtain/create the bitmap and select into // the memory device context. CBrush brushblue( RGB( 0, 0, 255 ) ); CBrush brush( RGB( 0, 255, 255 ) ); CBitmap* pOldBitmap = dcMem.SelectObject( &bitmap ); dcMem.FillRect( CRect( 0, 0, 10, 10 ), &brushblue ); dcMem.FillRect( CRect( 10, 0, 20, 10 ), &brush ); dcMem.FillRect( CRect( 0, 10, 10, 20 ), &brush ); dcMem.FillRect( CRect( 10, 10, 20, 20 ), &brushblue ); // 4. Obtain the bitmap dimensions in pixels, making sure // they are then mapped into their corresponding logical // units BITMAP bm; bitmap.GetBitmap( &bm ); CPoint size( bm.bmWidth, bm.bmHeight ); CPoint org( 0, 0 ); dc.DPtoLP( &size ); dc.DPtoLP( &org ); // 5. Specify the memory device context’s mapping mode: // MM_ANISOTROPIC, MM_HIENGLISH etc dcMem.SetMapMode( dc.GetMapMode() ); // 6. ‘Blit’ the rectangular block of pixel data from // the source device context (dcMem) to the destination // device context (dc) dc.BitBlt( 12, 12, size.x, size.y, &dcMem, org.x, org.y, SRCCOPY ); // 7. Restore the default bitmap dcMem.SelectObject( pOldBitmap );A simple dialog application example to download: Bitmaps.zip