|
NTPort. It has C# examples also.
/\ |_ E X E GG
|
|
|
|
|
i would like to trap the windows state changes when your computer goes into standbye, hibernate, etc., which i believe are defined by ACPI as states S1-S5. can i trap these messages from .NET?
|
|
|
|
|
Implement the IMessageFilter and add your implementation using Application.AddMessageFilter . Each main form is sent the WM_QUERYENDSESSION (0x0011) and WM_ENDSESSION (0x0016) in succession. You can handle these in your IMessageFilter implementation. See the Platform SDK documentation at http://msdn.microsoft.com/library[^] for more information about these messages and what you can (and can't) return (i.e., assign to the Message.Result property), as well as the possible values for the Message.WParam and Message.LParam properties. These values are defined in winuser.h in the Platform SDK, which is downloadable from http://msdn.microsoft.com/platformsdk[^] and is installed by default with Visual Studio.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hmm... maybe i misunderstood your suggestion, but what i am specfically trying to do is have a winform running on a computer, and when that computer goes into stanby or hibernate mode, i want to be able to catch this state change and perform actions based on which state it changed into right before the system goes off into this state.
|
|
|
|
|
And I told you exactly how to do that. You can also use the Microsoft.Win32.SystemEvents.SessionEnding and Microsoft.Win32.SystemEvents.SessionEnded events, but then your code will not be portable to other platforms.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I am using CultureInfo objects in my application to ensure that the correct localisation is loaded from a set of resources, however I have found that certain cultures are not supported, for example Celtic languages such as "GD" (Scots Gaelic), "CY" (Welsh) or "GA" (Irish Gaelic).
For the moment, I want just to be able to use the CultureInfo object to pull the correct resources from Satellite assemblies. However every route I look at requires a CultureInfo object to be presented somewhere.
Is there any way to extend the CultureInfo so that I can have it accepting cultures that .NET does not intrinsically support? Or is there anyway to pull the resources easily from the correct satellite assembly without having to write lots of addional code mimicking what the existing system does?
CultureInfo does appear to be open to derivation, however I've not seen and indication that it would achieve anything. Can anyone point me in the direction of some links that would get me started on this?
Any help would be appreciated. Thanks.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
You could extend CultureInfo hypothetically, but you'll have to override every virtual member. The CultureInfo ctor won't accept an unrecognized LCID or name.
Getting satellite resources isn't that hard, however. The problem is overriding ResourceManager so that you can tell it which resource assembly to grab for unsupported CultureInfo s.
I have written such code fairly easily (all the power you need is pretty much defined on the Assembly class, like GetSatelliteAssembly ) and have extended the ResourceManager to do so. Either way, you're going to have to write some code. Since the current ResourceManager works with CultureInfo class, you may have the best luck extending CultureInfo and overriding everything necessary (basically, keep your own look-up table of information; currently, localization in .NET P/Invokes some of this functionality from native APIs).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
I have written such code fairly easily
Rather than re-invent the wheel, do you care to share?
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
This code gets a manifest resource stream (identitied by the const StreamResource ) from a satellite assembly. Unfortunately, you'll still need a valid CultureInfo (sorry, it's been a while since I wrote this; it might still help, though):
public static Stream GetZipResourceStream(CultureInfo culture)
{
Assembly asm = typeof(SiteBuilder).Assembly;
CultureInfo neutral = GetNeutralResourcesLanguage(asm);
if (culture == null || !culture.Equals(neutral))
{
Version v = GetSatelliteContractVersion(asm);
if (v == null) v = asm.GetName().Version;
try
{
asm = asm.GetSatelliteAssembly(culture, v);
}
catch
{
try
{
asm = asm.GetSatelliteAssembly(culture.Parent, v);
}
catch {}
}
}
Stream s = asm.GetManifestResourceStream(SiteResource);
return s;
}
internal static CultureInfo GetNeutralResourcesLanguage(Assembly a)
{
if (a == null) throw new ArgumentNullException("a");
if (a == typeof(object).Assembly)
return CultureInfo.InvariantCulture;
NeutralResourcesLanguageAttribute[] attrs =
(NeutralResourcesLanguageAttribute[])
a.GetCustomAttributes(typeof(NeutralResourcesLanguageAttribute), false);
if (attrs.Length == 0) return CultureInfo.InvariantCulture;
try
{
return new CultureInfo(attrs[0].CultureName);
}
catch (ThreadAbortException)
{
throw;
}
catch (Exception ex)
{
throw new ArgumentException(
BLR.FormatString("InvalidNeutralResourcesLanguageCulture",
a.ToString(), attrs[0].CultureName), "a", ex);
}
}
internal static Version GetSatelliteContractVersion(Assembly a)
{
if (a == null) throw new ArgumentNullException("a");
if (a == typeof(object).Assembly)
return null;
SatelliteContractVersionAttribute[] attrs =
(SatelliteContractVersionAttribute[])
a.GetCustomAttributes(typeof(SatelliteContractVersionAttribute), false);
if (attrs.Length == 0) return null;
try
{
return new Version(attrs[0].Version);
}
catch (Exception ex)
{
throw new ArgumentException(
BLR.FormatString("InvalidSatelliteContractVersion",
a.ToString(), attrs[0].Version), "a", ex);
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
Unfortunately, you'll still need a valid CultureInfo
Can't have everything!
Thanks for your help.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
Hello!
This is my first post. I have a little problem. I have build a small Windows Form application. It has 1 form and a couple of buttons and textboxes and a datagrid. I want to build a simple search. So, if I type a letter "D" in a textbox, I want in a DataGrid a list of all names that starts with a "D". If I type further a letter "a" and "v" for example, I would get a "Dave" names for example.
This is what I programmed so far:
static void FilterData()<br />
{<br />
<br />
try<br />
{<br />
<br />
string strFilter = "SELECT Avtosalon.Ime," + <br />
"Naslov.Ulica, Naslov.PostnaSt, Naslov.Kraj, Avtosalon.Telefon," + <br />
"Avtosalon.EPosta, Avtosalon.Vodja, Avtosalon.OdpiralniCas " +<br />
"FROM Avtosalon INNER JOIN Naslov ON Avtosalon.IDNaslov = Naslov.IDNaslov ";<br />
<br />
if (!MyForm.txtIme.Focused)<br />
{<br />
strFilter = strFilter + "WHERE Avtosalon.Ime LIKE '" + MyForm.txtIme.Text + "%'";<br />
if (MyForm.txtUlica.Focused)<br />
strFilter = strFilter + " AND Naslov.Ulica LIKE '" + MyForm.txtUlica.Text + "%'";<br />
else if (MyForm.txtPostnaSt.Focused)<br />
strFilter = strFilter + " AND Naslov.PostnaSt LIKE '" + MyForm.txtPostnaSt.Text + "%'";<br />
else if (MyForm.txtKraj.Focused)<br />
strFilter = strFilter + " AND Naslov.Kraj LIKE '" + MyForm.txtKraj.Text + "%'";<br />
else if (MyForm.txtTelefon.Focused)<br />
strFilter = strFilter + " AND Avtosalon.Telefon LIKE '" + MyForm.txtTelefon.Text + "%'";<br />
else if (MyForm.txtEPosta.Focused)<br />
strFilter = strFilter + " AND Avtosalon.EPosta LIKE '" + MyForm.txtEPosta.Text + "%'";<br />
else if (MyForm.txtVodja.Focused)<br />
strFilter = strFilter + " AND Avtosalon.Vodja LIKE '" + MyForm.txtVodja.Text + "%'";<br />
else if (MyForm.txtOdpiralniCas.Focused)<br />
strFilter = strFilter + " AND Avtosalon.OdpiralniCas LIKE '" + MyForm.txtOdpiralniCas.Text + "%'";<br />
} <br />
<br />
MyDataSet = new DataSet();<br />
MyDataAdapter = new SqlDataAdapter(strFilter,conn); <br />
MyDataAdapter.Fill(MyDataSet,"Avtosalon"); <br />
MyDataAdapter.Dispose();<br />
MyForm.BeginInvoke(CallDataBindToDataGrid);<br />
strFilter = null;<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message.ToString());<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
static void DataBindToDataGrid()<br />
{<br />
<br />
MyForm.gridAvtosalon.DataMember = "Avtosalon"; <br />
MyForm.gridAvtosalon.DataSource = MyDataSet;<br />
MyDataSet = null;<br />
MyDataAdapter = null;<br />
}
private void txtIme_TextChanged(object sender, System.EventArgs e)<br />
{<br />
try<br />
{<br />
UpdateThread = new Thread(UpdateThreadStart);<br />
UpdateThread.Name = "Update Thread";<br />
UpdateThread.IsBackground = true;<br />
UpdateThread.Start();<br />
<br />
<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message.ToString());<br />
}<br />
<br />
}
So, the problem is, when I type in a textbox, I get an error message "There is an open DataReader associated with this
Connection wich must be closed first" and I don't use DataReader at all. Could you help me, couse I study this now for
days and I can't see where is a problem. Thank in advance.
|
|
|
|
|
There are several problems here. With every character you type, TextChanged is fired. Since your updating your DataSet in the background using the same SqlConnection , then all those threads are trying to open separate connections to the same resource (the SqlConnection instance) at once. Even using separate connection resources isn't a good way, because this code is grossly inefficient (with each character typed, the database is queried). Instead, either use a button that filters the results when clicked, or use the LostFocus event or something for a TextBox .
Also, you're relying on input from the user to fill the WHERE clause. This is extremely bad. Think of what would happen if I typed the following into a TextBox :
A';DELETE FROM Avtosalon WHERE Ime LIKE ' That would delete all records in your Actosalon table - and even worse is possible if your DB security isn't tight (I could drop the master table, for example). The important thing when writing software is NEVER TRUST USER INPUT - no matter who the user is (they could inadvertently do something bad). And don't think they won't know your database structure: I could use the IL Disassembler (ildasm.exe) that comes with the SDK (free) or some other disassembler/decompiler and easily find out how to attack your code and database.
Instead, do what you're supposed to use with ADO.NET: parameterized queries. Read about the SqlParameter class and the SqlCommand.Parameters property in the .NET Framework SDK for lots of information and example source code. Using this not only makes for easier to read code, but eliminates the need for you to make sure strings are escaped (which is one thing that allows me to type what I did above) and it automatically performs checks for common attacks, this decreasing the attack surface.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hello every one,
can i integrate my Menu with Windows Shell ContextMenu (the one which pops up whenever we right click mouse) using C# classes.
Problem is, I want to do it without using Interop (Com) simply because i dont have pre-requiste COM knowledge.
suggestion of ne kind are welcomed
thanx.
|
|
|
|
|
goooooooogle wrote:
Problem is, I want to do it without using Interop (Com) simply because i dont have pre-requiste COM knowledge. suggestion of ne kind are welcomed
If you don't want to learn, why are you bothering asking. There are a whole slew of articles here on both COM Interop and Shell programming within C#. I would suggest you read those and when you get stuck either check out MSDN[^], post a question to the articles author on the forum within the article or post a question here.
- Nick Parker My Blog | My Articles
|
|
|
|
|
goooooooogle wrote:
Problem is, I want to do it without using Interop (Com) simply because i dont have pre-requiste COM knowledge
Impossible. Windows is still COM based so either you do it in COM or you don't do it all.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
How would I go about changing the number of spaces a tab uses when the user presses Tab on his/her keyboard? Thanks in advance.
Happy Programming and may God Bless!
"Your coding practices might be buggy, but your code is always right."
Internet::WWW::CodeProject::bneacetp
|
|
|
|
|
From my experience, I dont think u can, I digged alot thru the Win API but couldnt find anything...
top secret xacc-ide 0.0.1
|
|
|
|
|
See the documentation[^] for the RichTextBox.SelectionTabs property. This is the same as sending the EM_SETPARAFORMAT with a PARAFORMAT2 structure in native code with the cTabCount and rgzTabs fields assigned.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the help.
Happy Programming and may God Bless!
"Your coding practices might be buggy, but your code is always right."
Internet::WWW::CodeProject::bneacetp
|
|
|
|
|
Hi All,
We want to use sql server reporting services (ssrs), but want to create our own viewer and print buttons. Does anyone know of an article that shows how to do this. We really need to create a dll that can be called that will print our reports. Any info would be appreciated.
later,
Clyde
|
|
|
|
|
Here is task at hand:
I need to create a help system that allows users to hit F1 on any field, and they will get a popup explaining the use of the field. Assume that I know how to capture the keyboard event. I have a seperate class that has all functionailty of the HtmlHelp API in it. I need to call the HH_DISPLAY_TEXT_POPUP command. which takes the following structure for input: HH_POPUP as well as the location of the .chm file. I am getting confused as to how I define a structure to pass into this function. I do not have much experience with COM. The reason we are using this HtmlHelp API instead of the System.Windows.Forms.Help definition is becasue we want to read directly from our already created .chm file. If there is a way to do this with .net controls, please let me know as well. Thanks in advance!
|
|
|
|
|
Dear, Sir and Madam
Please see the code below.
bool bCtrl = false;
private void treeView1_KeyDown(object sender, KeyEventArgs e)
{
bCtrl = e.Control;
this.Text= bCtrl.ToString();
}
private void treeView1_KeyUp(object sender, KeyEventArgs e)
{
bCtrl = e.Control;
this.Text= bCtrl.ToString();
}
private void treeView1_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
{
if(bCtrl)
DoDragDrop(e.Item, DragDropEffects.Copy);
else
DoDragDrop(e.Item, DragDropEffects.Move);
}
While I dragging item(node) why the KeyDown event is not fire?
How to solve this problem?
Sorry for bad English.
Thank You.
|
|
|
|
|
|
It's not supposed to. If you want to detect if the CTRL key was pressed while dragging, handle the Control.QueryContinueDrag event. See the documentation for that event as well as the QueryContinueDragEventArgs in the .NET Framework SDK for more information and examples.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a class in my middle tier in which I hold a DataTable object, which has already been filled out with data. All I want to do is filter the DataRows based on one of the Fields in the DataRow, and return a DataTable object with the filtered Rows.
This is my code:
public DataTable FilteredData( int clientType )<br />
{<br />
string filter = "CLIENT_TYPE = " + clientType;<br />
DataRow[] foundRows = _myData.Select( filter );<br />
DataTable dt = new DataTable();<br />
foreach( DataRow row in foundRows )<br />
{<br />
dt.Rows.Add( row );<br />
}<br />
return dt;<br />
}
The problem is that when it reaches the line dt.Rows.Add( row ); I get an exception saying that "This row already belongs to another table". It doesn't matter that I will be returning a seperate DataTable, as the Rows won't be updated in the interface. Can someone please tell me how I can return my data in a DataTable object, I would rather not have to return an array of DataRows.
|
|
|
|
|