Only rename file extension!

Ever felt the need for renaming a file extension! Use PathRenameExtension. Does not verify the integrity of given path. Renames extension if there is one, else just appends given extension to given path. So if I give C:\System32 as path then the output will be C:\System32.doc. [sourcecode language=’cpp’]TCHAR szPath[MAX_PATH] = _T( “C:/nibu.txt” ); PathRenameExtension( szPath, […]
Continue reading…

 

How to unexpand environment variables in a string?

Ever felt the need for unexpanding expanded environment variables in a string… Use PathUnExpandEnvStrings. [sourcecode language=’cpp’]TCHAR szUnexpandedPath[MAX_PATH] = { 0 }; PathUnExpandEnvStrings( _T( “C:/windows/system32/” ), szUnexpandedPath, MAX_PATH ); wcout < < szUnexpandedPath;[/sourcecode] Output: %SystemRoot%/System32/
Continue reading…

 

Remove quotes from the beginning and end of a path

Use PathUnquoteSpaces. A sample from MSDN… [sourcecode language=’cpp’]#include #include #include “Shlwapi.h” void main( void ) { // Path to convert. char buffer_1[ ] = “”C:/path1/path2″”; char *lpStr1; lpStr1 = buffer_1; // Print the path before quotes are stripped. cout
Continue reading…

 

How to undecorate symbol names?

So what does decoration of symbols mean? Decoration of symbols take place to provide c++ polymorphism support. For e.g. if you have two functions [sourcecode language=’cpp’]void Add( int num1, int num2 ) void Add( float num1, float num2 )[/sourcecode] How does the compiler differentiate between the two? It creates a unique name for above functions […]
Continue reading…

 

Set and Get a DC’s pen color

Use SetDCPenColor for setting color of a DC’s pen and GetDCPenColor for retrieving a DC’s pen color. Here is an example from MSDN… [sourcecode language=’cpp’]SelectObject( hdc, GetStockObject( DC_PEN )); SetDCPenColor( hdc, RGB( 00, 0xff, 00 ); Rectangle( 0, 0, 20, 20 ); SetDCPenColor( hdc, RGB( 00, 00, 0xff )); Rectangle( 0, 0, 20, 20);[/sourcecode]
Continue reading…

 

Set and Get a DC’s Brush color

Use GetDCBrushColor for retrieving brush color of a dc and SetDCBrushColor for setting a DC’s brush color. Here is a sample from MSDN… [sourcecode language=’cpp’]SelectObject( hDC, GetStockObject( DC_BRUSH )); SetDCBrushColor( hDC,0x0 );[/sourcecode]
Continue reading…