Free Source Code and Program Tips
Win32/MFC
MFC sample code, MFC projects
Simple CEdit Validation
Jun 27th
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
CComModule in porting ATL DLL project to VC8
Jun 22nd
When migrating an ATL project from vc6 to vc8, you will get a problem about CComModule. Problem: In vc6, there is such a declaration in stdafx.h as: extern CComModule _Module; and in the main module: CComModule _Module; But when you complie it in vc8, the following errors apears: c:\temp\myatl\stdafx.h(24) : error C2146: syntax error :
How to check whether the window is in minimise or Maximise mode
Mar 21st
CWnd::IsIconic BOOL IsIconic( ) const; Return Value Nonzero if CWnd is minimized; otherwise 0. Remarks Specifies whether CWnd is minimized (iconic). Example // This code, normally emitted by the AppWizard for a dialog-based // project for the dialog’s WM_PAINT handler, runs only if the // window is iconic. The window erase the icon’s area, then
sscanf with CString
Mar 20th
Problem: In the C time, we used to use sscanf to read data from string as following: char strUserName[20], strPassword[20]; // if the content of m_recvBuff is “Microsoft Bill”. sscanf((const char *)m_recvBuff, “%s %s”, strUserName, strPassword); And when you first get CString in sight, you may write the similar code: CString strUserName, strPassword; // if the
How to read sectors of a physical drive under Win32?
Jan 15th
How to read the sectors of physical drive under win32? The API ReadFile is most useful function, and with it, you can read the physical sectors directly. Here is a sample function, BOOL ReadSectors(…) BOOL ReadSectors( BYTE bDrive, //drive index DWORD dwStartSector, //start sector WORD wSectors, //sectors number LPBYTE lpSectBuff) {  if (bDrive == 0)
How to get a fixed code for serial number(2)
Jan 10th
I have post an article about “How to get a fixed code for serial number” at http://www.ucosoft.com/archives/51.html. In that article, I suggest you try WMI class to retrieve some hardware ID. But there is some limitation of this method. The WMI redist package is not always available on user’s system, for example, Windows NT4 and Windows
How to Draw Bitmap from a bmp File?
Jan 4th
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