article

Registry

Email
Submitted on: 1/2/2015 7:15:00 AM
By: Anonymous (from psc cd)  
Level: Advanced
User Rating: By 8 Users
Compatibility: C++ (general), Borland C++
Views: 1341
 
     The following code does two things: 1) Opens a new registry key if an existing one doesn't exist and writes to it 2) Reads the existing data in the key, and applies the data to the form using the SetBounds(); function. The code looks VERY cluttered and there is a fair bit here to put on one page, so i have uploaded a .txt version of the following code that is structured and ready to copy-and-paste!

This article has accompanying files
 
				Firsty, you have to include the vcl\Registry.hpp header file for the compiler to reckonise the commands used in this program.
Click on the form once and double click the OnActivate event in the object inspector. Add the following code:
TRegistry& regKey = *new TRegisry();
bool keyGood = regKey.OpenKey("Software\\Test\\Test", false);
if (keyGood) {
int top = regKey.ReadInteger("Top");
int left = regKey.ReadInteger("Left");
int width = regKey.ReadInteger("Width");
int height = regKey.ReadInteger("Height");
SetBounds(left,top,width,height);
}
delete ®Key;
The above code checks for a registry key called Test. If it returns true(if it exists) then it begins reading the keys and finally sets the dimensions of the form by using the SetBounds() function. The following code must be placed in the OnClose event of the form:
TRegistry& regKey = *new TRegistry();
regKey.OpenKey("Software\\Test\\Test", true);
regKey.WriteInteger("Top", Top);
regKey.WriteInteger("Left", Left);
regKey.WriteInteger("Width", Width);
regKey.WriteInteger("Height", Height);
delete ®Key;
The above code opens a key called Test whether it exists or not and write the four dimensions of the form (width, height, top and left). The last line, delete ®Key;, simply exists the active key. Although it says delete, the key is not deleted just closed and left alone.

winzip iconDownload article

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com


Other 21 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Advanced category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.