Enabling broadcast option on a socket!

In order to enable broadcasting option on a socket you’ve got to enable it via a call to setsockopt with optname set to SO_BROADCAST and level set to SOL_SOCKET! Here is a function which does this! [sourcecode language=’cpp’]bool SetBroadcastOn( const bool Enable ) {     const BOOL bEnable = Enable;     if( setsockopt( sckHandle,                     […]
Continue reading…

 

Charizing operator (Microsoft specific)!

You’ve heard of stringizing pre-processor operators, ever heard of charizing operators? Very similar to stringizing operators, except that it puts single quotes around it’s arguments, that’s why it’s called the charizing operator! For stringizing we use “#” operator but for charizing we use “#@”. Here is an e.g. From MSDN: [sourcecode language=’cpp’]#define MakeChar( ch ) […]
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…

 

Careful with memset and ZeroMemory!

Do not use these functions for initializing classes which contains other class objects. Always go via constructors for initializing class objects. I personally use { 0 } for initializing c-style structures which is safe since compiler will give an error just in case future someone adds a class object to this structure. For e.g. [sourcecode […]
Continue reading…

 

Making a property sheet window resizable!

Sometime back my boss asked me to write a test application for a layout manager. This test application was for testing layout manager on a property sheet! Hmm so property sheet cannot be resized even if you modify the style of a property sheet. Well the reason why it can’t be resized is because SC_SIZE […]
Continue reading…

 

DLL Best Practices

Following information taken from this document maintained by microsoft! An important excerpt from this document! DllMain is called while the loader-lock is held. Therefore, significant restrictions are imposed on the functions that can be called within DllMain. As such, DllMain is designed to perform minimal initialization tasks, by using a small subset of the Microsoft® […]
Continue reading…

 

Retrieve work area rectangle using SystemParametersInfo!

Work area is that area of the screen excluding windows task bars and other custom application bars. Simplest way to retrieve this area is to call SystemParametersInfo. Here is an e.g. [sourcecode language=’cpp’]RECT rcWorkArea = { 0 }; SystemParametersInfo( SPI_GETWORKAREA, 0, &rcWorkArea, 0 ); AfxTrace( _T( “Work area: %d, %d, %d, %d” ), rcWorkArea.left, rcWorkArea.top, […]
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…

 

Using PS_USERSTYLE for creating funky pens!

Using ExtCreatePen and PS_USERSTYLE you can create funky styled pens instead of the old PS_DOT, PS_DASHDOT, PS_DASHDOTDOT style pens. When using PS_USERSTYLE for creating pens you’ve got specify an array of DWORD which holds dash and space length while drawing a user styled pen! I’ve created a sample application which demostrates marching ants demo, if […]
Continue reading…