<?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>Code Library &#187; Cpp</title>
	<atom:link href="http://www.ucosoft.com/tag/cpp/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ucosoft.com</link>
	<description>Free Source Code and Program Tips</description>
	<lastBuildDate>Thu, 22 Jul 2010 05:17:10 +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>Simple CEdit Validation</title>
		<link>http://www.ucosoft.com/simple-cedit-validation.html</link>
		<comments>http://www.ucosoft.com/simple-cedit-validation.html#comments</comments>
		<pubDate>Wed, 27 Jun 2007 09:41:55 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[CEdit]]></category>
		<category><![CDATA[Cpp]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2007/06/27/simple-cedit-validation.html</guid>
		<description><![CDATA[Sometime you need some CEdit Validation, for example, restricting the data number only. The simple implemetion is to handle the EN_UPDATE notification message. The EN_UPDATE message is useful to handle as it caters for both normal entry and clipboard paste. You can do that in the Dialog or subclass the CEdit class. Here is an [...]]]></description>
			<content:encoded><![CDATA[<p>Sometime you need some CEdit Validation, for example, restricting the data number only.</p>
<p>The simple implemetion is to handle the <strong>EN_UPDATE</strong> notification message. The <strong>EN_UPDATE</strong> message is useful to handle as it caters for both normal entry and clipboard paste. You can do that in the Dialog or subclass the CEdit class.</p>
<p>Here is an example of a derived CEdit class.</p>
<p><coolcode lang="cpp" linenum="no"><br />
class CNumEdit : public CEdit<br />
{<br />
//â€¦.<br />
    afx_msg void OnUpdate();<br />
    //}}AFX_MSG </p>
<p>    DECLARE_MESSAGE_MAP()<br />
private:<br />
    CString m_strLastGood;<br />
}; </p>
<p></coolcode></p>
<p>In the cpp file:</p>
<p> <span id="more-86"></span><br />
<coolcode lang="cpp" linenum="no"><br />
BEGIN_MESSAGE_MAP(CNumEdit, CEdit)<br />
    //{{AFX_MSG_MAP(CNumEdit)<br />
    ON_CONTROL_REFLECT(EN_UPDATE, OnUpdate)<br />
    //}}AFX_MSG_MAP<br />
END_MESSAGE_MAP() </p>
<p>void CNumEdit::OnUpdate()<br />
{<br />
    CString str;<br />
    GetWindowText( str );<br />
    bool bProblem = false;<br />
    for ( int indx = 0; indx < str.GetLength(); indx++ )<br />
    {<br />
        if (( str[indx] < â€˜0â€² ) || ( str[indx] > â€˜9â€²) )<br />
        {<br />
            bProblem = true;<br />
            break;<br />
        }<br />
    }<br />
    if ( bProblem )<br />
    {<br />
        int start, end;<br />
        /* Find the current caret position */<br />
        GetSel( start, end );<br />
        /* Restore the last good text that was entered */<br />
        SetWindowText( m_strLastGood );<br />
        /* Restore the caret */<br />
        SetSel( start-1, end-1, true );<br />
        /* Let the user know */<br />
        MessageBeep( MB_OK );<br />
    }<br />
    else<br />
    {<br />
    /* Store the last good entry string in a member variable of the Hex edit class*/<br />
        m_strLastGood = str;<br />
    }<br />
} </p>
<p></coolcode></p>
<p>At last, you may find one of these meets your needs:</p>
<ul>
<li>http://www.codeproject.com/editctrl/maskededit.asp</li>
<li>http://www.codeproject.com/editctrl/validatingedit.asp</li>
</ul>

	Tags: <strong><a href="http://www.ucosoft.com/tag/cedit" title="CEdit" rel="tag">CEdit</a>, <a href="http://www.ucosoft.com/tag/cpp" title="Cpp" rel="tag">Cpp</a>, <a href="http://www.ucosoft.com/tag/win32mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/simple-cedit-validation.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Draw Bitmap from a bmp File?</title>
		<link>http://www.ucosoft.com/how-to-draw-bitmap-from-a-bmp-file.html</link>
		<comments>http://www.ucosoft.com/how-to-draw-bitmap-from-a-bmp-file.html#comments</comments>
		<pubDate>Fri, 05 Jan 2007 07:06:52 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[Cpp]]></category>
		<category><![CDATA[How-to]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/archives/72.html</guid>
		<description><![CDATA[How to load a bitmap from bmp file and draw it in DC? There are two main steps: Load the bitmap from the file to a memory DC. Paint the content of the memory DC to the one which display the bitmap. In MFC, there is no API to load a bitmap directly from a [...]]]></description>
			<content:encoded><![CDATA[<p>How to load a bitmap from bmp file and draw it in DC?</p>
<p>There are two main steps:</p>
<ul>
<li>Load the bitmap from the file to a memory DC.</li>
<li>Paint the content of the memory DC to the one which display the bitmap.</li>
</ul>
<p>In MFC, there is no API to load a bitmap directly from a file, but you can use a Win32 API: <strong>LoadImage</strong>.<br />
Here is the delaration of LoadImage.</p>
<p><coolcode lang="cpp" linenum="no"><br />
HANDLE LoadImage(<br />
HINSTANCE hinst, //handle to instance, if load from file, it should be NULL<br />
LPCTSTR lpszName, //image resource name or the image file path<br />
UINT uType, //image type<br />
//1. IMAGE_BITMAP<br />
//2. IMAGE_CURSOR<br />
//3. IMAGE_ICON<br />
int cxDesired, //desired width<br />
int cyDesired, //desired height<br />
UINT fuLoad //load options<br />
);<br />
</coolcode></p>
<p>After this,&nbsp; the following steps are similar with loading a bitmap from resource. Here is a short example.</p>
<p><span id="more-72"></span><br />
<coolcode lang="cpp" linenum="no" download="ShowBmp_demo.cpp"><br />
CClientDC dc(this);<br />
CDC *mdc=new CDC;<br />
mdc->CreateCompatibleDC(&#038;dc);</p>
<p>CBitmap bitmap;<br />
//CBitmap is devived from CGdiObject<br />
//It has a handle:m_hObject, which can obtained with LoadImage<br />
bitmap.m_hObject=(HBITMAP)::LoadImage(<br />
   NULL,<br />
   &#8220;b1.bmp&#8221;,<br />
   IMAGE_BITMAP,<br />
   500,<br />
   400,<br />
   LR_LOADFROMFILE);</p>
<p>mdc->SelectObject(bitmap);<br />
CRect rect;<br />
GetClientRect(&#038;rect);<br />
//BitBlt()<br />
dc.BitBlt(0,0,rect.right,rect.bottom,mdc,0,0,SRCCOPY);</p>
<p>//release mdc<br />
delete mdc;<br />
</coolcode></p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/bitmap" title="Bitmap" rel="tag">Bitmap</a>, <a href="http://www.ucosoft.com/tag/cpp" title="Cpp" rel="tag">Cpp</a>, <a href="http://www.ucosoft.com/tag/how-to" title="How-to" rel="tag">How-to</a>, <a href="http://www.ucosoft.com/tag/win32mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-draw-bitmap-from-a-bmp-file.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to change the row height of CListCtrl</title>
		<link>http://www.ucosoft.com/how-to-change-the-row-height-of-clistctrl.html</link>
		<comments>http://www.ucosoft.com/how-to-change-the-row-height-of-clistctrl.html#comments</comments>
		<pubDate>Wed, 06 Dec 2006 02:34:32 +0000</pubDate>
		<dc:creator>hamo</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[CListCtrl]]></category>
		<category><![CDATA[Cpp]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/archives/54.html</guid>
		<description><![CDATA[When you&#160;want to change the height of CListCtrl, you need to use an owner-draw version of CListCtrl and change the font of the control. But when&#160;you change the font of&#160;the CListCtrl, the control or its parent window does not get a chance to respecify the height of the rows and the effect will not be [...]]]></description>
			<content:encoded><![CDATA[<p>When you&nbsp;want to change the height of CListCtrl, you need to use an owner-draw version of CListCtrl and change the font of the control. But when&nbsp;you change the font of&nbsp;the CListCtrl, the control or its parent window does not get a chance to respecify the height of the rows and the effect will not be taken. The reason is that No WM_MEASUREITEM message is sent to the controls parent window. </p>
<p>The following article from <a href="http://www.codeproject.com" rel="nofollow">CodeProject</a>&nbsp;provided a good solution.</p>
<p><!--adsensex-->
<ul>
<li><a href="http://www.codeproject.com/listctrl/changerowheight.asp">Changing Row Height in an owner drawn Control</a></li>
</ul>
<p>And there is a similar&nbsp;article on CodeGuru.</p>
<ul>
<li><a href="http://www.codeguru.com/Cpp/controls/listview/advanced/article.php/c1013" rel="nofollow">Changing row height in owner drawn control</a></li>
</ul>

	Tags: <strong><a href="http://www.ucosoft.com/tag/clistctrl" title="CListCtrl" rel="tag">CListCtrl</a>, <a href="http://www.ucosoft.com/tag/cpp" title="Cpp" rel="tag">Cpp</a>, <a href="http://www.ucosoft.com/tag/win32mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-change-the-row-height-of-clistctrl.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A powerful math function parser(zz)</title>
		<link>http://www.ucosoft.com/a-powerful-math-function-parser.html</link>
		<comments>http://www.ucosoft.com/a-powerful-math-function-parser.html#comments</comments>
		<pubDate>Wed, 29 Nov 2006 16:12:30 +0000</pubDate>
		<dc:creator>hamo</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[Cpp]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[parser]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/archives/46.html</guid>
		<description><![CDATA[by Andreas Jdger The inspiration to write this code was to have an easy-to-use parser for functions given as string. You have a string like cos(x)-7*x/(1+x) and you want to compute some values, maybe for displaying the graph of the function. You can write code like this: CFunction* fkt = CFunction::Parse(&#8220;cos(x)-7*x/(1+x)&#8221;); long double y = [...]]]></description>
			<content:encoded><![CDATA[<p> by <b>Andreas Jdger </b></P></p>
<p>The inspiration to write this code was to have an easy-to-use parser for functions given as string. You have a string like </P><br />
<coolcode linenum="no"><br />
cos(x)-7*x/(1+x)<br />
</coolcode><br />
<P><br />
and you want to compute some values, maybe for displaying the graph of the function. You can write code like this:</P><br />
<coolcode lang="cpp" linenum="no"><br />
CFunction<long double>* fkt =<br />
  CFunction<long double>::Parse(&#8220;cos(x)-7*x/(1+x)&#8221;);</p>
<p>long double y = fkt->Execute(1.5);<br />
</coolcode><br />
<P><br />
There are lots of definitions in the background, but the result is easy and fast! There is a one-time pasing step to construct the function tree, and function evaluations are only calls of standard math functions like sin, +, *, sqrt. When you want to know details about the implementaion, you should look into the source code. It would be too complex to describe the parsing algorithm here.<br />
</P></p>
<p><strong>Download here: <span id="more-46"></span></strong><br />
<!--adsense--><br />
<a href="/wp-content/download/FunctionParser_demo_app.zip">Download demo source</a><br />
<a href="/wp-content/download/FunctionParser_demo_src.zip">Download demo app</a></p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/cpp" title="Cpp" rel="tag">Cpp</a>, <a href="http://www.ucosoft.com/tag/how-to" title="How-to" rel="tag">How-to</a>, <a href="http://www.ucosoft.com/tag/math" title="math" rel="tag">math</a>, <a href="http://www.ucosoft.com/tag/parser" title="parser" rel="tag">parser</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/a-powerful-math-function-parser.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A good article about Using auto_ptr Effectively</title>
		<link>http://www.ucosoft.com/using-auto_ptr-effectively-part-1.html</link>
		<comments>http://www.ucosoft.com/using-auto_ptr-effectively-part-1.html#comments</comments>
		<pubDate>Sat, 25 Nov 2006 14:10:24 +0000</pubDate>
		<dc:creator>hamo</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[Cpp]]></category>
		<category><![CDATA[How-to]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/archives/37.html</guid>
		<description><![CDATA[Here is only a short introduction of the article, if you are interested, please goto the author&#8217;s website for the full text. Most people have heard of the standard auto_ptr smart pointer facility, but not everyone uses it daily. That&#8217;s a shame, because it turns out that auto_ptr neatly solves common C++ design and coding [...]]]></description>
			<content:encoded><![CDATA[<p><strong><a href="http://www.gotw.ca/publications/using_auto_ptr_effectively.htm">Here is only a short introduction of the article, if you are interested, please goto the author&#8217;s website for the full text.</a></strong></p>
<p>Most people have heard of the standard auto_ptr smart pointer facility, but not everyone uses it daily. That&#8217;s a shame, because it turns out that auto_ptr neatly solves common C++ design and coding problems, and using it well can lead to more robust code. This article shows how to use auto_ptr correctly to make your code safer&#8211;and how to avoid the dangerous but common abuses of auto_ptr that create intermittent and hard-to-diagnose bugs. </p>
<h2>Why Call It an &quot;Auto&quot; Pointer? </h2>
<p><!--adsense--></p>
<p>auto_ptr is just one of a wide array of possible smart pointers. Many commercial libraries provide more sophisticated kinds of smart pointers that can do wild and wonderful things, from managing reference counts to providing advanced proxy services. Think of the Standard C++ auto_ptr as the Ford Escort of smart pointers: A simple general-purpose smart pointer that doesn&#8217;t have all the gizmos and luxuries of special-purpose or high-performance smart pointers, but that does many common things well and is perfectly suitable for regular daily use. </p>
<p>What auto_ptr does is own a dynamically allocated object and perform automatic cleanup when the object is no longer needed. Here&#8217;s a simple example of code that&#8217;s unsafe without auto_ptr:</p>
<p><a href="http://www.gotw.ca/publications/using_auto_ptr_effectively.htm">Visit the author&#8217;s website for more details.</a></p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/cpp" title="Cpp" rel="tag">Cpp</a>, <a href="http://www.ucosoft.com/tag/how-to" title="How-to" rel="tag">How-to</a>, <a href="http://www.ucosoft.com/tag/win32mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/using-auto_ptr-effectively-part-1.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Write and read binary data in VARIANT</title>
		<link>http://www.ucosoft.com/write-and-read-binary-data-in-variant.html</link>
		<comments>http://www.ucosoft.com/write-and-read-binary-data-in-variant.html#comments</comments>
		<pubDate>Wed, 22 Nov 2006 08:51:33 +0000</pubDate>
		<dc:creator>hamo</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[Cpp]]></category>
		<category><![CDATA[Database]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[Program]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/archives/30.html</guid>
		<description><![CDATA[We offen need to store some binary data in the mdb database, thus we have to transefer the data by VARIANT structure.But how to read from binary data from VARIANT or write to? Here is a solution by safe array of VARRIANT. BOOL GetBinaryFromVariant(COleVariant &#038; ovData, BYTE ** ppBuf, unsigned long * pcBufLen) { BOOL [...]]]></description>
			<content:encoded><![CDATA[<p>We offen need to store some binary data in the mdb database, thus we have to transefer the data by VARIANT structure.<br />But how to read from binary data from VARIANT or write to? Here is a solution by safe array of VARRIANT.</p>
<p> <span id="more-30"></span></p>
<p><coolcode lang="cpp" linenum="off" download="src.cpp"><br />
BOOL GetBinaryFromVariant(COleVariant &#038; ovData, BYTE ** ppBuf,  unsigned long * pcBufLen)<br />
{<br />
 BOOL fRetVal = FALSE;<br />
 //Binary data is stored in the variant as an array of unsigned char<br />
 if(ovData.vt == (VT_ARRAY|VT_UI1))  // (OLE SAFEARRAY)<br />
 {<br />
  //Retrieve size of array<br />
  *pcBufLen = ovData.parray->rgsabound[0].cElements;<br />
  *ppBuf = new BYTE[*pcBufLen]; //Allocate a buffer to store the data<br />
  if(*ppBuf != NULL)<br />
  {<br />
   void * pArrayData;<br />
   //Obtain safe pointer to the array<br />
   SafeArrayAccessData(ovData.parray,&#038;pArrayData);<br />
   //Copy the bitmap into our buffer<br />
   memcpy(*ppBuf, pArrayData, *pcBufLen);  //Unlock the variant data<br />
   SafeArrayUnaccessData(ovData.parray);<br />
   fRetVal = TRUE;<br />
  }<br />
 }<br />
 return fRetVal;<br />
}<br />
</coolcode><br />
<!--adsense#468l--><br />
<coolcode lang="cpp" linenum="off" download="src.cpp"><br />
BOOL PutBinaryIntoVariant(COleVariant * ovData, BYTE * pBuf,unsigned long cBufLen)<br />
{<br />
 BOOL fRetVal = FALSE;<br />
 VARIANT var;<br />
 VariantInit(&#038;var); 	//Initialize our variant<br />
 //Set the type to an array of unsigned chars (OLE SAFEARRAY)<br />
 var.vt = VT_ARRAY | VT_UI1;<br />
 //Set up the bounds structure<br />
 SAFEARRAYBOUND  rgsabound[1];<br />
 rgsabound[0].cElements = cBufLen;<br />
 rgsabound[0].lLbound = 0;<br />
 //Create an OLE SAFEARRAY<br />
 var.parray = SafeArrayCreate(VT_UI1,1,rgsabound);<br />
 if(var.parray != NULL)<br />
 {<br />
  void * pArrayData = NULL;<br />
  //Get a safe pointer to the array<br />
  SafeArrayAccessData(var.parray,&#038;pArrayData);<br />
  //Copy data to it<br />
  memcpy(pArrayData, pBuf, cBufLen);<br />
  //Unlock the variant data<br />
  SafeArrayUnaccessData(var.parray);<br />
  *ovData = var;<br />
  // Create a COleVariant based on our variant<br />
  VariantClear(&#038;var);<br />
  fRetVal = TRUE;<br />
 }<br />
 return fRetVal;<br />
}</p>
<p></coolcode></p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/cpp" title="Cpp" rel="tag">Cpp</a>, <a href="http://www.ucosoft.com/tag/database" title="Database" rel="tag">Database</a>, <a href="http://www.ucosoft.com/tag/how-to" title="How-to" rel="tag">How-to</a>, <a href="http://www.ucosoft.com/tag/program" title="Program" rel="tag">Program</a>, <a href="http://www.ucosoft.com/tag/win32mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/write-and-read-binary-data-in-variant.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

