MFC Extension Class CProductKey

The CProductKey class provides an easy way to enter IDs, PINs, product keys, or so forth. The data to be entered can consist of any number of fields of any length. You can choose a decimal, hexadecimal, or alphanumeric format for the key.

To achieve better readability, a special monospaced font approximately 1.5 times larger than the standard font will be used as the display font. The digit zero will be displayed with a point in the center instead of 0 to avoid cofusion with the letter O. This special font will be embedded in the program as a binary resource. Manual installation or uninstallation of the font isn't necessary. By studying the source code, you can learn the technique to embed customized fonts for temporary use into other programs, too.

Functions are provided to do simple Clipboard operations. After copying a product key to the Clipboard, the items of the product key will be separated by a special delimiter character. The default is the dash. If you choose the binary zero as the delimiter character, the items will not be separated.

CProductKey class members:
Data Types:
enum TYPE {DEC, HEX, ALPHANUM} Type of the product key: decimal, hexadecimal, or alphanumeric (0-9, A-Z).
Public member functions:
bool Copy() const Copies the product key to the Clipboard. Returns true if the product key is complete and has been copied; otherwise, false.
bool Cut() const Copies the product key to the Clipboard. Then, the input fields for the product key will be deleted. Returns true if the product key is complete and has been copied and deleted; otherwise, false.
void Delete() const Deletes the input fields for the product key.
const CString Get() const Returns the product key. The items of the product key will be separated by the delimiter character (as Copy and Cut do).
TYPE GetType() const Returns the type of the product key (decimal, hexadecimal, or alphanumeric).
bool IsComplete() const Returns true if the product key has been completely entered and if it's syntactically correct; otherwise, false.
bool IsEmpty() const Returns true if all input fields for the product key are empty; otherwise, false.
bool IsValid(int ch) const Returns true if ch is a valid character of a product key; otherwise, false.
void LimitText(int nItem = -1, int nChars = 5) const Limits the length of the input field for the item nItem to nChars. If nItem is -1, the length of all input fields will be limited to nChars.
bool Paste() const Copies a product key from the Clipboard into the input fields. The delimiter character will be filtered. Returns true if the product key has been copied successfully; otherwise, false.
bool Set(LPCTSTR pszProductKey) const Copies the product key pszProductKey into the input fields. Returns true if the product key has been copied successfully; otherwise, false.
TCHAR SetDelimiter(TCHAR chDelimiter = _T('-')) Sets the delimiter character to the chDelimiter character. If chDelimiter is _T('\0'), no delimiter character will be used. Returns the delimiter character previously used.

The delimiter character will be used to separate the items of the product key.

CWnd* SetFocus() const Claims the input focus to the input field of the first item. The input focus directs all subsequent keyboard input to this window. Any window that previously had the input focus loses it. Returns a pointer to the window object that previously had the input focus. It is 0 if there is no such window. The returned pointer may be temporary and should not be stored.
TYPE SetType(TYPE type) Sets the type of the product key to type (decimal, hexadecimal, or alphanumeric). Returns the previous type.
bool SubclassDlgItem(UINT nIDOfFirstItem, CWnd* pParent, int nItemCount = 1, int nChars = 5) Subclasses the nItemCount edit controls with the IDs nIDOfFirstItem, nIDOfFirstItem+1, nIDOfFirstItem+2, and so forth. The subclassed edit controls represent the input fields for the nItemCount items of the product key. The maximum text length of each input field is nChars.


About the Author

Thomas Holte

Born in 1953 I'm a passionate programmer since 30 years. I'm employed as a software developer at a large company in Nuremberg, Germany. My hobbies are programming (what else) and digital photography.

Downloads

Comments

  • Nice,but

    Posted by Cui Sheng on 03/12/2004 07:08pm

    Excellent work, you get my 5,but I have one question. You say,the digit zero will be displayed with a point in the center instead of 0, but I have not seen point at all,Sorry for I say so.

    • Sorry, I am late

      Posted by Cui Sheng on 04/05/2004 08:30am

      The OS is Windows2000 Professional Version5.0(Build 2195: Service Pack 4), English Version The country settings: Chinese(PRC)

      Reply
    • I Can't See Any Errors

      Posted by holte on 03/14/2004 04:55am

      Because I cannot reproduce your problem, I ask you for telling me your operating system and your country settings.

      Reply
    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • When individual departments procure cloud service for their own use, they usually don't consider the hazardous organization-wide implications. Read this paper to learn best practices for setting up an internal, IT-based cloud brokerage function that service the entire organization. Find out how this approach enables you to retain top-down visibility and control of network security and manage the impact of cloud traffic on your WAN.

  • Complex hybrid environments can make it difficult to track interdependencies, increasing the risk of disrupting critical business services. In this white paper by EMA, you'll learn how application discovery and dependency mapping can help you: Meet granular targets for availability, cost, and time-to-revenue for cloud services. Accelerate mean time to repair (MTTR) while communicating better with stakeholders. Manage even the most complex hybrid environments more efficiently and effectively Understand the …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date