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

  • Managing your company's financials is the backbone of your business and is vital to the long-term health and viability of your company. To continue applying the necessary financial rigor to support rapid growth, the accounting department needs the right tools to most efficiently do their job. Read this white paper to understand the 10 essentials of a complete financial management system and how the right solution can help you keep up with the rapidly changing business world.

  • Live Event Date: August 14, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Data protection has long been considered "overhead" by many organizations in the past, many chalking it up to an insurance policy or an extended warranty you may never use. The realities of today makes data protection a must-have, as we live in a data-driven society -- the digital assets we create, share, and collaborate with others on must be managed and protected for many purposes. Check out this upcoming eSeminar and join Seagate Cloud …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds