So what are stock objects? “Stock” as the name says means goods in hand, which a shop keeper always has as a backup. In the same way GDI also keep a set of backup of objects which it creates during initialization and these are known as stock objects. Let’s think of a case like this… […]
Continue reading…
Posts tagged with 'GDI'
Making many drawing calls using just one API call!
Use Polyxxxx set of functions. Some of the functions that I know are listed below PolyPolyline PolyTextOut PolylineTo PolyDraw PolyBezier PolyBezierTo From MSDN: These functions exploit the fact that many drawing calls use identical attributes, and so multiple items can be drawn in a single call once the brushes, pens, colors, and fonts have been […]
Continue reading…
Retrieving current text color of a DC!
Use GetTextColor! Function signature is as follows… [sourcecode language=’cpp’] // MFC COLORREF GetTextColor() const; // SDK COLORREF GetTextColor( HDC hdc ); // handle to DC[/sourcecode]
Continue reading…
Retrieving face name of font selected into a DC!
Use GetTextFace function! Function signature is as follows… [sourcecode language=’cpp’] // MFC int GetTextFace( CString& rString ) const; // SDK int GetTextFace( HDC hdc, // handle to DC int nCount, //length of typeface name buffer LPTSTR lpFaceName // typeface name buffer );[/sourcecode]
Continue reading…
Retrieving graphics objects selected into a DC!
Felt the need to retrieve current brush or pen or palette selected into a DC? Sometime back a friend of mine asked me this question, as an answer I gave him a better solution, but the question was a valid one! So are there any windows api’s that helps us in the regard? Well the […]
Continue reading…
Type of GDI object!
To retrieve type of a HGDIOBJ object call GetObjectType. E.g. GetObjectType( hGdiObj ); Possible return values taken from MSDN… [sourcecode language=’cpp’]OBJ_BITMAP OBJ_BRUSH OBJ_COLORSPACE OBJ_DC OBJ_ENHMETADC OBJ_ENHMETAFILE OBJ_EXTPEN OBJ_FONT OBJ_MEMDC OBJ_METAFILE OBJ_METADC OBJ_PAL OBJ_PEN OBJ_REGION[/sourcecode]
Continue reading…
Drawing outlined text!
How to draw text like this! Looks interesting right! Well this is done using plain window’s GDI functions, here is a function which does this! [sourcecode language=’cpp’]// Thanks to Charles Petzold! void CCanvas::DrawOutlineText( CDC& dc, const CString& Text ) { const int RestorePoint = dc.SaveDC(); // Create new font CFont NewFont; NewFont.CreatePointFont( 700, TEXT( […]
Continue reading…
How to get color of a pixel from any Bitmap?
It’s easy to get color of a pixel from a bitmap. Here is a function which does this… [sourcecode language=’cpp’]#include #include // Returns Pixel color from bitmap COLORREF GetPixelValueFromBitmap( const int x, const int y, CBitmap& bmp ) { // DC for desktop CDC dcDesktop; dcDesktop.Attach( ::GetDC( GetDesktopWindow() )); // Create a DC compatible with […]
Continue reading…