MFC

PostHeaderIcon Some of the Best Open Source Projects in VC++ & MFC

List of Best Open Source Projects Written in VC++/MFC

  1. 7-Zip (http://sourceforge.net/projects/sevenzip/) :
    7-Zip is a file archiver with a high compression ratio. The program supports 7z, ZIP, CAB, RAR, ARJ, LZH, CHM, GZIP, BZIP2, Z, TAR, CPIO, RPM and DEB formats. Compression ratio in the new 7z format is 30-50% better than ratio in ZIP format.
  2. eMule (http://sourceforge.net/projects/emule/):
    eMule is a filesharing client which is based on the eDonkey2000 network but offers more features than the standard client.
  3. eMule Plus (http://sourceforge.net/projects/emuleplus/) :
    eMule Plus is an evolution of the original eMule project, created to improve its abilities and features, in both work efficiency and user interface.
  4. eMule Morph (http://sourceforge.net/projects/emulemorph/):
    eMule Morph Mod – eMule Modding Project.
  5. FileZilla (http://sourceforge.net/projects/filezilla/):
    FileZilla is a fast FTP and SFTP client for Windows with a lot of features. FileZilla Server is a reliable FTP server.
  6. KeePass Password Safe (http://sourceforge.net/projects/keepass/):
    KeePass Password Safe is a free, open source, light-weight and easy-to-use password manager for Windows. You can store your passwords in a highly-encrypted database, which is locked with one master password or key file.
  7. K-Meleon (http://sourceforge.net/projects/kmeleon/):
    K-Meleon is a fast and customizable web browser that can be used instead of Internet Explorer on Windows. Powered by the same Gecko engine as the Firefox and Mozilla browsers, K-Meleon provides users with a secure browsing experience.
  8. MiKTeX (http://sourceforge.net/projects/miktex/):
    MiKTeX is an up-to-date implementation of TeX & Friends for Windows (all current variants).
  9. MyNapster (http://sourceforge.net/projects/mynapster/):
    MyNapster is a Win32 client using Gnutella and IRC for chat. It is based on Gnucleus and utilizes MFC (works with WINE).
  10. Nokia Composer (http://sourceforge.net/projects/nokiacomposer/):
    This is a Win32, VC++ MFC application to manage Nokia mobile phones melodies. Includes VC++ source code and Rational Rose UML model. Read the rest of this entry »
116,454 views

PostHeaderIcon MFC Convert DWORD IP Address to CString(Dotted IP Notation)

CString ConvertIP(DWORD ip)
{
	unsigned char a, b, c, d;
	d = ip & 0xFF;
	c = ( ip >> 8 ) & 0xFF;
	b = ( ip >> 16 ) & 0xFF;
	a = ( ip >> 24 ) & 0xFF;  

	CString url;
	url.Format(_T("%u.%u.%u.%u"), a, b, c, d);
	return url;
}
111,424 views

PostHeaderIcon Win32 Worker Thread without UI

When you want to create a worker thread with Win32 API.

first,define a function like this: UNIT ThreadFunc(LPVOID pParam) ,the detail of it you can find on MSDN;

second,call the ThreadFunc with the Win32API – AfxBeginThread;

last,put the AfxBeginThread API in the right place.

You can find the AfxBeginThread API declarations on MSDN:

CWinThread* AfxBeginThread(
   AFX_THREADPROC pfnThreadProc,
   LPVOID pParam,
   int nPriority = THREAD_PRIORITY_NORMAL,
   UINT nStackSize = 0,
   DWORD dwCreateFlags = 0,
   LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL
);
CWinThread* AfxBeginThread(
   CRuntimeClass* pThreadClass,
   int nPriority = THREAD_PRIORITY_NORMAL,
   UINT nStackSize = 0,
   DWORD dwCreateFlags = 0,
   LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL
);

The first form of AfxBeginThread creates a worker thread. The second form creates a user-interface thread[From MSDN].

Read the rest of this entry »

15,497 views

PostHeaderIcon Create UI thread when the application startup

In this demo, I use win32 api to create thread.absolutely,I’ll use CWinThread in other demos.

The demo shows a  UI thread working when the application’s main thread startup.

Sometimes,the application may be large,If you have a friendly UI thread,it looks good. Especially if the application startup slowly.

One defect of this demo is I Just give the UI thread 7.5 seconds,the time depends on your application size.

The demo depends on the time but not other event messages,I will improve it to make it work better(change the progroess bar and the message event ).

OK,let’s first see the result of this:

UI thread

UI thread

The UI thread is working at the same time the application startup,of course,they are two different threads.

You can treat the main thread as the worker thread,In fact,it has its own interface thread and worker thread.

Have a startup UI thread,you have the follow steps to do:

1.Creat a Class based on CDialog(with CProgressCtrl and a static text),here I call this class name as CWin32ProcessDlg;
2.Declare the CWin32ProcessDlg variable at the appropriate place in your application;
3.Declare and define the UI thread function(in this thread create the startup UI thread dialog);
4.Create the UI thread in your application init part;
5.Test it.

Read the rest of this entry »

115,190 views

PostHeaderIcon A MFC Number Edit

To write A number edit class  in MFC is simple, but to achieve the class like the system itself is a little difficult.

let us see a demo with picture:

number edit

number edit

This edit is same with windows system edit, it only support decimal number.

Actually, it is easy, just a utility class.

Let us see the definition of  CNumberEdit

class CNumberEdit : public CEdit , public CDecimalSupport
{
protected:
	afx_msg void OnChar( UINT nChar, UINT nRepCnt, UINT nFlags );
	DECLARE_MESSAGE_MAP()
};

In the above code fragments, you can find a new Class, CDecimalSupport this one is really behind the attacks:

class CDecimalSupport
{
public:
	/// the locale dependant decimal separator
	TCHAR m_DecimalSeparator[5];
	/// the locale dependant negative sign
	TCHAR m_NegativeSign[6];

#ifdef BEGIN_MSG_MAP
	BEGIN_MSG_MAP(CDecimalSupport)

		ALT_MSG_MAP(8)
		MESSAGE_HANDLER(WM_CHAR, OnChar)
		MESSAGE_HANDLER(WM_PASTE, OnPaste)
	END_MSG_MAP()
#endif

        /// \brief Initialize m_DecimalSeparator and m_NegativeSign
	/// \remarks calls InitDecimalSeparator and InitNegativeSign
	CDecimalSupport();

	/// \brief sets m_DecimalSeparator
	/// \remarks calls GetLocaleInfo with LOCALE_SDECIMAL to set m_DecimalSeparator
	/// \param[in] Locale the locale parameter (see GetLocaleInfo)
	/// \return the number of TCHARs written to the destination buffer
	int InitDecimalSeparator(LCID Locale = LOCALE_USER_DEFAULT);

	/// \brief sets m_NegativeSign
	/// \remarks calls GetLocaleInfo with LOCALE_SNEGATIVESIGN to set m_NegativeSign
	/// \param[in] Locale the locale parameter (see GetLocaleInfo)
	/// \return the number of TCHARs written to the destination buffer
	int InitNegativeSign(LCID Locale = LOCALE_USER_DEFAULT);

	/// callback for the WM_PASTE message
	/// validates the input
	/// \param uMsg
	/// \param wParam
	/// \param lParam
	/// \param[out] bHandled true, if the text is a valid number
	/// \return 0
	LRESULT OnPaste(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/,BOOL& bHandled);

	/// callback for the WM_CHAR message
	/// handles the decimal point and the negative sign keys
	/// \param uMsg
	/// \param[in] wParam contains the pressed key
	/// \param lParam
	/// \param[out] bHandled true, if the key press was handled in this function
	/// \return 0
	LRESULT OnChar(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& bHandled);

        /// converts the controls text to double
	/// \param[out] d the converted value
	/// \return true on success
	bool GetDecimalValue(double& d) const;

        /// converts a string to double
	/// \remarks the decimal separator and the negative sign may change in the string
	/// \param[in, out] szBuff the string to convert
	/// \param[out] d the converted value
	/// \return true on success
	bool TextToDouble(TCHAR* szBuff, double& d) const;

	/// sets a number as the controls text
	/// \param[in] d the value
	/// \param[in] count digits after the decimal point
	void SetFixedValue(double d, int count);

	/// sets a number as the controls text
	/// \param[in] d the value
	/// \param[in] count total number of digits
	void SetDecimalValue(double d, int count);

	/// sets a number as the controls text
	/// \param[in] d the value
	/// \remarks the total number of digits is calculated using the GetLimitText function
	void SetDecimalValue(double d);

	/// sets the controls text
	/// \param[in] digits array containing the digits
	/// \param[in] decimal_pos the position of the decimal point
	/// \param[in] sign 1 if negative
	void DisplayDecimalValue(const char* digits, int decimal_pos, int sign);

	/// convert a digit array to string
	/// \param[out] szBuff target buffer for output
	/// \param[in] buflen maximum characters in output buffer
	/// \param[in] digits array containing the digits
	/// \param[in] decimal_pos the position of the decimal point
	/// \param[in] sign 1 if negative
	void DecimalToText(TCHAR* szBuff, size_t buflen ,
        const char* digits, int decimal_pos, int sign) const;
};

Here is the source CDecimalSupport Class, you can download it and use it in your project~

112,634 views

Copyright © 2010 - C++ Technology. All Rights Reserved.

Powered by Jerry | Free Space Provided by connove.com