Thursday, August 25, 2005

The Code Project - A Fast CSV Reader - C# Database

The Code Project - A Fast CSV Reader - C# Database

Wednesday, August 24, 2005

Jenks optimization method

Summary Describes the Jenks optimization method, used to determine natural breaks in Arcview legends. Procedure The Jenks optimization method is also known as the goodness of variance fit (GVF). It is used to minimize the squared deviations of the class means. Optimization is achieved when the quantity GVF is maximized: 1. Calculate the sum of squared deviations between classes (SDBC). GVF = ------------------- 2. Calculate the sum of squared deviations from the array mean (SDAM). 3. Subtract the SDBC from the SDAM (SDAM-SDBC). This equals the sum of the squared deviations from the class means (SDCM). The method first specifies an arbitary grouping of the numeric data. SDAM is a constant and does not change unless the data changes. The mean of each class is computed and the SDCM is calculated. Observations are then moved from one class to another in an effort to reduce the sum of SDCM and therefore increase the GVF statistic. This process continues until the GVF value can no longer be increased. Further Reading Jenks, George F. 1967. 'The Data Model Concept in Statistical Mapping', International Yearbook of Cartography 7: 186-190. "

Tuesday, August 23, 2005

The Code Project - A flexible charting library for .NET - C# Programming

The Code Project - A flexible charting library for .NET - C# Programming: "A flexible charting library for .NET By JChampion Looking for a way to draw 2D line graphs with C#? Here's yet another charting class library with a high degree of configurability, that is also easy to use. "

Differentiating between a single click and a double click C#

In a Windows control, whenever the user performs a double click with his mouse, it generates 2 sets of events: first a single click event, followed by a double click event. In some controls this does not pose a problem. For example in a text box, the first click places the caret in the control, the double click selects the text. In others, this behaviour can lead to problems. In a listview, that contains a checkbox, for example. Single clicking it toggles the checkbox on and off. If you want a double click event to do something, like pop up a messagebox, that displays the information in the row that was double clicked, then the double click will cause the checkbox to toggle (because of the single click that gets generated). The only way to get around this behaviour, is to wait for the time allowed between two clicks, so as to consider them as part of one double click event. If in this time a double click did not follow, the fire the single click event (or as my code shows, toggles the checkbox), if it does, then just call the double click event. Here is the sample code, that I used to extend the ListBox control, so as to not confuse the single and double click events. Here is what you need to know: The listview has an ImageList assigned to it. Image 0 is a CheckedBox image and Image 1 is a un-checked box image. The timer fires every 50 milliseconds. The timer is started everytime a single click event is fired and stoped after the time given for a double click has elapsed. (The doubleClickTime, is the maximum allowed time between 2 single clicks so as to be considered as a single click.) If a double click event is detected from when a single click was fired, to the expiry of the doubleClickTime, the OnDoubleClick method is called. If a double click event is not received, then its assumed that the user wants to process a single click event. (in my case, I set the image index to toggle the checkbox and also call the OnItemCheck event). C# code example: using System; using System.Drawing; namespace System.Windows.Forms { public class ListViewEx : System.Windows.Forms.ListView { private const int WM_LBUTTONDBLCLK = 0x0203; private const int WM_LBUTTONDOWN = 0x0201; private const int WM_RBUTTONDBLCLK = 0x0206; Timer _timer = new Timer(); bool _dblClick; Point _p = Point.Empty; ListViewItem _lvi = null; private int milliseconds = 0; private Rectangle _dblClickHitTest = Rectangle.Empty; public ListViewEx():base() { _timer.Interval = 50; _timer.Tick +=new EventHandler(_timer_Tick); } protected override void WndProc(ref Message m) { _p = Point.Empty; Point translatedPt = Point.Empty; switch (m.Msg) { case WM_RBUTTONDBLCLK: break; case WM_LBUTTONDBLCLK: _dblClick = true; _p = PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y)); _lvi = GetItemAt(_p.X, _p.Y); break; case WM_LBUTTONDOWN: _dblClick = false; _p = PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y)); _lvi = GetItemAt(_p.X, _p.Y); translatedPt = new Point(_p.X - SystemInformation.DoubleClickSize.Width / 2, _p.Y - SystemInformation.DoubleClickSize.Height/2); _dblClickHitTest = new Rectangle(translatedPt,SystemInformation.DoubleClickSize); _timer.Start(); break; default: base.WndProc (ref m); break; } } private void _timer_Tick(object sender, EventArgs e) { milliseconds += _timer.Interval; if (milliseconds >= SystemInformation.DoubleClickTime/2) { milliseconds = 0; _timer.Stop(); if (_dblClick == true && _dblClickHitTest.Contains(_p)) { //double click if (_lvi != null) _lvi.Selected = true; this.OnDoubleClick(null); } else { //single click if (_lvi != null) { _lvi.Selected = true; _lvi.ImageIndex = 1 - _lvi.ImageIndex; this.OnItemCheck(new ItemCheckEventArgs(this.Items.IndexOf(_lvi), _lvi.ImageIndex == 0 ? CheckState.Checked : CheckState.Unchecked, _lvi.ImageIndex == 0 ? CheckState.Unchecked: CheckState.Checked)); } } } } } }

Monday, August 22, 2005

Building a Store Locator with MapPoint's Web Service

Here's a link on how to build a store locator application with MapPoint's Web Service: http://www.livemeeting.com/cc/partners1/view?id=2745&role=attend&pw=c15052. This is a line by line presentation on how to code against the APIs and how it applies to a store locator application. The presentation goes through Authenticating, FindAddress, Find, FindNearby, GetMap, FindByID, and CalculateSimpleRoute.

Friday, August 12, 2005

Automatically starting the debugger when an application starts (registry entry)

Image File Execution Options

There is a location in the registry that will automatically attach a debugger to an application when it starts to run. This registry location is the following:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
    NT\CurrentVersion\Image File Execution Options

Under this registry key, you simply create a new registry key with the name of the process you want to debug, such as "myapplication.exe". If you have not used this before, there is probably a default key already created called "Your Application Here" or something similar. You can rename that key and use it if you like.

One of the values on this key is "Debugger". This should point to the debugger you want to start when this application is run. The default for "Your Application Here" is "ntsd -d". You cannot use this unless you have a kernel debugger attached so I would remove the "-d" part.

Note: Keeping "-d" and not having a kernel debugger attached could result in locking up of your system every time that application is run! Be careful. If you have a kernel debugger setup, you can unlock the system by hitting "g".

There is another value that may be there called "GlobalFlags". This is another tool that can be used for debugging, however it is outside the scope of this article. For more information on that, look up "gflags.exe".