<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Reflections of my thoughts... &#187; Visual Studio</title>
	<atom:link href="http://codereflect.com/category/visual-studio/feed/" rel="self" type="application/rss+xml" />
	<link>http://codereflect.com</link>
	<description>on programming tips and trending topics...</description>
	<lastBuildDate>Wed, 08 Feb 2012 08:58:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Graphics Debugging in Visual Studio 2011</title>
		<link>http://codereflect.com/2011/11/09/graphics-debugging-in-visual-studio-2011/</link>
		<comments>http://codereflect.com/2011/11/09/graphics-debugging-in-visual-studio-2011/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 17:35:49 +0000</pubDate>
		<dc:creator>@sarat</dc:creator>
				<category><![CDATA[direct2D]]></category>
		<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[Visual Studio 2011]]></category>
		<category><![CDATA[D2D]]></category>
		<category><![CDATA[D3D]]></category>
		<category><![CDATA[links]]></category>

		<guid isPermaLink="false">http://codereflect.com/?p=1776</guid>
		<description><![CDATA[Metro style games and graphics-intensive apps present a huge opportunity for developers on new devices such as tablets. The primary API for accessing the full power of the underlying graphics hardware on Windows is DirectX 11 (including Direct3D and Direct2D). One of the most significant innovations we have brought to Visual Studio 11 is a series of tools for assisting [...]]]></description>
			<content:encoded><![CDATA[<p>Metro style games and graphics-intensive apps present a huge opportunity for developers on new devices such as tablets. The primary API for accessing the full power of the underlying graphics hardware on Windows is <strong>DirectX 11</strong> (including <strong>Direct3D</strong> and <strong>Direct2D</strong>).</p>
<p>One of the most significant innovations we have brought to Visual Studio 11 is a series of tools for assisting you in developing Direct3D games. We made a quick video of some of these features on Channel9 (<a href="http://channel9.msdn.com/posts/Visual-Studio-vNext-DirectX-11-Development-Experience" target="_blank">link</a>). In this post, I will walk through our debugging &amp; diagnostics support for D3D.</p>
<p>The new <strong>Graphics Debugger</strong> in Visual Studio is a debugging and analysis tool that captures detailed information from a Direct3D application as it executes. You can use it to:</p>
<ul>
<li>Capture rendered frames for later inspection and analysis.</li>
<li>View DirectX events and their effects on the application.</li>
<li>View 3D meshes before and after vertex shader transformations.</li>
<li>Discover which DirectX events contribute to the color of a specific pixel.</li>
<li>Jump directly to the location in source code for a particular DirectX call</li>
</ul>
<div><strong><a href="http://blogs.msdn.com/b/vcblog/archive/2011/11/08/10235150.aspx" target="_blank">Read more from Visual C++ Team Blog </a></strong></div>
<div><img class="alignnone" src="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-65-69-metablogapi/7713.image27_5F00_thumb_5F00_210F27F9.png" alt="" width="644" height="370" /></div>
]]></content:encoded>
			<wfw:commentRss>http://codereflect.com/2011/11/09/graphics-debugging-in-visual-studio-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to check Visual Studio 2008 Service Pack 1 is installed?</title>
		<link>http://codereflect.com/2011/09/06/how-to-check-visual-studio-2008-service-pack-1-is-installed/</link>
		<comments>http://codereflect.com/2011/09/06/how-to-check-visual-studio-2008-service-pack-1-is-installed/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 07:29:49 +0000</pubDate>
		<dc:creator>@sarat</dc:creator>
				<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[sp1]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://codereflect.com/?p=1705</guid>
		<description><![CDATA[Take Help->About Visual Studio See if KB945140 has installed or not. Alternatively you can click on Copy Info button and paste entire information about Installed Product to a text editor and do search for the corresponding KB]]></description>
			<content:encoded><![CDATA[<p>Take <code>Help->About Visual Studio</code><br />
See if <a href="http://support.microsoft.com/kb/945140" target="_blank">KB945140 </a> has installed or not.</p>
<p>
<a href="http://codereflect.com/assets/VSABOUT.png"><img src="http://codereflect.com/assets/VSABOUT.png" alt="" title="VSABOUT" width="650" height="501" class="alignnone size-full wp-image-1706" /></a>
</p>
<p>Alternatively you can click on <code>Copy Info</code> button and paste entire information about <code>Installed Product</code> to a text editor and do search for the corresponding KB</p>
]]></content:encoded>
			<wfw:commentRss>http://codereflect.com/2011/09/06/how-to-check-visual-studio-2008-service-pack-1-is-installed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The case of Visual Studio 2008 SP1 crash on Docking/Undocking and Switching from Debugging to Design View</title>
		<link>http://codereflect.com/2011/08/12/the-case-of-visual-studio-2008-sp1-crash-on-dockingundocking-and-switching-from-debugging-to-design-view/</link>
		<comments>http://codereflect.com/2011/08/12/the-case-of-visual-studio-2008-sp1-crash-on-dockingundocking-and-switching-from-debugging-to-design-view/#comments</comments>
		<pubDate>Fri, 12 Aug 2011 06:01:27 +0000</pubDate>
		<dc:creator>@sarat</dc:creator>
				<category><![CDATA[Crashes]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[WinDBG]]></category>
		<category><![CDATA[crashes]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://codereflect.com/?p=1657</guid>
		<description><![CDATA[I&#8217;m using dual monitors with my laptop and I found that Visual Studio is crashing on docking/undocking window to/from other display. Although I am not do the same operation it was crashing again on switching back to design/code view from debugging. I&#8217;m primary using IBM Clearcase as versioninig system and I have n number of [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m using dual monitors with my laptop and I found that Visual Studio is crashing on docking/undocking window to/from other display. Although I am not do the same operation it was crashing again on switching back to design/code view from debugging. </p>
<p>I&#8217;m primary using IBM Clearcase as versioninig system and I have n number of issues ever since I started using with Windows 7. The same issue happened though I copied my source to local folder and debugging from there.</p>
<p>Simply took the dump and attached to WinDBG. <code>!analyze -v</code> had given me following call stack</p>
<pre>
EXCEPTION_RECORD:  002ad92c -- (.exr 0x2ad92c)
ExceptionAddress: 3fe083d0
   ExceptionCode: c0000005 (Access violation)
  ExceptionFlags: 00000000
NumberParameters: 2
   Parameter[0]: 00000008
   Parameter[1]: 3fe083d0
Attempt to execute non-executable address 3fe083d0

FAULTING_THREAD:  00002718

DEFAULT_BUCKET_ID:  SILENT

PROCESS_NAME:  devenv.exe

ERROR_CODE: (NTSTATUS) 0x80000003 - {EXCEPTION}  Breakpoint  A breakpoint has been reached.

EXCEPTION_CODE: (HRESULT) 0x80000003 (2147483651) - One or more arguments are invalid

NTGLOBALFLAG:  400

APPLICATION_VERIFIER_FLAGS:  0

MANAGED_STACK: !dumpstack -EE
OS Thread Id: 0x2718 (0)
Current frame:
ChildEBP RetAddr  Caller,Callee
002af168 71bc5a99 (MethodDesc 0x714cc250 +0x79 System.Collections.Generic.Dictionary`2+ValueCollection+Enumerator[[System.Int32, mscorlib],[System.__Canon, mscorlib]].MoveNext())

CONTEXT:  002ad948 -- (.cxr 0x2ad948)
eax=59730146 ebx=00000000 ecx=01a72c50 edx=0000001d esi=01a72c50 edi=01a729c8
eip=3fe083d0 esp=002adc2c ebp=002adeb0 iopl=0         nv up ei ng nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010286
3fe083d0 ??              ???
Resetting default scope

WRITE_ADDRESS:  3fe083d0 

FOLLOWUP_IP:
msenv!CDockManager::PruneAllDeadPanes+45
5986cbf6 e97745f8ff      jmp     msenv!CDockManager::PruneAllDeadPanes+0x45 (597f1172)

FAILED_INSTRUCTION_ADDRESS:
+5789952f04fedcac
3fe083d0 ??              ???

PRIMARY_PROBLEM_CLASS:  SILENT

BUGCHECK_STR:  APPLICATION_FAULT_SILENT

LAST_CONTROL_TRANSFER:  from 5986cbf6 to 3fe083d0

IP_ON_HEAP:  3fe083d0
The fault address in not in any loaded module, please check your build's rebase
log at <releasedir>\bin\build_logs\timebuild\ntrebase.log for module which may
contain the address if it were loaded.

IP_IN_FREE_BLOCK: 3fe083d0

STACK_TEXT:
3fe083d0 unknown+0x0
5986cbf6 msenv!CDockManager::PruneAllDeadPanes+0x45
597eef9b msenv!CDockManager::SaveUI+0xb7
598122a5 msenv!CPane::TransitionToDesign+0x46
597f67a9 msenv!CVsShellDebugMgr::m_OnModeChange+0xe6
5976aca3 msenv!CVsUIShell::OnModeChange+0x21
5f4dbfa3 vsdebug!CDebugger::SetShellMode+0x9b
5f4dc04f vsdebug!CDebugger::OnModeChange+0x44
5f4dbeef vsdebug!CDebugger::SetDebugMode+0x69
5f4f2c93 vsdebug!CDebugger::OnExitBreakState+0xaa
5f53cab1 vsdebug!CDebugger::OnDebuggingStopped+0x6e
5f51bcb6 vsdebug!CDebugger::HandleEvent+0x8ae
5f4dbc19 vsdebug!CDebugger::Event+0xef
5f4dbaef vsdebug!sdm::CDebugManager::HandleEvent+0xb5
75eefc8f rpcrt4!Invoke+0x2a
75f54c53 rpcrt4!NdrStubCall2+0x2d6
75e9d936 ole32!CStdStubBuffer_Invoke+0xb6
75e9d9c6 ole32!SyncStubInvoke+0x3c
75e9df1f ole32!StubInvoke+0xb9
75db223c ole32!CCtxComChnl::ContextInvoke+0xfa
75db2131 ole32!MTAInvoke+0x1a
75db30fa ole32!STAInvoke+0x46
75e9de47 ole32!AppInvoke+0xab
75e9dcbb ole32!ComInvokeWithLockAndIPID+0x372
75e9e34c ole32!ComInvoke+0xc5
75db2ed2 ole32!ThreadDispatch+0x23
75db2e91 ole32!ThreadWndProc+0x161
762986ef user32!InternalCallWinProc+0x23
76298876 user32!UserCallWinProcCheckWow+0x14b
762989b5 user32!DispatchMessageWorker+0x35e
76298e9c user32!DispatchMessageW+0xf
75d7d6be ole32!CCliModalLoop::PeekRPCAndDDEMessage+0x4c
75d7d66d ole32!CCliModalLoop::FindMessage+0x30
75d7d57e ole32!CCliModalLoop::HandleWakeForMsg+0x41
75d7d633 ole32!CCliModalLoop::BlockFn+0xc3
75d71117 ole32!CoWaitForMultipleHandles+0xcd
5f513ed6 vsdebug!sdm::CDebugManager::WaitForEvent+0x8a
5f526aa0 vsdebug!CDebugger::WaitForDebuggingToStop+0x51
5f526fed vsdebug!CDebugger::TerminateSession+0x106
5f52711a vsdebug!CDebugger::StopDebugging+0x10a
5f4e8014 vsdebug!CVSDebugPackage::Exec+0x5f9
5974249f msenv!CVSCommandTarget::ExecCmd+0x937
59884617 msenv!FTranslateAcceleratorEx+0x4a3
597581c3 msenv!FTranslateAccelerator+0x49
59758045 msenv!MainFTranslateMessage+0x1a7
59757f2b msenv!CMsoComponent::FPreTranslateMessage+0x72
59757ec0 msenv!SCM_MsoStdCompMgr::FPreTranslateMessage+0xdd
5974152c msenv!EnvironmentMsgLoop+0x159
597fb9bd msenv!CMsoCMHandler::FPushMessageLoop+0x86
597fb94d msenv!SCM::FPushMessageLoop+0xb7
597fb8e9 msenv!SCM_MsoCompMgr::FPushMessageLoop+0x28
597fb8b8 msenv!CMsoComponent::PushMsgLoop+0x28
597fbe4e msenv!VStudioMainLogged+0x482
597f7561 msenv!VStudioMain+0xc1
2f6aaabc devenv!util_CallVsMain+0xff
2f6a78f2 devenv!CDevEnvAppId::Run+0x11fd
2f6a7bf4 devenv!WinMain+0x74
2f6a7c68 devenv!License::GetPID+0x258
765a1114 kernel32!BaseThreadInitThunk+0xe
7791b429 ntdll!__RtlUserThreadStart+0x70
7791b3fc ntdll!_RtlUserThreadStart+0x1b

SYMBOL_STACK_INDEX:  1

SYMBOL_NAME:  msenv!CDockManager::PruneAllDeadPanes+45

FOLLOWUP_NAME:  MachineOwner

MODULE_NAME: msenv

IMAGE_NAME:  msenv.dll

DEBUG_FLR_IMAGE_TIMESTAMP:  488f2b9f

STACK_COMMAND:  .cxr 002AD948 ; kb ; dds 2adc2c ; kb

FAILURE_BUCKET_ID:  SILENT_80000003_msenv.dll!CDockManager::PruneAllDeadPanes

BUCKET_ID:  APPLICATION_FAULT_SILENT_BAD_IP_msenv!CDockManager::PruneAllDeadPanes+45

WATSON_STAGEONE_URL:  http://watson.microsoft.com/StageOne/devenv_exe/9_0_30729_1/488f2b50/unknown/0_0_0_0/bbbbbbb4/80000003/00000000.htm?Retriage=1

Followup: MachineOwner
---------
</pre>
<p>Luckily a Google search with the call stack has returneda single relevant result about this issue in Microsoft Connect.</p>
<p><a href="http://connect.microsoft.com/VisualStudio/feedback/details/373507/visual-studio-2008-ide-crashes-returning-to-design-mode-when-stopping-debugging-native-c-code" target="_blank">Visual Studio 2008 IDE Crashes Returning to Design Mode When Stopping Debugging Native C++ Code</a></p>
<p>Microsoft has released a patch to resolve this issue. <a href="http://archive.msdn.microsoft.com/KB960075" target="_blank">Download</a></p>
]]></content:encoded>
			<wfw:commentRss>http://codereflect.com/2011/08/12/the-case-of-visual-studio-2008-sp1-crash-on-dockingundocking-and-switching-from-debugging-to-design-view/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to resolve Visual Studio warning &#8220;The project location is not trusted&#8221; on mapped network drives?</title>
		<link>http://codereflect.com/2011/08/03/how-to-resolve-visual-studio-warning-the-project-location-is-not-trusted-on-mapped-network-drives/</link>
		<comments>http://codereflect.com/2011/08/03/how-to-resolve-visual-studio-warning-the-project-location-is-not-trusted-on-mapped-network-drives/#comments</comments>
		<pubDate>Wed, 03 Aug 2011 05:34:01 +0000</pubDate>
		<dc:creator>@sarat</dc:creator>
				<category><![CDATA[Clearcase]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[caspol]]></category>
		<category><![CDATA[clearcase]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Security settings]]></category>
		<category><![CDATA[troubleshooting]]></category>

		<guid isPermaLink="false">http://codereflect.com/?p=1649</guid>
		<description><![CDATA[You might have seen the above warning when you open a Visual Studio solution on a mapped network drive. This especially appears when you work with clearcase mapped network drives. Find for caspol.exe in your Windows\Microsoft.NET\Framework folder. C:\Windows\Microsoft.NET\Framework\v2.0.50727\CasPol.exe -m -pp off -cg 1.2 FullTrust This will grant full trust to local intranet code group. Note [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://codereflect.com/assets/Untrusted.png"><img src="http://codereflect.com/assets/Untrusted.png" alt="" title="Untrusted Project Location" width="492" height="263" class="alignnone size-full wp-image-1650" /></a></p>
<p>You might have seen the above warning when you open a Visual Studio solution on a mapped network drive. This especially appears when you work with clearcase mapped network drives. </p>
<p>Find for <a href="http://msdn.microsoft.com/en-us/library/cb6t8dtz%28v=vs.80%29.aspx">caspol.exe </a>in your Windows\Microsoft.NET\Framework folder.</p>
<pre>C:\Windows\Microsoft.NET\Framework\v2.0.50727\CasPol.exe -m -pp off -cg 1.2 FullTrust</pre>
<p>This will grant full trust to local intranet code group. Note that caspol tool will apply the security settings for 3.0, 3.5 as well though it&#8217;s coming with .NET 2.0</p>
]]></content:encoded>
			<wfw:commentRss>http://codereflect.com/2011/08/03/how-to-resolve-visual-studio-warning-the-project-location-is-not-trusted-on-mapped-network-drives/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to save Icon as bitmap?</title>
		<link>http://codereflect.com/2011/05/05/how-to-save-icon-as-bitmap/</link>
		<comments>http://codereflect.com/2011/05/05/how-to-save-icon-as-bitmap/#comments</comments>
		<pubDate>Thu, 05 May 2011 12:06:55 +0000</pubDate>
		<dc:creator>@sarat</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[bitmap]]></category>
		<category><![CDATA[icon]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[tweak]]></category>

		<guid isPermaLink="false">http://codereflect.com/?p=1428</guid>
		<description><![CDATA[Icons are being a bit mysterious comparing to bitmaps. Now how we can save and icon to bitmap. There are several methods to do this. Here&#8217;s a simple tweak to save it using memory DC. void SaveBitmapToFile( BYTE* pBitmapBits, LONG lWidth, LONG lHeight,WORD wBitsPerPixel, LPCTSTR lpszFileName ) { BITMAPINFOHEADER bmpInfoHeader = {0}; // Set the [...]]]></description>
			<content:encoded><![CDATA[<p>Icons are being a bit mysterious comparing to bitmaps. Now how we can save and icon to bitmap. There are several methods to do this. Here&#8217;s a simple tweak to save it using memory DC.</p>
<pre>
void SaveBitmapToFile( BYTE* pBitmapBits, LONG lWidth, LONG lHeight,WORD wBitsPerPixel, LPCTSTR lpszFileName )
{
    BITMAPINFOHEADER bmpInfoHeader = {0};
    // Set the size
    bmpInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
    // Bit count
    bmpInfoHeader.biBitCount = wBitsPerPixel;
    // Use all colors
    bmpInfoHeader.biClrImportant = 0;
    // Use as many colors according to bits per pixel
    bmpInfoHeader.biClrUsed = 0;
    // Store as un Compressed
    bmpInfoHeader.biCompression = BI_RGB;
    // Set the height in pixels
    bmpInfoHeader.biHeight = lHeight;
    // Width of the Image in pixels
    bmpInfoHeader.biWidth = lWidth;
    // Default number of planes
    bmpInfoHeader.biPlanes = 1;
    // Calculate the image size in bytes
    bmpInfoHeader.biSizeImage = lWidth* lHeight * (wBitsPerPixel/8);

    BITMAPFILEHEADER bfh = {0};
    // This value should be values of BM letters i.e 0x4D42
    // 0x4D = M 0×42 = B storing in reverse order to match with endian
    bfh.bfType=0x4D42;
    /* or
    bfh.bfType = ‘B’+(‘M’ &lt;&lt; 8);
    // &lt;&lt;8 used to shift ‘M’ to end
    */
    // Offset to the RGBQUAD
    bfh.bfOffBits = sizeof(BITMAPINFOHEADER) + sizeof(BITMAPFILEHEADER);
    // Total size of image including size of headers
    bfh.bfSize = bfh.bfOffBits + bmpInfoHeader.biSizeImage;
    // Create the file in disk to write
    HANDLE hFile = CreateFile( lpszFileName,GENERIC_WRITE, 0,NULL,

                               CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);

    if( !hFile ) // return if error opening file
    {
        return;
    }

    DWORD dwWritten = 0;
    // Write the File header
    WriteFile( hFile, &amp;bfh, sizeof(bfh), &amp;dwWritten , NULL );
    // Write the bitmap info header
    WriteFile( hFile, &amp;bmpInfoHeader, sizeof(bmpInfoHeader), &amp;dwWritten, NULL );
    // Write the RGB Data
    WriteFile( hFile, pBitmapBits, bmpInfoHeader.biSizeImage, &amp;dwWritten, NULL );
    // Close the file handle
    CloseHandle( hFile );
}

void CLoadIconSampleDlg::OnBnClickedButtonSaveIcon()
{
	// Loading resource from DLL.
	HMODULE h = LoadLibrary( L&quot;myresource.dll&quot; );

	if( !h )
	{
		MessageBox( L&quot;Failed to load library&quot; );
		return;
	}

	INT id = GetDlgItemInt( IDC_EDIT1 );
	m_hLoadedIcon = LoadIcon( (HINSTANCE) h , MAKEINTRESOURCE( id ) );

	CBitmap bmpSave;
	CClientDC dc(this);
	bmpSave.CreateCompatibleBitmap( &amp;dc, 32, 32 );

	CDC dcMem;
	dcMem.CreateCompatibleDC( &amp;dc );
	dcMem.SelectObject( &amp;bmpSave );
	dcMem.DrawIcon( 0, 0, m_hLoadedIcon );

	BITMAP bmpInfo;
	bmpSave.GetBitmap( &amp;bmpInfo );

	int size = bmpInfo.bmHeight* bmpInfo.bmWidth * (bmpInfo.bmBitsPixel / 8 );
	unsigned char* pBytes = new unsigned char[size];
	bmpSave.GetBitmapBits( size, pBytes );
	SaveBitmapToFile( pBytes, 32, 32, bmpInfo.bmBitsPixel, _T( &quot;C:\\temp\\temp.bmp&quot; ));
	delete []pBytes;

	FreeLibrary( h );
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://codereflect.com/2011/05/05/how-to-save-icon-as-bitmap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>const to data and pointer</title>
		<link>http://codereflect.com/2011/02/23/const-to-data-and-pointer/</link>
		<comments>http://codereflect.com/2011/02/23/const-to-data-and-pointer/#comments</comments>
		<pubDate>Wed, 23 Feb 2011 08:57:52 +0000</pubDate>
		<dc:creator>@sarat</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>

		<guid isPermaLink="false">http://codereflect.com/?p=1424</guid>
		<description><![CDATA[This is a fundamental thing that every C++ programmers must know. const to data This is the simplest form of pointer definition that we always do. const int* data3 = arr2; // Const to data data3[0] = 55;  // ERROR: Data can't be changed data3 = arr1;    // Success:  Can't change the pointer to somewhere [...]]]></description>
			<content:encoded><![CDATA[<p>This is a fundamental thing that every C++ programmers must know.</p>
<h2>const to data</h2>
<p>This is the simplest form of pointer definition that we always do.</p>
<pre>
const int* data3 = arr2; // Const to data
data3[0] = 55;  // ERROR: Data can't be changed
data3 = arr1;    // Success:  Can't change the pointer to somewhere else
</pre>
<p>Here the data is can’t changed using data3 pointer. but the pointer itself can be modified and can point to some other location.</p>
<p>Usually  we don’t care even if pass the pointer to some function and that  pointer changes to some other location, as the function parameters  points to same location but the pointer is a copy of actual parameter.  But things may go different if we wrongly pass reference to function  parameters even it’s const. So we’ve to take care this while designing  the interfaces.</p>
<pre>
void Foo(  LPCTSTR&amp; lpszValue )
{
	lpszValue = _T( &quot;codereflect.com&quot; );
}

int _tmain(int argc, _TCHAR* argv[])
{
	LPCTSTR sz = NULL;
	Foo(sz);
	_tprintf( sz );
	return 0;
}
</pre>
<h2>const to pointer</h2>
<p>In this form of usage, the pointer can’t be changed to some location but the data can be changed.</p>
<pre>
int* const data2 = arr2; // const to pointer
data2 = arr1;    // Can't change the pointer to somewhere else
data2[0] = 55;  // SUCCESS: Data can be changed
</pre>
<h2>const to both data and pointer</h2>
<p>This is the goodness of both <img src='http://codereflect.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . The most secure pointer.</p>
<pre>
const int* const data1 = arr1; // Const to both pointer and data
data1 = arr2;    // ERROR: can't change the pointer
data1[0] = 100; // ERROR: can't change the data
</pre>
]]></content:encoded>
			<wfw:commentRss>http://codereflect.com/2011/02/23/const-to-data-and-pointer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to restrict Window Movement?</title>
		<link>http://codereflect.com/2010/09/16/how-to-restrict-window-movement/</link>
		<comments>http://codereflect.com/2010/09/16/how-to-restrict-window-movement/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 14:44:36 +0000</pubDate>
		<dc:creator>@sarat</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[MFC]]></category>
		<category><![CDATA[Win32]]></category>
		<category><![CDATA[Windows Vista]]></category>
		<category><![CDATA[Windows XP]]></category>

		<guid isPermaLink="false">http://codereflect.com/2010/09/16/how-to-restrict-window-movement/</guid>
		<description><![CDATA[This is beginner level post. How we can make a Window immovable? Roughly we’ve two methods to do this. Method #1. Handle the NCHITTEST message and ignore while user click on the caption area (Titlebar). This method doesn’t work well in Windows 7/Vista if Aero is enabled. This method works with any type of Window [...]]]></description>
			<content:encoded><![CDATA[<p>This is beginner level post. How we can make a Window immovable?</p>
<p>Roughly we’ve two methods to do this.</p>
<p><strong>Method #1</strong>. Handle the NCHITTEST message and ignore while user click on the caption area (Titlebar). This method doesn’t work well in Windows 7/Vista if Aero is enabled. This method works with any type of Window having titlebar. The disadvantage of this method is , the user will still able to move using keyboard, if system menu is available.</p>
<p>&#160;</p>
<pre>
LRESULT CMoveWindowSampleDlg::OnNcHitTest(CPoint point)
{
    UINT nHitTest = CDialogEx::OnNcHitTest(point);

    if( HTCAPTION == nHitTest )
        nHitTest = HTNOWHERE;

    return nHitTest;
}</pre>
<p><strong>Method #2</strong> – Remove the Move command from System Menu (Works with windows having system menu stle (WS_SYSMENU) ). The the Move command in the system menu will be removed in this case. Windows will internally disable the movement of this kind of Windows. </p>
<pre>
BOOL CMoveWindowSampleDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();

    CMenu* pSysMenu = GetSystemMenu(FALSE);

    if (pSysMenu != NULL)
    {
        pSysMenu-&gt;RemoveMenu( SC_MOVE, MF_BYCOMMAND );
       }
...

       return TRUE;
}
</pre>
<p>PS: Using method 2, this is the same method we use to disable the close button of a Window. For disabling a menu/titlebar button. Call EnableMenu function with relevant parameters.</p>
]]></content:encoded>
			<wfw:commentRss>http://codereflect.com/2010/09/16/how-to-restrict-window-movement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Studio 2010 &#8211; Productivity tools</title>
		<link>http://codereflect.com/2010/08/11/visual-studio-2010-productivity-tools/</link>
		<comments>http://codereflect.com/2010/08/11/visual-studio-2010-productivity-tools/#comments</comments>
		<pubDate>Wed, 11 Aug 2010 17:22:25 +0000</pubDate>
		<dc:creator>@sarat</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C Sharp]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[Extensibility]]></category>
		<category><![CDATA[Productivity Tools]]></category>

		<guid isPermaLink="false">http://codereflect.com/2010/08/11/visual-studio-2010-productivity-tools/</guid>
		<description><![CDATA[Most of the Visual Studio Developers are familiar with Visual Assist X developer tool. It has really nifty features for improving the productivity. It may not be too detailed refactoring facilities or so flexible features as other tools provides like DevExpress but as a whole all we like this tool. But only one problem, it’s [...]]]></description>
			<content:encoded><![CDATA[<p>Most of the Visual Studio Developers are familiar with Visual Assist X developer tool. It has really nifty features for improving the productivity. It may not be too detailed refactoring facilities or so flexible features as other tools provides like DevExpress but as a whole all we like this tool. But only one problem, it’s a paid software.</p>
<p>Visual Studio IDE is consistently getting improved over the versions but still some of the feature are missing like Symbol Search, file search within the IDE until Visual Studio 2010. It’s really important while managing large projects. The best thing in the Visual Studio 2010, is the <a href="http://msdn.microsoft.com/en-us/vstudio/vextend.aspx" target="_blank">extensibility SDK</a>. It’s far more flexible and prominent comparing to it’s predecessors.</p>
<p>Microsoft has created a really helpful site to host the useful tools for Visual Studio created by developers across the world. Even Microsoft has created some really cool tools for Visual Studio which is freely available in <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/" target="_blank">Visual Studio Gallery</a>.</p>
<p>Productivity tools are one of best extensions available. It contains a bunch of features to improve your Visual Studio 2010 experience. You can download it from <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/d0d33361-18e2-46c0-8ff2-4adea1e34fef?SRC=Home" target="_blank">Visual Studio Gallery</a>. The features can be simply enabled and disabled through Tools-&gt;Option menu.</p>
<p><a href="http://codereflect.com/wp-content/uploads/2010/08/image.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://codereflect.com/wp-content/uploads/2010/08/image_thumb.png" width="619" height="360" /></a> </p>
<p>Let’s have a quick look into the features. Each options are described well in their home page itself. Let’s skim through the features anyway. This contains only the features I handpicked from the whole features available. You can see the entire features the home page itself. The descriptions and screenshots are given same as the extension&#8217;s homepage.</p>
<p><strong>Solution Navigator</strong><strong>&#160; (<a href="http://blogs.msdn.com/b/visualstudio/archive/2010/07/20/solution-navigator-blog-post.aspx">More Info</a>)</strong></p>
<p><a href="http://codereflect.com/wp-content/uploads/2010/08/image1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://codereflect.com/wp-content/uploads/2010/08/image_thumb1.png" width="341" height="430" /></a> </p>
<p>This is one of the best feature.</p>
<ul>
<li>Expand code files to navigate to its classes, expand classes to navigate to their members, and so on (C# and VB only) </li>
<li>Search your solution, all the way down to class members </li>
<li>Filter your solution or projects to see just opened files, unsaved files, and so on </li>
<li>View related information about classes and members (such as references or callers/callees for C#) </li>
<li>Preview images by hovering over them, or preview rich information by hovering over code item</li>
</ul>
<p>Solution Navigator also provides interactive tooltips in C# and VB code (replacing the default “quick info” tooltips) that give you the same kind of data, but right at your fingertips.&#160; In addition to getting the tooltips on hover, you can: </p>
<ul>
<li>Press Ctrl+1 to open a relevant tooltip at the current cursor location </li>
<li>Press Ctrl+2 to quickly navigate to any class/member in the current source file</li>
</ul>
<p><strong></strong></p>
<p><strong>Ctrl + Click Go To Definition</strong>    <br />This extension gives the editor a web browser by adding clickable hyperlinks to symbols in your code as you hold down the Ctrl key.</p>
<p><strong>Align Assignments</strong>    <br />This extension is useful for making your code a little more readable by aligning the assignments when you type Ctrl+Alt+] such that it takes this:    <br /><img alt="" src="http://i3.visualstudiogallery.msdn.microsoft.com/en-us/d0d33361-18e2-46c0-8ff2-4adea1e34fef/image/file/32145/0/align1.bmp" width="224" height="89" />    <br />And turns it into this:    <br /><img alt="" src="http://i1.visualstudiogallery.msdn.microsoft.com/en-us/d0d33361-18e2-46c0-8ff2-4adea1e34fef/image/file/32146/0/align2.bmp" width="235" height="84" />    <br /><em>Please note:</em> This may conflict with your formatting settings. E.g. in C# you will need to disable: Tools-&gt;Options-&gt;Text Editor-&gt;C#-&gt;Formatting-&gt;Spacing-&gt;&quot;Ignore spaces in declaration statements&quot;</p>
<p><strong>Triple Click</strong>    <br />It’s never been easier to select a line of code from the mouse by simple triple-clicking anywhere on the line. </p>
<p><strong>Highlight Current Line</strong>    <br />As the resolution of monitors increases, it’s becoming more difficult to find the caret in the code editor.&#160; The highlight current line extension makes it easy to find the caret by highlighting the line that the caret is on in the editor.&#160; You can even configure the default colour by changing the setting for “Current Line (Extension)” and “Current Line Inactive (Extension)” in Tools Options Fonts &amp; Colors. </p>
<p><strong>HTML Copy (<a href="http://blogs.msdn.com/b/kirillosenkov/archive/2010/06/07/copy-code-in-html-format-with-visual-studio-2010.aspx">More Info</a>)</strong>    <br />This extension provides support for the HTML Clipboard format when cutting or copying code from the editor.&#160; This means that you’ll no longer have to go fix up the formatting of your code when you paste it into a TFS bug form or any other HTML based control. </p>
<p><strong>Colorized Parameter Help</strong>    <br />This extension improves consistency with the editor by applying syntax highlighting to the contents of the Parameter Help window for C# &amp;VB.    <br />Please note: Syntax highlighting colors can be customized using the display items prefixed with “Signature Help” in the “Fonts and Colors” menu.</p>
<p><strong>Tab Well UI </strong>    <br />This extension allows you to completely customize the behavior of your document tabs from the Productivity Power Tools Options: See <a href="http://blogs.msdn.com/b/visualstudio/archive/2010/06/10/document-well-2010-plus.aspx">More Info</a></p>
<p><strong>Auto Brace Completion     <br /></strong>Automatic Brace Completion improves the productivity of writing code by automatically inserting the closing code construct when the opening construct is typed for VB &amp; C#.&#160; More specifically, this extension:</p>
<ul>
<li>Supports the following constructs: (), {}, [], &lt;&gt;, “”, and ‘’.&#160; </li>
<li>Allows you to press &lt;TAB&gt; to navigate past the next enclosing brace </li>
<li>Allows you to automatically complete a statement in C# by inserting the closing semi-colon and moving you to the next line with SHIFT + ENTER</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://codereflect.com/2010/08/11/visual-studio-2010-productivity-tools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming Direct2D – Part 1</title>
		<link>http://codereflect.com/2010/07/19/programming-direct2d-part-1/</link>
		<comments>http://codereflect.com/2010/07/19/programming-direct2d-part-1/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 15:00:05 +0000</pubDate>
		<dc:creator>@sarat</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://codereflect.com/?p=1209</guid>
		<description><![CDATA[Most of the native Windows Programmers are familiar with GDI, the graphics API provided under Windows. GDI is widely used in windows applications. Later, Microsoft had introduced class-based, better services through GDI+ under Windows. Both Native programmers and Managed developers are making use of GDI/GDI+ classes and APIs. But GDI was too old and was [...]]]></description>
			<content:encoded><![CDATA[<p>Most of the native Windows Programmers are familiar with GDI, the graphics API provided under Windows. GDI is widely used in windows applications. Later, Microsoft had introduced class-based, better services through GDI+ under Windows. Both Native programmers and Managed developers are making use of GDI/GDI+ classes and APIs.</p>
<p>But GDI was too old and was introduced with the initial versions of the Windows and over the time the capabilities of graphics hardware has grown and so does the demand for creating Visually Rich UI. With Windows 7, Microsoft has introduced a totally revamped 2D graphics subsystem called <strong><a href="http://msdn.microsoft.com/en-us/library/dd370990(VS.85).aspx" target="_blank">Direct2D</a></strong> based on their prominent Direct3D platform to create high quality 2D rendering. If you know or not, <a href="http://windows.microsoft.com/en-us/windows-vista/products/features/productivity">Windows Aero</a> system is already taking advantage of graphics hardware since Windows Vista. This is supposed to replace the GDI APIs in the coming years. Direct2D is not only available under Windows 7 but Microsoft has made it available in Window Vista with the latest service pack upgrade.</p>
<p>The major advantages of the Direct2D APIs are it&#8217;s hardware accelerated and provides high quality 2D rendering. It enables the user to create visually rich applications by paying less effort, when comparing to conventional APIs .</p>
<p>GDI uses Pixel graphics but Direct2D can supports vector graphics as well, in which mathematical formulas are used to draw the lines and curves. Vector graphics provides high quality rendering independent of resolution of the device, while the pixelated graphics has dependency with resolution which may results in choppy graphics.</p>
<p>Most of the GDI APIs are not using anti-aliasing and transparency. Ofcrouse there are functions to do so but always there&#8217;s programming cost for taking advantage of these features. Also if we apply  transparency and anti-aliasing, the computations are done using CPU. Direct2D can take advantage of graphics hardware and delegate the computationally intensive tasks to <a href="http://en.wikipedia.org/wiki/Graphics_processing_unit">GPU</a>.</p>
<p><img src="http://codereflect.com/wp-content/uploads/2010/07/071910_1523_Programming11.png" alt="" /></p>
<p>Direct2D built on top of Direct3D components. The layered architecture is described below</p>
<p><img src="http://codereflect.com/wp-content/uploads/2010/07/071910_1523_Programming21.png" alt="" /></p>
<p>You can see the underlying layers are Direct3D which make use of DXGI(DirectX Graphics Infrastructure), which manages the low level graphics related tasks that are independent of DirectX graphics runtime. DXGI provides common framework for graphics components. Simultaneously a high performance software rasterizer is available when the hardware acceleration is not possible. Another advantage of Direct2D API is, it&#8217;s using lightweight COM. It&#8217;s almost like simple C++ class. No BSTRS, COM Variants, Interfaces, Apartments etc.</p>
<p>Let&#8217;s start analyzing a simple Direct2D Program</p>
<p>There are 3 main components inevitable for enabling D2D rendering your application.</p>
<ul>
<li>A rendering Window and its handle (HWND)</li>
<li><a href="http://msdn.microsoft.com/en-us/library/dd371246(VS.85).aspx">ID2D1Factory</a> object to create the Direct2D resources</li>
<li><a href="http://msdn.microsoft.com/en-us/library/dd371461(VS.85).aspx">ID2D1HwndRenderTarget</a> object to draw the scene on the window.</li>
</ul>
<p>The below example provides steps for enabling Direct2D Rendering in your MFC Application. It&#8217;s hard to describe the parameters of all APIs. Please refer them in MSDN.</p>
<p><img src="http://codereflect.com/wp-content/uploads/2010/07/071910_1523_Programming31.png" alt="" /></p>
<h2>Create your Window</h2>
<p>Here I&#8217;m taking a dialog based application for rendering. The functions and messages may change if you&#8217;re using any other type of applications like SDI or MDI. No need to reinvent the wheel, allow the wizard to create your main dialog.</p>
<h2>Prepare your Rendering Engine</h2>
<p>Let&#8217;s delegate all the rendering tasks to another class instead of managing everything in the dialog class. I call this class as Direct2DHandler.</p>
<p>The Direct2DHandler declaration goes like below and it exposes the following functions.</p>
<pre>
#pragma once
#include &lt;d2d1.h&gt;
#include &lt;d2d1helper.h&gt;

class Direct2DHandler
{
public:
	Direct2DHandler( HWND hWnd ); // ctor
	~Direct2DHandler(void); // dtor
	HRESULT Initialize(); // Initialize the rendering
	HRESULT OnRender(); // Called from OnPaint function
	void OnResize(UINT width, UINT height);

private:
	HRESULT CreateDeviceResources(); // Create resources for drawing
	void DiscardDeviceResources(); // Release resources for drawing

private:

	HWND					m_hWnd;
	ID2D1Factory*			m_pDirect2dFactory;
	ID2D1HwndRenderTarget*	m_pRenderTarget;
	ID2D1SolidColorBrush*	m_pLightSlateGrayBrush;
	ID2D1LinearGradientBrush* m_pLinearGradientBrush;
};
</pre>
<h3>The constructor</h3>
<p>does nothing other than calling CoInitialize() function and initialize the member variables( mostly to NULL).</p>
<h3>The Initialize function</h3>
<p>creates the Direct2D factor object, which similar the HDC (context variable) in GDI.</p>
<pre>
HRESULT Direct2DHandler::Initialize()
{
    HRESULT hr = S_OK;

    // Create a Direct2D factory.
    hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &amp;m_pDirect2dFactory);

    return hr;
}
</pre>
<p><strong>OnResize</strong></p>
<p>function handles the rendering area for the render target. We will be using whole window area in this example.<span style="font-family: Consolas; font-size: 9pt;"><br />
</span></p>
<pre>
void Direct2DHandler::OnResize(UINT width, UINT height)
{
    if (m_pRenderTarget)
    {
        // Note: This method can fail, but it's okay to ignore the
        // error here, because the error will be returned again
        // the next time EndDraw is called.
        m_pRenderTarget-&gt;Resize(D2D1::SizeU(width, height));
    }
}
</pre>
<h3>OnRender</h3>
<p>function does the following</p>
<ol>
<li>Create the device resource for drawing (if not created)</li>
<li>Render the scene to the Window</li>
<li>Release the resources if error occurred</li>
</ol>
<p>If you&#8217;re experienced 3D programming probably you might be knowing about the role of matrix and how the affects the rendering object. The matrix can be used for representing the objects coordinates system. We can apply rotation, translation (movement) etc (collectively called transformation). on a matrix and this can be used for specifying how object must be rendered. Here we&#8217;re using <span style="font-family: Consolas; font-size: 9pt;">D2D1::Matrix3x2F::Identity() </span>helper function which creates an identity matrix(object will be rendered at origin without any transformation)</p>
<p><span style="font-family: Consolas; font-size: 9pt;"> m_pRenderTarget-&gt;<a href="http://msdn.microsoft.com/en-us/library/dd742857(VS.85).aspx">SetTransform</a>(D2D1::Matrix3x2F::Identity());<br />
</span></p>
<p>We can clear the rendering area with a default color (as the dialog background filled with some default color according to Window&#8217;s theme. Here I selected white color</p>
<p><span style="font-family: Consolas; font-size: 9pt;"> m_pRenderTarget-&gt;Clear(D2D1::ColorF(D2D1::ColorF::White));<br />
</span></p>
<p>The important thing is, whatever you draw for the scene must be done between BeginDraw() and EndDraw() APIs. The other part of this code is simply straight forward and you can easily grasp it. See the source below.</p>
<pre>
HRESULT Direct2DHandler::OnRender()
{
	HRESULT hr = S_OK;

	hr = CreateDeviceResources();

	if (SUCCEEDED(hr))
	{
		m_pRenderTarget-&gt;BeginDraw();
		m_pRenderTarget-&gt;SetTransform(D2D1::Matrix3x2F::Identity());
		m_pRenderTarget-&gt;Clear(D2D1::ColorF(D2D1::ColorF::White));
		D2D1_SIZE_F rtSize = m_pRenderTarget-&gt;GetSize();
		// Draw a grid background.
		int width = static_cast&lt;int&gt;(rtSize.width);
		int height = static_cast&lt;int&gt;(rtSize.height);

		// Draw two rectangles.
		D2D1_RECT_F rectangle1 = D2D1::RectF(
			rtSize.width/2 - 50.0f,
			rtSize.height/2 - 50.0f,
			rtSize.width/2 + 50.0f,
			rtSize.height/2 + 50.0f
			);

		D2D1_RECT_F rectangle2 = D2D1::RectF(
			rtSize.width/2 - 100.0f,
			rtSize.height/2 - 100.0f,
			rtSize.width/2 + 100.0f,
			rtSize.height/2 + 100.0f
			);

		// Draw the outline of a rectangle.
		m_pRenderTarget-&gt;FillRectangle(&amp;rectangle2, m_pLinearGradientBrush);

		// Draw a filled rectangle.
		m_pRenderTarget-&gt;FillRectangle(&amp;rectangle1, m_pLightSlateGrayBrush);

		hr = m_pRenderTarget-&gt;EndDraw();

	}
	if (hr == D2DERR_RECREATE_TARGET)
	{
		hr = S_OK;
		DiscardDeviceResources();
	}
	return hr;
}
</pre>
<p><strong>CreateDeviceResources</strong></p>
<p>is slightly a lengthy function to initialize the required resources for rendering, like we create pens, brushes, bitmaps etc. Here mainly I&#8217;m creating a light colored solid brush and linear gradient brush to render as depicted in above picture. The comments are inlined and please read it along with the code. It will be interesting to learn about gradient brushes. If you&#8217;ve created a gradient brush in photoshop things will be far more easy. We can put stop spots to controls the end of gradients also line can be used for representing flow and angle for the gradient. Simple isn&#8217;t it? Like we create a normal gradient. See the code below.</p>
<pre>
HRESULT Direct2DHandler::CreateDeviceResources()
{
    HRESULT hr = S_OK;

    if (!m_pRenderTarget)
    {
        RECT rc;
        GetClientRect(m_hWnd, &amp;rc);

        D2D1_SIZE_U size = D2D1::SizeU(
            rc.right - rc.left,
            rc.bottom - rc.top
            );

        // Create a Direct2D render target.
        hr = m_pDirect2dFactory-&gt;CreateHwndRenderTarget(
            D2D1::RenderTargetProperties(),
            D2D1::HwndRenderTargetProperties(m_hWnd, size),
            &amp;m_pRenderTarget
            );

        if (SUCCEEDED(hr))
        {
            // Create a gray brush.
            hr = m_pRenderTarget-&gt;CreateSolidColorBrush(
                D2D1::ColorF(D2D1::ColorF::LightSlateGray),
                &amp;m_pLightSlateGrayBrush
                );
        }

		// Create an array of gradient stops to put in the gradient stop
		// collection that will be used in the gradient brush.
		ID2D1GradientStopCollection *pGradientStops = NULL;

		D2D1_GRADIENT_STOP gradientStops[2];
		gradientStops[0].color = D2D1::ColorF(D2D1::ColorF::Maroon, 1);
		gradientStops[0].position = 0.0f;
		gradientStops[1].color = D2D1::ColorF(D2D1::ColorF::Red, 1);
		gradientStops[1].position = 1.0f;
		// Create the ID2D1GradientStopCollection from a previously
		// declared array of D2D1_GRADIENT_STOP structs.
		hr = m_pRenderTarget-&gt;CreateGradientStopCollection(
			gradientStops,
			2,
			D2D1_GAMMA_2_2,
			D2D1_EXTEND_MODE_CLAMP,
			&amp;pGradientStops
			);
		// The line that determines the direction of the gradient starts at
		// the upper-left corner of the square and ends at the lower-right corner.

		if (SUCCEEDED(hr))
		{
			hr = m_pRenderTarget-&gt;CreateLinearGradientBrush(
				D2D1::LinearGradientBrushProperties(
				D2D1::Point2F(0, 0),
				D2D1::Point2F(300, 300)),
				pGradientStops,
				&amp;m_pLinearGradientBrush
				);
		}

    }

    return hr;
}
</pre>
<h3>DiscardDeviceResources</h3>
<p>Just releases the allocated resouces. It simply uses helper macro SafeRelease described below the code.</p>
<pre>
void Direct2DHandler::DiscardDeviceResources()
{
    SafeRelease(&amp;m_pRenderTarget);
    SafeRelease(&amp;m_pLightSlateGrayBrush);
    SafeRelease(&amp;m_pLinearGradientBrush);
}

template&lt;class Interface&gt;
inline void SafeRelease(
    Interface **ppInterfaceToRelease
    )
{
    if (*ppInterfaceToRelease != NULL)
    {
        (*ppInterfaceToRelease)-&gt;Release();

        (*ppInterfaceToRelease) = NULL;
    }
}
</pre>
<p><strong>Initializing Rendering in Dialog class</strong></p>
<p>In the</p>
<h3>OnInitDialog function,</h3>
<p>allocate memory for the Direct2DHandler class and Initialize it. You can call this from OnCreate function as well but ensure that there&#8217;s a valid Window handle is there.</p>
<pre>
m_pRender = new Direct2DHandler( m_hWnd );
m_pRender-&gt;Initialize();
</pre>
<h3>Disable Default Background Drawing</h3>
<p>Disable the default OnErasBkgrnd function because it may cause flickering while drawing. Also we&#8217;re occupying full client area in the dialog and the background is clearing is OnRender function itself.</p>
<pre>
BOOL CDirect2DDemoDlg::OnEraseBkgnd(CDC* pDC)
{
    return FALSE;//CDialogEx::OnEraseBkgnd(pDC);
}
</pre>
<h3>OnSize (WM_SIZE)</h3>
<p>function handles the Window size events. It will resize render target according to the Window Size.</p>
<pre>
void CDirect2DDemoDlg::OnSize(UINT nType, int cx, int cy)
{
    CDialogEx::OnSize(nType, cx, cy);
    if( m_pRender )
        m_pRender-&gt;OnResize( cx, cy );
}
</pre>
<h3>OnPaint function</h3>
<p>calls OnRender function of Direct2DHandler to draw the scene.</p>
<pre>
void CDirect2DDemoDlg::OnPaint()
{
    if (IsIconic())
    {
        // code for handling when window is minimized. Check original CPP file attached.
    }
    else
    {
        // CDialogEx::OnPaint(); no need to call this.
        if( m_pRender )
            m_pRender-&gt;OnRender();
    }
}
</pre>
<h3>Linking</h3>
<p>The Application must link to d2d1.lib through project settings or using #pragma comment( lib, &#8220;d2d1.lib&#8221; ) in the source file</p>
<h3> d2d1helper </h3>
<p>d2d1helper.h contains some useful functions to help the drawing. See the header for more details.</p>
<p>OK that&#8217;s the basics of creating Direct2D rendering for your Windows Application. Go ahead with the attached source code.</p>
<p>The project file is in Visual Studio 2010 format, but basically you only need to have Direct2DHandler class. You can also use other prior version of Visual Studio with Windows 7/Vista SDK.</p>
<p>Note: Take whole responsibility of downloading and executing the code shared here. Don&#8217;t sue me. It was virus free, malware free when I uploaded.</p>
<p><a href="http://cid-5544789b26bfc05d.office.live.com/embedicon.aspx/.Public/Direct2DDemo.zip">Download Demo Source code</a><br />
<iframe title ="Preview" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" style="width:98px;height:115px;padding:0;background-color:#fcfcfc;" src="http://cid-5544789b26bfc05d.office.live.com/embedicon.aspx/.Public/Direct2DDemo.zip"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://codereflect.com/2010/07/19/programming-direct2d-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Visual Studio 2010 &#8211; Theme Editor &amp; Hide Main Menubar extension</title>
		<link>http://codereflect.com/2010/07/09/visual-studio-2010-theme-editor/</link>
		<comments>http://codereflect.com/2010/07/09/visual-studio-2010-theme-editor/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 16:09:40 +0000</pubDate>
		<dc:creator>@sarat</dc:creator>
				<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[Visual Studio Editor]]></category>

		<guid isPermaLink="false">http://codereflect.com/2010/07/09/visual-studio-2010-theme-editor/</guid>
		<description><![CDATA[Are you really bored of the default appearance of Visual Studio? Even it’s quite different from Normal Windows (XP) Menus and toolbars, yea I’m sure it’s really nice if we can customize the colors based on our mood. Here’s a free tool to play around with Visual Studio 2010. You can edit the theme for [...]]]></description>
			<content:encoded><![CDATA[<p>Are you really bored of the default appearance of Visual Studio? Even it’s quite different from Normal Windows (XP) Menus and toolbars, yea I’m sure it’s really nice if we can customize the colors based on our mood. </p>
<p>Here’s a free tool to play around with Visual Studio 2010. You can edit the theme for Visual Studio with <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/20cd93a2-c435-4d00-a797-499f16402378">Visual Studio Color Theme Editor</a>. It comes up with some default flavors of themes but we can also customize or download pre-created themes from any website. You can see a bunch of extensions, tools, themes etc. at <a href="http://visualstudiogallery.msdn.microsoft.com/en-us">Visual Studio Gallery</a>.</p>
<p><a href="http://codereflect.com/wp-content/uploads/2010/07/image.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://codereflect.com/wp-content/uploads/2010/07/image_thumb.png" width="505" height="348" /></a> </p>
<p>Also <a href="http://studiostyles.info/">studiostyles.info</a> contains 100’s of themes to satisfy your moods. The Visual Studio 2010 extensibility library contains lot of gems to make everything in your way. Not only themes, the whole Visual Studio and it’s contents can be taken in your hand using <a href="http://msdn.microsoft.com/en-us/vstudio/vextend.aspx">Visual Studio 2010 SDK</a>. It’s much more flexible and innovative than it’s predecessors. You can get a bit more <a href="http://blogs.msdn.com/b/visualstudio/archive/2010/01/04/changing-visual-studio-s-color-palette.aspx" target="_blank">detailed scoop here</a>. Anyways have a nice time with colors <img src='http://codereflect.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong>Bonus: </strong>How many of you guys are fascinated with keyboard shortcuts? I usually use mouse only if I can’t operate something with keyobard. Have you ever wished, if we could hide the unusable menubar? Matthew Johnson has written a nice <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/bdbcffca-32a6-4034-8e89-c31b86ad4813">extension to hide the menubar from Visual Studio 2010 IDE</a>. On hitting, alt key will enable the menubar again. You can directly press the Alt+ Any (valid) key (e.g. Alt+F, Alt+T etc.)</p>
<p><a href="http://codereflect.com/wp-content/uploads/2010/07/image1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://codereflect.com/wp-content/uploads/2010/07/image_thumb1.png" width="422" height="175" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://codereflect.com/2010/07/09/visual-studio-2010-theme-editor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

