banner



How To Store A Value In A Register C

The registry is a huge database that holds all necessary the data that the operating organisation needs to function and communicate with anything that resides in the computer. It is organized as a tree view and functions similar Windows Explorer. Although it is highly used past applications installed in the reckoner, y'all can utilise it to store information related to your application and retrieve that information when necessary.

Most of the information in the registration is organized like a dictionary, as a combination of keys and values. In this exercise, we volition create an awarding with a grade that the user can motion while using the awarding. When the user closes the application, nosotros volition save the location of the course in the registry. The next time the user opens the application, we will call back the previous location and utilize it to the course.

Practical Learning: Creating the Awarding

  1. Start Microsoft Visual C++ or Visual Studio
  2. Create a Dialog-Based application named Remember1
  3. Delete the OK button and the TODO line
  4. Change the Caption of the Cancel push to Shut
  5. Change the dialog'due south Border property to Resizing
  6. Generate the WM_DESTROY message of the dialog box
  7. Implement its OnDestroy event equally follows:
    void CRemember1Dlg::OnDestroy() { 	CDialog::OnDestroy();  	// TODO: Add your message handler code hither 	CRect rctPosition; 	HKEY hk; 	DWORD dwDisp; 	TCHAR dwData[twoscore];  	// Retrieve the position and size of the dialog box 	GetWindowRect(&rctPosition);  	// Check the HKEY_CURRENT_USER key and look 	// for the RemDlgPos node nether 	// If y'all don't detect it, then create it 	RegCreateKeyEx(HKEY_CURRENT_USER, 		           "RemDlgPos", 				   0, 				   Cipher, 				   REG_OPTION_NON_VOLATILE, 				   KEY_WRITE, 				   NULL, 				   &hk, 				   &dwDisp);  	// Retrieve the value of the x coordinate of the dialog box... 	sprintf(dwData, "%d", rctPosition.left); 	// ... and shop it in a primal named Left 	RegSetValueEx(hk, 		          "Left", 				  0, 				  REG_DWORD, 				  (PBYTE)&dwData, 				  sizeof(PDWORD)); 	 	// Retrieve the value of the y coordinate of the dialog box... 	sprintf(dwData, "%d", rctPosition.pinnacle); 	// ... and shop it in a key named Height 	RegSetValueEx(hk, 		          "Top", 				  0, 				  REG_DWORD, 				  (PBYTE)&dwData, 				  sizeof(PDWORD));  	// Call up the width of the dialog box... 	sprintf(dwData, "%d", rctPosition.Width()); 	// ... and store it in a central named Width 	RegSetValueEx(hk, 		          "Width", 				  0, 				  REG_DWORD, 				  (PBYTE)&dwData, 				  sizeof(PDWORD));  	// Retrieve the peak of the dialog box... 	sprintf(dwData, "%d", rctPosition.Height()); 	// ... and shop it in a key named Height 	RegSetValueEx(hk, 		          "Top", 				  0, 				  REG_DWORD, 				  (PBYTE)&dwData, 				  sizeof(PDWORD));  	// We accept finished with the registry, 	// so liberate the resources we were using 	RegCloseKey(hk); }
  8. Generate the WM_CREATE bulletin of the dialog box
  9. Implement its OnCreate issue as follows:
    int CRemember1Dlg::OnCreate(LPCREATESTRUCT lpCreateStruct) { 	if (CDialog::OnCreate(lpCreateStruct) == -one) 		return -1;  	// TODO:  Add together your specialized creation code hither 	// This variable will allow usa to keep track of the KEY 	HKEY hk; 	// This variable will exist used to concur the type of value 	DWORD dwType; 	// This variable will represent the size of the value 	DWORD dwLength; 	// These variables represent the position 	// and the size of the dialol box 	TCHAR strValueLeft[twenty], strValueTop[20], 		  strValueWidth[20], strValueHeight[twenty];   	// Bank check the HKEY_CURRENT_USER node and expect for  	// the RemDlgPos node under it 	// If it exists, open it 	RegOpenKeyEx(HKEY_CURRENT_USER, 		           "RemDlgPos", 				   0, 				   KEY_QUERY_VALUE, 				   &hk); 	 	// Retrieve the value of the Left primal 	RegQueryValueEx(hk, 		             "Left", 		             Cipher, 		             NULL, 		             (LPBYTE)strValueLeft, 		             &dwLength); 	 	// Retrieve the value of the Top key 	RegQueryValueEx(hk, 		        "Elevation", 				Cipher, 				&dwType, 				(LPBYTE)strValueTop, 				&dwLength); 	 	// Call back the value of the Width cardinal 	RegQueryValueEx(hk, 		        "Width", 				Naught, 				&dwType, 				(LPBYTE)strValueWidth, 				&dwLength); 	 	// Retrieve the value of the Height primal 	RegQueryValueEx(hk, 		        "Height", 				Zippo, 				&dwType, 				(LPBYTE)strValueHeight, 				&dwLength);  	// Nosotros have finished reading the registry, 	// so gratuitous the resources nosotros were using 	RegCloseKey(hk);  	// Use the values retrieved from the retrieve to identify the dialog box 	// where it was the previous fourth dimension 	this->SetWindowPos(&wndTop, atoi(strValueLeft), atoi(strValueTop), 		               atoi(strValueWidth), atoi(strValueHeight), SWP_SHOWWINDOW);  	return 0; }
  10. Execute the awarding
  11. Resize the motion the dialog box effectually
  12. Close the dialog box
  13. Execute the application again and observe that it remembers where the dialog box was terminal positioned
  14. Open the registry and examine the HKEY_CURRENT_USER node. Notice that it has a new node named RegDlgPos
  15. Close the registry

How To Store A Value In A Register C,

Source: http://www.functionx.com/visualc/articles/regvalues.htm

Posted by: adamsdiationance.blogspot.com

0 Response to "How To Store A Value In A Register C"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel