<?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>Visual C++ Tips &#187; MFC</title>
	<atom:link href="http://weseetips.com/category/mfc/feed/" rel="self" type="application/rss+xml" />
	<link>http://weseetips.com</link>
	<description>Gold mine of Visual C++ tricks!</description>
	<lastBuildDate>Thu, 11 Mar 2010 09:09:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>How to set Focus to Different Control on Dialog Startup?</title>
		<link>http://weseetips.com/2010/02/08/how-to-set-focus-to-different-control-on-dialog-startup/</link>
		<comments>http://weseetips.com/2010/02/08/how-to-set-focus-to-different-control-on-dialog-startup/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 17:50:49 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[MFC]]></category>
		<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[CWnd::SetFocus()]]></category>
		<category><![CDATA[set control focus]]></category>
		<category><![CDATA[set focus]]></category>
		<category><![CDATA[SetFocus OnInitDialog]]></category>
		<category><![CDATA[VC++]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=1323</guid>
		<description><![CDATA[Do you want to set the focus to another control on displaying Dialog? Or tried SetFocus() to another control in OnInitDialog() and want to know why its not working? The answer for your &#8216;Focus&#8217; question is here. If you are setting the default focus to another control in dialog, then OnInitDialog() should return FALSE. Have [...]]]></description>
			<content:encoded><![CDATA[<p>Do you want to set the focus to another control on displaying Dialog? Or tried SetFocus() to another control in OnInitDialog() and want to know why its not working? The answer for your &#8216;Focus&#8217; question is here.</p>
<p><img class="alignnone size-full wp-image-1325" title="SetFocus" src="http://weseetips.com/wp-content/uploads/2010/02/SetFocus.jpg" alt="" width="400" height="267" /></p>
<p><img class="alignnone size-full wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.com/wp-content/uploads/2008/03/icon_howcanidoit.jpg" alt="" width="220" height="32" /></p>
<p>If you are setting the default focus to another control in dialog, then OnInitDialog() should return FALSE. Have a look at the code snippet below.</p>
<pre>BOOL CStartupFocusDlg::OnInitDialog()
{
 ...
 // Set focus to your control.
 CWnd* pWnd = GetDlgItem(IDC_EDIT2);
 pWnd-&gt;SetFocus();

 // return TRUE;  // Wizard Generated code.
 // Return FALSE if you set focus to different control
 return FALSE;
}
</pre>
<p><img class="alignnone size-full wp-image-18" title="Icon Note" src="http://weseetips.com/wp-content/uploads/2008/03/icon_note.jpg" alt="" width="94" height="32" /><br />
Download the <a href="http://weseetips.com/wp-content/uploads/2010/02/StartupFocus.zip" target="_blank">Sample</a>, if you want to see it in action. Please note that sample is compiled in Visual C++ 2008.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2010/02/08/how-to-set-focus-to-different-control-on-dialog-startup/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Start the ScreenSaver Programmatically?</title>
		<link>http://weseetips.com/2009/01/07/how-to-start-the-screensaver-programmatically/</link>
		<comments>http://weseetips.com/2009/01/07/how-to-start-the-screensaver-programmatically/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 21:25:22 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[MFC]]></category>
		<category><![CDATA[Windows APIs]]></category>
		<category><![CDATA[DefWindowProc()]]></category>
		<category><![CDATA[SC_SCREENSAVE]]></category>
		<category><![CDATA[start screen saver]]></category>
		<category><![CDATA[start screensaver]]></category>
		<category><![CDATA[windows screensaver]]></category>
		<category><![CDATA[WM_SYSCOMMAND]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=848</guid>
		<description><![CDATA[I&#8217;ve installed an aquarium screensaver and It works perfectly when i go to check the flames of stove. But from yesterday onwards, the screensaver is crashing due to some reasons. Well, i just thought about &#8211; is there any way to start the screensaver programmatically and see the crash once again? Picture Courtesy &#8211; fordesigner [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
I&#8217;ve installed an aquarium screensaver and It works perfectly when i go to check the flames of stove. <img src='http://weseetips.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  But from yesterday onwards, the screensaver is crashing due to some reasons. Well, i just thought about &#8211; <span style="color:#0000ff;">is there any way to start the screensaver programmatically</span> and see the crash once again? <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img class="alignnone size-full wp-image-853" title="startscreensaver" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/01/startscreensaver.jpg" alt="startscreensaver" width="425" height="282" /><br />
Picture Courtesy &#8211; <a title="fordesigner" href="http://www.fordesigner.com/maps//3034-0.htm">fordesigner</a></p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
Basically you have to <span style="color:#0000ff;">send a WM_SYSCOMMAND </span>to any of the windows <span style="color:#0000ff;">with wParam as SC_SCREENSAVE.</span> And what really happens in background is, <span style="text-decoration:underline;"><span style="color:#0000ff;">the default window proc will get the message and will start the screen saver.</span></span> So you can call the <span style="color:#0000ff;">DefWindowProc()</span> directly to start the screensaver. Have a look at the code snippet.</p>
<pre>// Start the screen-saver
DefWindowProc( WM_SYSCOMMAND, SC_SCREENSAVE, 0 );</pre>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
It was really a nice screensaver. May be I&#8217;ll reinstall it to see it again. <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img class="alignnone size-medium wp-image-51" title="beginnerseries" src="http://weseetips.files.wordpress.com/2008/03/beginnerseries.jpg?w=215" alt="" width="215" height="32" /><br />
Targeted Audiance &#8211; Beginners.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2009/01/07/how-to-start-the-screensaver-programmatically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Print the CView directly to Printer?</title>
		<link>http://weseetips.com/2009/01/06/how-to-print-the-cview-directly-to-printer/</link>
		<comments>http://weseetips.com/2009/01/06/how-to-print-the-cview-directly-to-printer/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 22:15:40 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[MFC]]></category>
		<category><![CDATA[CFrameWnd]]></category>
		<category><![CDATA[CView::OnCmdMsg()]]></category>
		<category><![CDATA[document/view print]]></category>
		<category><![CDATA[GetActiveView()]]></category>
		<category><![CDATA[ID_FILE_PRINT]]></category>
		<category><![CDATA[ID_FILE_PRINT_DIRECT]]></category>
		<category><![CDATA[mdi print]]></category>
		<category><![CDATA[print CView]]></category>
		<category><![CDATA[print document]]></category>
		<category><![CDATA[print view]]></category>
		<category><![CDATA[sdi print]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=836</guid>
		<description><![CDATA[MFC&#8217;s Document/View framework have built-in printing support for applications. If you create one SDI or MDI application, you can take the print by using the File-&#62;Print menu. But the menu handling and print functionality is buried deep inside mfc framework. Well, how to take the print of current view by your own? Picture Courtesy &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
<span style="color:#0000ff;"> MFC&#8217;s Document/View framework have built-in printing support for applications.</span> If you create one SDI or MDI application, you can take the print by using the File-&gt;Print menu. But the menu handling and print functionality is buried deep inside mfc framework. <span style="color:#0000ff;">Well, how to take the print of current view by your own?</span></p>
<p><img class="alignnone size-full wp-image-841" title="printview" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/01/printview.jpg" alt="printview" width="510" height="367" /><br />
Picture Courtesy &#8211; <a href="http://www.daycad.com/">DayCad</a>.</p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
You have to call <span style="color:#0000ff;">CView::OnCmdMsg()</span> by passing <span style="color:#0000ff;">ID_FILE_PRINT</span> or <span style="color:#0000ff;">ID_FILE_PRINT_DIRECT</span>. If ID_FILE_PRINT is passed, the printer dialog will be shown and for ID_FILE_PRINT_DIRECT, the print will be taken directly with default printer parameters. Have a look at the code snippet.</p>
<pre>// Get the active view.
CFrameWnd* pFrameWnd = (CFrameWnd*)AfxGetApp()-&gt;GetMainWnd();
CView* pView = pFrameWnd-&gt;GetActiveView();

if( pView != NULL )
{
    // Send Print message.
    // If you want to print directly, then change ID_FILE_PRINT
    // to ID_FILE_PRINT_DIRECT.
    pView-&gt;OnCmdMsg( ID_FILE_PRINT, 0, 0, 0 );
}</pre>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
Its interesting to know MFC internals. isn&#8217;t it?</p>
<p><img class="alignnone size-medium wp-image-53" title="intermediateseries" src="http://weseetips.files.wordpress.com/2008/03/intermediateseries.jpg?w=248" alt="" width="248" height="32" /><br />
Targeted Audience &#8211; Intermediate.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2009/01/06/how-to-print-the-cview-directly-to-printer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Enable Password Mask in Editbox?</title>
		<link>http://weseetips.com/2009/01/04/how-to-enable-password-mask-in-editbox/</link>
		<comments>http://weseetips.com/2009/01/04/how-to-enable-password-mask-in-editbox/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 21:07:21 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[MFC]]></category>
		<category><![CDATA[* in editbox]]></category>
		<category><![CDATA[CEdit]]></category>
		<category><![CDATA[editbox *]]></category>
		<category><![CDATA[editbox password char]]></category>
		<category><![CDATA[editbox set password char]]></category>
		<category><![CDATA[ES_PASSWORD]]></category>
		<category><![CDATA[password chat in edit box]]></category>
		<category><![CDATA[password edit box]]></category>
		<category><![CDATA[password mask]]></category>
		<category><![CDATA[SetPasswordChar()]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=827</guid>
		<description><![CDATA[User Authentication is common in windows application. Usually the password editbox is masked and won&#8217;t show the real password. But to to enable the password masking in Editbox? Picture Courtesy &#8211; NoteBookForums. You have to enable ES_PASSWORD style of editbox and have to call SetPasswordChar() to set the Password masking character. You can do it [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
User Authentication is common in windows application. Usually the password editbox is masked and won&#8217;t show the real password. <span style="color:#0000ff;">But to to enable the password masking in Editbox?</span></p>
<p><span style="color:#0000ff;"><img class="alignnone size-full wp-image-832" title="editpasswordmask" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/01/editpasswordmask.jpg" alt="editpasswordmask" width="510" height="382" /></span></p>
<p><span style="color:#0000ff;"><span style="color:#000000;">Picture Courtesy &#8211; <a title="NotebookForums" href="http://www.notebookforums.com/thread124080.html" target="_blank">NoteBookForums</a>.</span><br />
</span></p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
You have to <span style="color:#0000ff;">enable <strong>ES_PASSWORD</strong> </span>style of editbox and have to <span style="color:#0000ff;">call SetPasswordChar() to set the Password masking character.</span> You can do it in CDialog::OnInitDialog(). See the code snippet below.</p>
<pre>BOOL CRabbitDlg::OnInitDialog()
{
    ...

    // Get the Edit by using CtrlID.
    CEdit* pEdit = (CEdit*) GetDlgItem( IDC_EDIT_PASSWORD );

    // Set the password char.
    pEdit-&gt;SetPasswordChar( '*' );

    // Now modify the style to enable ES_PASSWORD.
    pEdit-&gt;ModifyStyle( 0, ES_PASSWORD );

    return TRUE;
}</pre>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
Unless I&#8217;m very mistaken, it was while setting up samba server in Linux, where i had an interesting incident related to password. I was asked to type the password and save it. When I took the dialog again, the displayed password length was different. I was confused. I retyped and saved it again and again. Very lately i came to know that its a trick to fool the people who try to guess the password by length. <img src='http://weseetips.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><img class="alignnone size-medium wp-image-51" title="beginnerseries" src="http://weseetips.files.wordpress.com/2008/03/beginnerseries.jpg?w=215" alt="" width="215" height="32" /><br />
Targeted Audience &#8211; Beginners.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2009/01/04/how-to-enable-password-mask-in-editbox/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Expand/Collapse TreeCtrl nodes by using Enter Key?</title>
		<link>http://weseetips.com/2009/01/02/how-to-expandcollapse-treectrl-nodes-by-using-enter-key/</link>
		<comments>http://weseetips.com/2009/01/02/how-to-expandcollapse-treectrl-nodes-by-using-enter-key/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 23:23:46 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[MFC]]></category>
		<category><![CDATA[collapse tree by enter key]]></category>
		<category><![CDATA[CTreeCtrl]]></category>
		<category><![CDATA[expand tree by enter key]]></category>
		<category><![CDATA[GetDlgCtrlID()]]></category>
		<category><![CDATA[GetItemState()]]></category>
		<category><![CDATA[GetSelectedItem()]]></category>
		<category><![CDATA[PreTranslateMessage()]]></category>
		<category><![CDATA[TVIS_EXPANDED]]></category>
		<category><![CDATA[VK_RETURN]]></category>
		<category><![CDATA[WM_KEYDOWN]]></category>
		<category><![CDATA[WM_SUBSTRACT]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=817</guid>
		<description><![CDATA[You can see Tree Control, almost in every heavy windows applications. They are very convineant method for organize things in hierarchy. But by default Tree control doesn&#8217;t support expand/collapse of its tree nodes by Enter key. Is there any way to do that? Picture Courtesy &#8211; hawaiibonsai Yes, you can! All you want to do [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.wordpress.com/files/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
You can see Tree Control, almost in every heavy windows applications. They are very convineant  method for organize things in hierarchy. But <span style="color:#0000ff;">by default Tree control doesn&#8217;t support expand/collapse of its tree nodes by Enter key.</span> Is there any way to do that?</p>
<p><img class="alignnone size-full wp-image-820" title="expandcollapsetreectrl" src="http://weseetips.wordpress.com/files/2009/01/expandcollapsetreectrl.jpg" alt="expandcollapsetreectrl" width="350" height="367" /><br />
Picture Courtesy &#8211; <a title="hawaiibonsai" href="http://hawaiibonsai.e-siteworks.com/bonsai/view.nhtml?profile=bonsai&amp;UID=10019" target="_blank">hawaiibonsai</a></p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.wordpress.com/files/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
Yes, you can! All you want to do is &#8211; <span style="color:#0000ff;">Override <strong>PreTranslateMessage()</strong></span> in your dialog and <span style="color:#0000ff;">handle all <strong>WM_KEYDOWN</strong> messages for your tree control</span>. <span style="color:#0000ff;">If,</span> the key is <strong><span style="color:#0000ff;">VK_RETURN</span></strong>, i.e. enter key, then <span style="color:#0000ff;">check</span> whether the <span style="color:#0000ff;">current selected node in TreeCtrl is expanded or collapsed</span> and <span style="color:#0000ff;">modify the key stroke as <strong>WM_ADD</strong> key</span> or <span style="color:#0000ff;"><strong>WM_SUBSTRACT</strong> key accordingly.</span> The idea is, if you press +, then tree node expands and for &#8211; key, the tree node collapse &#8211; which is the default behavior of tree control. Well, have a look at the code snippet.</p>
<pre>BOOL CRabbitDlg::PreTranslateMessage(MSG* pMsg)
{
    // Check whether its a keypress.
    if( pMsg-&gt;message == WM_KEYDOWN )
    {
        // Check whether its for our tree control.
        UINT CtrlId = ::GetDlgCtrlID( pMsg-&gt;hwnd );
        if( CtrlId == IDC_TREECTRL )
        {
            // Check whether its enter key.
            if( pMsg-&gt;wParam == VK_RETURN)
            {
                // Check whether the currently selected item is
                HTREEITEM CurrentItem = m_TreeCtrl.GetSelectedItem();
                if( m_TreeCtrl.GetItemState( CurrentItem, TVIS_EXPANDED )
                        &amp; TVIS_EXPANDED )
                {
                    // Current Item is Expanded.
                    // So send - Key code to collapse it.
                    pMsg-&gt;wParam = VK_SUBTRACT;
                }
                else
                {
                    // Current Item is Collapsed.
                    // So send + Key code to Expand it.
                    pMsg-&gt;wParam = VK_ADD;
                }
            }
        }
    }

    return CDialog::PreTranslateMessage(pMsg);
}</pre>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.wordpress.com/files/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
If you want the expand entire child nodes under a particular node, then press * key. I used to use this techniqe to report performance bugs. <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img class="alignnone size-medium wp-image-53" title="intermediateseries" src="http://weseetips.wordpress.com/files/2008/03/intermediateseries.jpg?w=248" alt="" width="248" height="32" /><br />
Targeted Audience &#8211; Intermediate.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2009/01/02/how-to-expandcollapse-treectrl-nodes-by-using-enter-key/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to convert CString to char* or LPTSTR?</title>
		<link>http://weseetips.com/2008/12/17/how-to-convert-cstring-to-char-or-lptstr/</link>
		<comments>http://weseetips.com/2008/12/17/how-to-convert-cstring-to-char-or-lptstr/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 21:43:24 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[MFC]]></category>
		<category><![CDATA[Misc]]></category>
		<category><![CDATA[cannot convert parameter 1 from 'class CString' to 'cha]]></category>
		<category><![CDATA[CString to char*]]></category>
		<category><![CDATA[CString to LPCTSTR]]></category>
		<category><![CDATA[CString to LPTSTR]]></category>
		<category><![CDATA[CString to LPWSTR]]></category>
		<category><![CDATA[CString to str]]></category>
		<category><![CDATA[CString to TCHAR*]]></category>
		<category><![CDATA[CString to wchar_t*]]></category>
		<category><![CDATA[CString::GetBuffer()]]></category>
		<category><![CDATA[CString::ReleaseBuffer()]]></category>
		<category><![CDATA[error C2664]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=738</guid>
		<description><![CDATA[Without a second thought, I can say that it will be one of the first problems that beginners face &#8211; How to convert a CString to LPTSTR. I&#8217;ve seen this question several times in forums. Well, i think the CString to LPTSTR conversion is just like this picture. Well, you can use CString::GetBuffer() to access [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
Without a second thought, I can say that it will be one of the first problems that beginners face &#8211; <span style="color:#0000ff;">How to convert a CString to LPTSTR.</span> I&#8217;ve seen this question several times in forums. Well, i think the CString to LPTSTR conversion is just like this picture. <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img class="alignnone size-full wp-image-740" title="cstringtolptstr" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/12/cstringtolptstr.png" alt="cstringtolptstr" width="494" height="227" /></p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
Well, you can use <span style="color:#0000ff;">CString::GetBuffer()</span> to access the internal buffer of CString. But one thing to take care is that &#8211; <strong>you should release the buffer</strong> by calling <span style="color:#0000ff;">CString::ReleaseBuffer()</span> after use. Check the code snippet below,</p>
<pre>// Our CString object.
CString String = "HelloWorld";

// Get the internal buffer pointer of CString.
LPTSTR pString = String.GetBuffer( 0 );
...

// Use the pString and then release it.
String.ReleaseBuffer();</pre>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
Now get rid of that nasty error message &#8211; <span style="color:#0000ff;">error C2664: &#8216;Hello&#8217; : cannot convert parameter 1 from &#8216;class CString&#8217; to &#8216;char *&#8217;</span>. <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img class="alignnone size-medium wp-image-51" title="beginnerseries" src="http://weseetips.files.wordpress.com/2008/03/beginnerseries.jpg?w=215" alt="" width="215" height="32" /><br />
Targeted Audience &#8211; Beginners.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2008/12/17/how-to-convert-cstring-to-char-or-lptstr/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to set Transparent Dialogs?</title>
		<link>http://weseetips.com/2008/10/07/how-to-set-transparent-dialogs/</link>
		<comments>http://weseetips.com/2008/10/07/how-to-set-transparent-dialogs/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 20:46:51 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[MFC]]></category>
		<category><![CDATA[dialog transparency]]></category>
		<category><![CDATA[GetWindowLong()]]></category>
		<category><![CDATA[HG Wells]]></category>
		<category><![CDATA[layered windows]]></category>
		<category><![CDATA[LWA_ALPHA]]></category>
		<category><![CDATA[set window transparency]]></category>
		<category><![CDATA[SetLayeredWindowAttributes()]]></category>
		<category><![CDATA[SetWindowLong()]]></category>
		<category><![CDATA[the invisible man]]></category>
		<category><![CDATA[transparent dialog]]></category>
		<category><![CDATA[window transparency]]></category>
		<category><![CDATA[WS_EX_LAYERED]]></category>

		<guid isPermaLink="false">http://weseetips.wordpress.com/?p=510</guid>
		<description><![CDATA[&#8220;The Invisible Man&#8221; by HG Wells. I still remember reading the translated version of that classic, when i was a kid. And even thought to conduct some experiments to become invisible. You could guess, what happened then. I couldn&#8217;t. But now I feel happy that atleast I could find a magic portion which can make [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.wordpress.com/files/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
&#8220;<strong><span style="color:#0000ff;">The Invisible Man</span></strong>&#8221; by <span style="color:#0000ff;">HG Wells</span>. I <span style="color:#0000ff;">still remember reading the translated version of that classic</span>, when <span style="color:#0000ff;">i was a kid</span>. And <span style="color:#0000ff;">even thought to conduct some experiments to become invisible.</span> You could guess, what happened then. <img src='http://weseetips.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I couldn&#8217;t. <span style="color:#0000ff;">But now I feel happy</span> that atleast <span style="color:#0000ff;">I could find</span> a <span style="color:#0000ff;">magic portion</span> which <span style="color:#0000ff;">can make dialogs invisible.</span> <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />   Well, how to change the transparency of dialogs?</p>
<p><img class="alignnone size-full wp-image-517" title="transparentdialog" src="http://weseetips.wordpress.com/files/2008/10/transparentdialog.jpg" alt="" width="510" height="389" /></p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.wordpress.com/files/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
The secret is <span style="color:#0000ff;">Layered windows</span>. For that you&#8217;ve to enable <span style="color:#0000ff;">WS_EX_LAYERED</span> style and set the <span style="color:#0000ff;">alpha </span>of dialog by calling <span style="color:#0000ff;">SetLayeredWindowAttributes()</span>. See the code snippet below.</p>
<pre>// Enable WS_EX_LAYERED window extended style.
LONG ExtendedStyle = GetWindowLong( GetSafeHwnd(),
                                    GWL_EXSTYLE );
SetWindowLong( GetSafeHwnd(),
               GWL_EXSTYLE,
               ExtendedStyle | WS_EX_LAYERED );

// Select the transparency percentage.
// The alpha will be calculated accordingly.
double TransparencyPercentage = 50.0;

// Set the alpha for transparency.
// 0 is transparent and 255 is opaque.
double fAlpha = TransparencyPercentage * ( 255.0 /100 );
BYTE byAlpha = static_cast&lt;BYTE&gt;( fAlpha );
SetLayeredWindowAttributes( GetSafeHwnd(),
                            0,
                            byAlpha,
                            LWA_ALPHA );</pre>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.wordpress.com/files/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
<span style="color:#0000ff;">Layered windows are available</span> from <span style="color:#0000ff;">Windows 2000 onwards.</span> So don&#8217;t forget to add <strong><span style="color:#0000ff;">_WIN32_WINNT=0&#215;0500 </span></strong>to project settings for preparing the dialog invisible portion. <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img class="alignnone size-medium wp-image-53" title="intermediateseries" src="http://weseetips.wordpress.com/files/2008/03/intermediateseries.jpg?w=248" alt="" width="248" height="32" /><br />
Targeted Audience &#8211; Intermediate.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2008/10/07/how-to-set-transparent-dialogs/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to adjust the drop down width of ComboBox?</title>
		<link>http://weseetips.com/2008/10/05/how-to-adjust-the-drop-down-width-of-combobox/</link>
		<comments>http://weseetips.com/2008/10/05/how-to-adjust-the-drop-down-width-of-combobox/#comments</comments>
		<pubDate>Sun, 05 Oct 2008 18:44:37 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[MFC]]></category>
		<category><![CDATA[adjust combobox dropdown width]]></category>
		<category><![CDATA[CB_SETDROPPEDWIDTH]]></category>
		<category><![CDATA[CCombobox]]></category>
		<category><![CDATA[change combobox dropdown width]]></category>
		<category><![CDATA[combobox dropdown width]]></category>
		<category><![CDATA[combobox width]]></category>
		<category><![CDATA[SendMessage]]></category>

		<guid isPermaLink="false">http://weseetips.wordpress.com/?p=499</guid>
		<description><![CDATA[Combobox is good, because they utilize less space and at the same time they can show a list of options. But did you noticed one thing? By default the dropdown width of combobox is same as the width of combobox itself. If you add a loooong string to combobox, it will be displayed partially in [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.wordpress.com/files/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
<span style="color:#0000ff;">Combobox is good</span>, because <span style="color:#0000ff;">they utilize less space </span>and <span style="color:#0000ff;">at the same time they can show a list of options</span>. But did you noticed one thing? <span style="color:#0000ff;">By default the dropdown width of combobox is same as the width of combobox itself.</span> <span style="color:#0000ff;">If you add a loooong string to combobox</span>, it will be <span style="color:#0000ff;">displayed partially in the drop down list.</span> So how to stretch the with of dropdown list of combobox?</p>
<p><img class="alignnone size-full wp-image-506" title="ComboBox" src="http://weseetips.wordpress.com/files/2008/10/comboboxdropdownwidth.jpg" alt="" width="400" height="267" /></p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.wordpress.com/files/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
<span style="color:#0000ff;">If you are using MFC,</span> you could use the api &#8211; <span style="color:#0000ff;">CComboBox::SetDroppedWidth()</span> or <span style="color:#0000ff;">else </span>you could use <span style="color:#0000ff;">the message CB_SETDROPPEDWIDTH</span>. <span style="color:#0000ff;">First of all you&#8217;ve to iterate all strings</span> in the combobox list <span style="color:#0000ff;">and find out the required width.</span> Then <span style="color:#0000ff;">set the new drop down width</span> of combobox. See the MFC code snippet for doing so. Code snippet is taken from MSDN and has been modified appropriately.</p>
<pre>void CComboBoxDemoDlg::AdjustDropDownWidth()
{
    // Find the longest string in the combo box.
    CComboBox* pComboBox =
        ( CComboBox* ) GetDlgItem( IDC_CMB_STRINGS );
    int MaxWidth = 0;
    CDC* pDC = pComboBox-&gt;GetDC();

    // Iterate through all strings in Combobox and get MaxWidth
    CString String;
    CSize TextSize;
    for ( int Index = 0; Index &lt; pComboBox-&gt;GetCount(); Index++ )
    {
        // Get n'th string.
        pComboBox-&gt;GetLBText( Index, String );

        // Get TextExtend
        TextSize = pDC-&gt;GetTextExtent( String );

        // Get MaxWidth.
        if( TextSize.cx &gt; MaxWidth )
        {
            MaxWidth = TextSize.cx;
        }
    }

    pComboBox-&gt;ReleaseDC( pDC );

    // Adjust the width for the vertical scroll bar and
    // the left and right border.
    MaxWidth += ::GetSystemMetrics(SM_CXVSCROLL) +
                2 * ::GetSystemMetrics(SM_CXEDGE);

    // Set the dropdown width of combobox.
    pComboBox-&gt;SetDroppedWidth( MaxWidth );
}</pre>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.wordpress.com/files/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
You could achieve the same by sending <span><span style="color:#0000ff;">CB_SETDROPPEDWIDTH</span> by using <span style="color:#0000ff;">SendMessage()</span>.<br />
</span></p>
<p><img class="alignnone size-medium wp-image-53" title="intermediateseries" src="http://weseetips.wordpress.com/files/2008/03/intermediateseries.jpg?w=248" alt="" width="248" height="32" /><br />
Targeted Audience &#8211; Intermediate.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2008/10/05/how-to-adjust-the-drop-down-width-of-combobox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to disable maximizing the dialog from Task manager?</title>
		<link>http://weseetips.com/2008/08/20/how-to-disable-maximizing-the-dialog-from-task-manager/</link>
		<comments>http://weseetips.com/2008/08/20/how-to-disable-maximizing-the-dialog-from-task-manager/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 17:42:13 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[MFC]]></category>
		<category><![CDATA[disable dialog maximize task manager]]></category>
		<category><![CDATA[disable maximize dialog]]></category>
		<category><![CDATA[maixmize dialog taskmgr]]></category>
		<category><![CDATA[maximize dialog task manager]]></category>
		<category><![CDATA[MINMAXINFO]]></category>
		<category><![CDATA[OnGetMinMaxInfo]]></category>
		<category><![CDATA[WM_GETMINMAXINFO]]></category>

		<guid isPermaLink="false">http://weseetips.wordpress.com/?p=395</guid>
		<description><![CDATA[Its not mandatory for every windows citizen to have maximize button. For instance, Windows calculator. But do you know that via taskmgr we could maximize any dialogs? Even you can maximize the dialog which doesn&#8217;t have maximize style. Its a master piece of QA team to make the dialog look weired. Well how to prevent [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /></p>
<p>Its <span style="color:#0000ff;">not mandatory</span> for <span style="color:#0000ff;">every windows citizen</span> to have <span style="color:#0000ff;">maximize button</span>. <img src='http://weseetips.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  For instance, <span style="color:#0000ff;">Windows calculator</span>. But do you know that <span style="color:#0000ff;">via taskmgr we could maximize any dialogs</span>? <span style="color:#0000ff;">Even </span>you can <span style="color:#0000ff;">maximize the dialog</span> which <span style="color:#0000ff;">doesn&#8217;t have maximize style</span>. Its a master piece of QA team to make the dialog look weired. Well how to prevent it?</p>
<p><a href="http://siteground205.com/~weseetip/wp-content/uploads/2008/08/taskmgrmaximize.jpg"><img class="alignnone size-full wp-image-399" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/08/taskmgrmaximize.jpg" alt="" width="508" height="492" /></a></p>
<p><img class="alignnone size-medium wp-image-12" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
You can do it by handling &#8211; <span style="color:#0000ff;">WM_GETMINMAXINFO</span> message. <span style="color:#0000ff;">Before resizing</span>, <span style="color:#0000ff;">this message is fired</span> to the dialog t<span style="color:#0000ff;">o get the minimum and maximum window dimensions</span>. Since, we don&#8217;t need to change our dimensions, <span style="color:#0000ff;">we have to set the max dimensions as current window dimension</span>. Have a look at the code snippet.</p>
<pre>// Message map
BEGIN_MESSAGE_MAP(CRabbitDlg, CDialog)
    ...
    ON_WM_GETMINMAXINFO()
END_MESSAGE_MAP()

void CRabbitDlg::OnGetMinMaxInfo( MINMAXINFO FAR* pMinMaxInfo )
{
    // Window rect.
    RECT rect = { 0 };
    GetWindowRect( &amp;rect );
    CRect WindowRect( &amp;rect );

    // Set the maximum size. Used while maximizing.
    pMinMaxInfo-&gt;ptMaxSize.x = WindowRect.Width();
    pMinMaxInfo-&gt;ptMaxSize.y = WindowRect.Height();

    // Set the x,y position after maximized.
    pMinMaxInfo-&gt;ptMaxPosition.x = rect.left;
    pMinMaxInfo-&gt;ptMaxPosition.y = rect.top;
}</pre>
<p><img class="alignnone size-medium wp-image-18" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
There is one <span style="color:#0000ff;">small known issue</span> &#8211; if we maximize via taskmgr, the window remains same, but <span style="color:#0000ff;">the title bar will be painted like maximized</span>.</p>
<p><img class="alignnone size-medium wp-image-53" src="http://weseetips.files.wordpress.com/2008/03/intermediateseries.jpg?w=248" alt="" width="248" height="32" /><br />
Targeted Audience &#8211; Intermediate.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2008/08/20/how-to-disable-maximizing-the-dialog-from-task-manager/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to handle F1 or help in application?</title>
		<link>http://weseetips.com/2008/08/17/how-to-handle-f1-or-help-in-application/</link>
		<comments>http://weseetips.com/2008/08/17/how-to-handle-f1-or-help-in-application/#comments</comments>
		<pubDate>Sun, 17 Aug 2008 18:40:19 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[MFC]]></category>
		<category><![CDATA[Windows APIs]]></category>
		<category><![CDATA[application help]]></category>
		<category><![CDATA[F1]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[how to handle application help]]></category>
		<category><![CDATA[mayday]]></category>
		<category><![CDATA[OnHelpInfo()]]></category>
		<category><![CDATA[ON_WM_HELPINFO()]]></category>
		<category><![CDATA[WM_HELP]]></category>

		<guid isPermaLink="false">http://weseetips.wordpress.com/?p=378</guid>
		<description><![CDATA[Help is inevitable part of every windows application. The first function key &#8211; F1 itself is assigned as help in every application. Well, how to handle the user&#8217;s &#8220;Mayday&#8221; call in application? Basically you&#8217;ve to handle the WM_HELP message. When you press F1 the WM_HELP message will be posted to your window. To handle this [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
<span style="color:#0000ff;">Help is inevitable part </span>of every <span style="color:#0000ff;">windows application</span>. The first function key &#8211; <span style="color:#0000ff;">F1</span> itself is <span style="color:#0000ff;">assigned as help</span> in every application. Well, <span style="color:#0000ff;">how to handle</span> the user&#8217;s <span style="color:#0000ff;">&#8220;Mayday&#8221; call</span> in application?</p>
<p><img class="alignnone size-full wp-image-382" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/08/help.jpg" alt="" width="320" height="178" /></p>
<p><img class="alignnone size-medium wp-image-12" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
Basically you&#8217;ve to handle the <span style="color:#0000ff;">WM_HELP</span> message. When you press<span style="color:#0000ff;"> F1</span> the <span style="color:#0000ff;">WM_HELP</span> message <span style="color:#0000ff;">will be posted to your window.</span> To handle this via <span style="color:#0000ff;">MFC</span>, Add <span style="color:#0000ff;">ON_WM_HELPINFO()</span> to message map <span style="color:#0000ff;">and implement</span> <span style="color:#0000ff;">OnHelpInfo()</span> in your dialog. Have a look at the following code snippet.</p>
<pre>// Add ON_WM_HELPINFO() to your message map.
BEGIN_MESSAGE_MAP(CYourDialog, CDialog)
   ...
   ON_WM_HELPINFO()
END_MESSAGE_MAP()

// Add this function to your dialog.
BOOL CYourDialog::OnHelpInfo( HELPINFO* HelpInfo)
{
   // Handle your help request here.
   return TRUE;
}</pre>
<p><img class="alignnone size-medium wp-image-18" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
Well, the <span style="color:#0000ff;">only help i used to use is MSDN</span>. If I accidentally launch Windows help, I&#8217;ll kill it immediately by using taskmgr. I don&#8217;t know why I hate it. <img src='http://weseetips.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><img class="alignnone size-medium wp-image-51" src="http://weseetips.files.wordpress.com/2008/03/beginnerseries.jpg?w=215" alt="" width="215" height="32" /><br />
Targeted Audience &#8211; Beginners.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2008/08/17/how-to-handle-f1-or-help-in-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

