Creating a Shareware Registration Dialog Box | CodeGuru

Creating a Shareware Registration Dialog Box

Environment: VC++ 6.0, W2000 RegDialog is the MFC-based dialog that will help you to manage shareware applications’ registration. When the shareware application is started for the first time, information about the company, applicant’s name, version number, trial period, and starting date is created in the Registry. Every following time the user starts the application, RegDialog […]

Written By
CodeGuru Staff
CodeGuru Staff
Oct 24, 2002
3 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment: VC++ 6.0, W2000

RegDialog is the MFC-based dialog that will help you to manage shareware applications’ registration.

When the shareware application is started for the first time, information about the company, applicant’s name, version number, trial period, and starting date is created in the Registry. Every following time the user starts the application, RegDialog appears with information about the number of days left to use and offers registration code entering or to continue unregistered.

After the trial period is finished, the user can only enter the registration code and after the shareware application is registered, RegDialog will no longer appear. Of course, the user can register the application during the trial period, also. Reinstalling the shareware application will not “help” because the information about the starting date is left in the Registry and the “new” application will just continue to count the trial period days. The first time the user starts the shareware application, RegDialog will not appear; that is because the user should first see and test the application. That time, I think, is not the right time to send him messages about days left to use or about continuing unregistered. So keep this in mind when you start the demo application or your application with RegDialog—REGDIALOG WILL SHOW WHEN YOU START YOUR APPLICATION THE SECOND TIME! Also, because RegDialog is working with SYSTEMS REGISTRY, please see the NOTE below.

How to Use It

  1. Create or open your existing code.
  2. In the VC++ menu, select Project->Add to Project->Components and Controls...
  3. Browse to RegDialog.ogx (downloaded in RegDialog_ogx.zip) and select it.
  4. In the application’s main class, insert #include "RegDialog.h".
  5. In the same class, in the InitInstance() function, insert:
    ...
     SetRegistryKey(_T("MyCompany"));
     CRegDialog regDlg;
     regDlg.Check();
    ...
    

    Of course, replace “MyCompany” with something you choose or have as an adequate name.

  6. In RegDialog.cpp, modify the part specified as "App specific data":
  7. /////////////////      App Specific Data !!!  ////////////
    
    int DaysLimit = 30;
    long KeyCode  = 12345678;
    CString Version = "1.1";
    /////////////////////////////////////////////////////////
    

where:

DaysLimit is the number of days application will work unregistered.

KeyCode is the code that user must enter to register application.

Version is a string used to avoid that newer versions of your software are all registered if older version was.

All this you can see in the demo project you can download from this page (RegDialog_demo.zip).

Here are a few things you need to know:

The OnAskcode() function of the CRegDialog class is the place you should put what will happen when the user clicked the “Register” button. It can be some dialog with the price and a hyperlink to registration site, some register.exe file, or a “send mail” link.

KeyCode is a long type variable. If you need KeyCode with letters included, modify the code so it writes string types instead of int types to the Registry database (see the NOTE below!).

The code can be easily modified to calculate the user’s registration code from letters of his name instead of using the KeyCode variable compiled in the application.

NOTE: Because this class is working with the system’s Registry—the important OS database—be careful if you change the code. If you don’t know exactly what the Registry functions are doing, do not change them! Just use the class as it is and it will work. See MSDN for information and help about the Registry system.

Downloads

Download demo project – 44 Kb
Download ogx source – 5 Kb
Download single executable – 6 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.