@import url("http://www.blogger.com/css/blog_controls.css"); @import url("http://www.blogger.com/dyn-css/authorization.css?blogID=8706105"); Hardik Shah - Trying to be with the Technology
Networks

Friday, November 11, 2005

Registry Explorer - Missing from SmartPhone

One thing which I really missed in a SmartPhone was a registry editor. I have been thinking of writing an application for "Registry Editor" for a few weeks now. Finally its done.

However I have just given some limited functionality to the explorer. I can edit only a DWORD or a string value - nothing more than these two. Partly cause its not safe to play with the registry and second cause I dont think a person might need to change any other values apart from these two.

Having said that, I was initially trying to hook onto the the CF framework by OpenNETCF.org, but then I moved to using P/Invoke. This was partly cause it was a pain to make a DWORD editor using OpenNETCF.

There was also one thing which caught my eye. The TAB order under .NET CF. Thankfully MSDN had answers to my queries. Baically forms designer creates the Controls collection in reverse order of when the controls were added to the form.

Here's a sample code from the app - will post up a complete code, once i am sure its working fine.


using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace RegEdit
{
public class DwordEditor : System.Windows.Forms.Form, IValueEditor
{
private System.Windows.Forms.MenuItem mnuDone;
private System.Windows.Forms.MenuItem mnuCancel;

private System.Windows.Forms.TextBox txtValueName;
private System.Windows.Forms.TextBox txtValueData;
private System.Windows.Forms.Label lblValueName;
private System.Windows.Forms.Label lblValueData;
private System.Windows.Forms.MainMenu mainMenuEditor;
public DwordEditor()
{
InitializeComponent();
bSaveChanges = false;
}

#region Private Variables
// init
private string ERegistryPath;
private string EValueName;
private System.UInt32 EValueData;
private bool ENewValue;
// status
private bool bSaveChanges;
#endregion

protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.lblValueName = new System.Windows.Forms.Label();
this.txtValueName = new System.Windows.Forms.TextBox();
this.txtValueData = new System.Windows.Forms.TextBox();
this.lblValueData = new System.Windows.Forms.Label();
this.mainMenuEditor = new System.Windows.Forms.MainMenu();
this.mnuDone = new System.Windows.Forms.MenuItem();
this.mnuCancel = new System.Windows.Forms.MenuItem();


// lblValueName
this.lblValueName.Size = new System.Drawing.Size(152, 22);
this.lblValueName.Text = "Value name:";
//
// txtValueName
//
this.txtValueName.Location = new System.Drawing.Point(0, 24);
this.txtValueName.Size = new System.Drawing.Size(168, 25);
this.txtValueName.Text = "";

// txtValueData

this.txtValueData.Location = new System.Drawing.Point(0, 80);
this.txtValueData.Size = new System.Drawing.Size(168, 25);
this.txtValueData.Text = "";

// lblValueData

this.lblValueData.Location = new System.Drawing.Point(0, 56);
this.lblValueData.Size = new System.Drawing.Size(152, 22);
this.lblValueData.Text = "Value data:";

this.mainMenuEditor.MenuItems.Add(this.mnuDone);
this.mainMenuEditor.MenuItems.Add(this.mnuCancel);

this.mnuDone.Text = "Done";
this.mnuDone.Click += new System.EventHandler(this.mnuDone_Click);

// mnuCancel
this.mnuCancel.Text = "Cancel";
this.mnuCancel.Click += new System.EventHandler(this.mnuCancel_Click);


// DwordEditor
this.Controls.Add(this.lblValueName);
this.Controls.Add(this.txtValueName);
this.Controls.Add(this.lblValueData);
this.Controls.Add(this.txtValueData);
this.Menu = this.mainMenuEditor;
this.Text = "Edit DWORD Value";
this.Load += new System.EventHandler(this.StringEditor_Load);
}
#endregion
private void mnuCancel_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void mnuDone_Click(object sender, System.EventArgs e)
{
EValueName = txtValueName.Text.Trim();
// change to more elegant: check that only integers are actually entered
try
{
EValueData = UInt32.Parse(txtValueData.Text.Trim());
}
catch
{
MessageBox.Show("The value is not parseable into a valid DWORD",
"Value creation impossible",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
return;
}
if (EValueName == "") return;
RegistryEditingService svc = RegistryEditingService.Instance();
if (ENewValue && svc.ValueNameExists(ERegistryPath, EValueName))
{
MessageBox.Show("The value name you have chosen does already exist",
"Value creation impossible",
MessageBoxButtons.OK,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button1);
return;
}
bool bSucceeded = svc.SetValue(ERegistryPath, EValueName, EValueData);
if (!bSucceeded) return;
bSaveChanges = true;
this.Close();
}
private void StringEditor_Load(object sender, System.EventArgs e)
{
if (!ENewValue)
{
txtValueName.Text = EValueName;
txtValueData.Text = EValueData.ToString();
txtValueName.Enabled = false;
}
else
{
txtValueName.Focus();
}
}
#region IValueEditor Members
public void Initialize(string registryKeyPath, string valueName, object valueData, bool newValue)
{
ERegistryPath = registryKeyPath;
EValueName = valueName;
EValueData = (System.UInt32)valueData;
ENewValue = newValue;
}
public bool ShowEditor()
{
this.ShowDialog();
return bSaveChanges;
}
#endregion
}
}


The best part would be that this would work with Windows Mobile 5.0 based smartphone

1 Comments:

Anonymous nilay said...

show me the demo if poss. dude

1:17 AM  

Post a Comment

Links to this post:

Create a Link

<< Home

Google
 
Web hardiks.blogspot.com