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 . |