|
1. If you have Microsoft SDK look in the "include" directory for WinUser.h, it has ALL Windows messages defined there. If you don't have the SDK, either get it or Google for the message codes. If you have VB6 I think the API Viewer has the Windows messages as well.
2. You need to implement the IMessageFilter in some class and it's only method
bool PreFilterMessage(ref Message msg)
Check the message code in msg.Msg and return either 'true' if you want to cancel processing of this message and 'false' if you want to let it through to WndProc. If you want this filter application wide you can add this message filter like so:
MyMessageFilter mf = new MyMessageFilter();
Application.AddMessageFilter(mf);
If you want to process this on just one window, just override the WndProc method. And do not call the base.WndProc after you process a message.
|
|
|
|
|
I wonder if there is an equivalent of C# to the #define prepropcessor directive of C++. The one of C# is not very useful since you can not define macros. Can i use something else, which would perform the same functions. This will really clean my code.
|
|
|
|
|
Simple answer: no, there isn't equivalant (but you can define symbols for compiler)
Complex answer:
Some solutions:
1) Develope own preprocessor that handles macros (shouldn't been too hard to do - but will make your code uncompatible)
2) Use #if (compiler symbols) to "select implementation". For example:
public abstract class DumpableObject : IDumpableObject
{
#if DEBUG
private DumpContext m_contextDump;
private int m_iDumpLevel = DumpContext.DEFAULT_DUMP_LEVEL;
protected int DumpLevel
{
get { return m_iDumpLevel; }
set { m_iDumpLevel = value; }
}
public void DumpAll()
{
DumpContext context = new DumpContext( this, m_iDumpLevel, DumpContext.DumpDetails.ALL );
}
public void Dump( DumpContext context )
{
m_contextDump = context;
OnDump();
m_contextDump = null;
}
protected virtual void OnDump()
{
}
protected void Dump( string strName, object obj )
{
m_contextDump.Dump( strName, obj );
}
#else
protected int DumpLevel
{
get { return 0; }
set { }
}
protected void DumpAll()
{
}
public void Dump( DumpContext context )
{
}
protected virtual void OnDump()
{
}
protected void Dump( string strName, object obj )
{
}
#endif
}
(Yes I know - it doesn't implement all macro tricks - but at least some). Basicly you really should be able to do almost anything without macros (just use sub methods).
|
|
|
|
|
The problem with this method is that my code size actually Increases very rapidely. I wonder how come there is no cheap tricks. Maybe I can Use attributes for that ?
But i will probably have to create a preprocessor directive myself
|
|
|
|
|
HAHAHA_NEXT wrote:
But i will probably have to create a preprocessor directive myself
I itch for that too
I use it (#if) alot. To simulate the enviroment, eg:
#define HELLO
bool Blah(string foo)
{
#if HELLO
return true;
#elseif
return false;
#endif
}
|
|
|
|
|
Hi guys!
My question is a big one as I spent all the day to find out HOW to redraw the scroll bars of a TreeView (or any other control) without finding anything!!!
So my question is how to make the TreeView's scrollbars owner drawn ??
Thanks!
Jean Bédard
|
|
|
|
|
I am using ThreadPool class and I cannot find a way to return data from the callback procedure. Does anybody have any idea how to do that.
Thank for your time
Spiros Prantalos
Miami the place to be!!
|
|
|
|
|
That's what the state parameter is for. Since it's an object - and therefore a reference type - it can be used to pass both input and output arguments. If you want better handling of parameters and return values, use asynchronous methods instead (such as BeginWhatever and EndWhatever ). If you use the proper signature for methods in C#, the compiler can actually create asynchronous methods for your methods. See Including Asynchronous Calls[^] in the .NET Framework SDK for more information.
Also, worker threads are common associated with an object that contains the data with which the callback method operates, so if it also stores state in such properties, you can always retrieve them later when the worker thread finishes, if it finishes at all (some are designed to run continuously - it's all up to your design).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
Try this sites for ideas and information.
http://www.codeproject.com/csharp/XYNetSocket.asp?target=socket%7Cprogramming
http://www.codeproject.com/csharp/socketsincs.asp
http://www.developerfusion.com/show/3918/4/
I hope this will help you.
/dabuskol
|
|
|
|
|
if I ask 'GetPrivateProfileString()' to read file
const string fileName = "c:\\temp\\myfile.ini";
instead of reading this file it reads file
const string fileName = "c:\\temp\\myfile";
In other words it drops the extention '.ini'. I have checked the facts and this is what is really going on.
Thanks for your comments.
Sample source follows.
using System.Runtime.InteropServices;
using System.Text;
using System.Diagnostics;
string key = "Key";
string defaultValue = "dftValue";
int size = 255;
StringBuilder result = new StringBuilder(size, size);
const string fileName = "c:\\temp\\myfile.ini";
for(int i=0; i < 5; i++)
{
string section = "Section" + i.ToString();
string outvalue = "Value" + i.ToString();
//WritePrivateProfileString(section, key, outvalue, fileName);
GetPrivateProfileString(section, key, defaultValue, result, size, fileName);
Debug.WriteLine(i + " result " + result);
}
|
|
|
|
|
hi,
can please tell me how do I add function to Explorer context menu (right mouse click on a file)? thanks
Paolo Ponzano
|
|
|
|
|
See Michael Dunn's article at http://www.codeproject.com/shell/ShellExtGuide1.asp and related articles for how this is done using C/C++. If you want to do this using C#, you have to create CCWs (COM-Callable Wrappers) for all the necessary COM interfaces you need to implement, as well as use the GuidAttribute and other attributes from System.Runtime.InteropServices as necessary.
If you know C/C++, you'd be wise to use it to avoid large development overheads, as well as for performance since a managed shell extension would require the CLR to be loaded which has quit a bit of overhead compared to a native DLL.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
|
I was just wondering if there is a way to do a control array for ease of setting up some controls. Basically I am trying to do this (syntax is more psuedo code):
<br />
controlA_View1.Top = controlA_View2.Top;<br />
controlA_View1.Left = controlA_View2.Left;<br />
controlA_View1.Visible = false;<br />
<br />
controlB_View1.Top = controlB_View2.Top;<br />
controlB_View1.Left = controlB_View2.Left;<br />
controlB_View1.Visible = false;<br />
<br />
...<br />
<br />
controlN_View1.Top = controlN_View2.Top;<br />
controlN_View1.Left = controlN_View2.Left;<br />
controlN_View1.Visible = false;<br />
<br />
I was wondering if I could do this:
<br />
Array arrView1;<br />
arrView1.Add(controlA_View1);<br />
arrView1.Add(controlB_View1);<br />
...<br />
arrView1.Add(controlN_View1);<br />
<br />
Array arrView2;<br />
arrView2.Add(controlA_View2);<br />
arrView2.Add(controlB_View2);<br />
...<br />
arrView2.Add(controlN_View2);<br />
<br />
for(int i = 0; i < arrView1.Count() && i < arrView2.Count(); i ++)<br />
{<br />
arrView1[i].Top = arrView2[i].Top;<br />
arrView1[i].Left = arrView2[i].Left;<br />
arrView2[i].Visible = false;<br />
}<br />
I am adding the controls via the form desinger because it is obviously easier to lay them out. I am using my current home project to explore deeper in to C# however I know I could do something like this with pointers or maybe with unsafe code. I remember the ref keyword can cause a reference to be passed to a function but can a ref be passed to an array?
Thanks for any help...
Brian
If you start a fire for a man, he will be warm for a day. If you start that same man on fire, he will be warm for the rest of his life.
|
|
|
|
|
You don't actually declare the variable as Array , but as Control[] , which inherits from Array implicitly:
Control[] controls = new Control[]
{
myControl1,
myControl2,
};
for (int i=0; i<controls.Length; i++)
{
Control c = controls[i];
if (i == 0) c.Location = new Point(8, 8);
else c.Location = new Point(8, 8 + controls[i - 1].Location.Y;
} You could also use a collection or list, but then you either have to cast or use a typed collection or list like Control.ControlCollection .
Also, since you need to add your controls to their container's Controls collection property anyway, you can always enumerate them all after adding them and initialize their properties.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I use a openfiledialog but i want it to return the filename with the extension and nothing more (eg: filename.doc). if i do it like this it returns the complete path:
openFileDialog1.ShowDialog();<br />
txtRunprogram.Text = openFileDialog1.FileName.ToString();
thx in advance
|
|
|
|
|
Try doing this:
string filename = String.Substring(openFileDialog1.FileName.ToString().LastIndexOf("\\"));
That should strip it out for you.
|
|
|
|
|
Or just Path.GetFileName(openFileDialog1.FileName) , which takes platform-dependent directory separators into account making your code more portable.
ToString is also completely unnecessary since FileName already returns a String .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
First of all, you do not need to call ToString on a string! It's already a string.
Second, use Path.GetFileName instead of the previous recommendation. Path.GetFileName takes platform-dependent directory separators into account. If you want to use String.LastIndexOf , then at least use the Path.PathSeparator field to get the platform-dependent directory separator.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
dear all,
i am using crystal reports for vs.net 2002, infact i want to set my report datasource as dataset. i am using AddCommand to reterive required fields. problem is that when i set report data source as dataset it shows all those reocrds on report that are retrived by AddCommand not by my
here is my code
private DataSet myDs()
{
SqlConnection nwindConn = new SqlConnection("DataSource=localhost;Integrated Security=SSPI;Initial Catalog=testDB");
SqlCommand selectCMD = new SqlCommand("testPorcedure",nwindConn);
selectCMD.CommandType = CommandType.StoredProcedure;
selectCMD.CommandTimeout = 30;
SqlDataAdapter custDA = new SqlDataAdapter();
custDA.SelectCommand = selectCMD;
nwindConn.Open();
custDA.Fill(custDS);
nwindConn.Close();
return custDS;
}
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
this.ConnectionString();
CrystalReport1 oReport = new CrystalReport1();
oReport.SetDataSource(this.myDs());//dataset that is filled by my sp
crTableLogonInfos = new TableLogOnInfos();
crTableLogonInfo = new TableLogOnInfo();
crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName = server;
crConnectionInfo.DatabaseName = database;
crConnectionInfo.UserID = user_id;
crConnectionInfo.Password = password;
crTableLogonInfo.ConnectionInfo = crConnectionInfo;
crTableLogonInfo.TableName = "Command";
crTableLogonInfos.Add(crTableLogonInfo);
CrystalReportViewer1.LogOnInfo = crTableLogonInfos;
CrystalReportViewer1.ReportSource = oReport;
CrystalReportViewer1.DataBind();
}
any body kindly help me i realy stuck
thanks in advance
|
|
|
|
|
Why are you providing log into to another source when you're already providing the data in a DataSet ? Using ADO.NET to fill a DataSet (along with a connection string stored in your .config file) is much more robust than hard-coding connection information in your report source. If you ever need to re-deploy the solution elsewhere, you have to change your source and recompile. Instead, make it as abstract as possible. Just configurable connection strings and DataSet s, as you seem to do above, except you're still using connection information on the viewer, for which I really don't understand the point.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the reply......ur point is taken.......but the problem is that even if report gets the connection info from the webconfig file..and i set the report source to the DataSet which is filled up by the SP i run....the report ignores the data source and gives the result according to the Select command i hav set in report design, which i have to do in order to tell the report which fields are required.
I need a way in which the report will display results according to the DataSet i give it.
Thanks.
|
|
|
|
|
When designing the report, instead of using a SQL statement use an ADO.NET DataSet , which is available in the report designer for data sources. It's been a long time since I worked with CR, but I remember that you could do this. That way, you need no connection-specific information and can instead just set your DataSet as the report data source.
The most likely reason it isn't working is because the report definition is binding against that SQL statement instead of expecting a DataSet . I don't know much about the internal workings of CR or the report definition, but it seems like a logical explanation.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
is C# CF able to build an application for the pocket pc
i see the c# able to do zooming but how bout bluring ? smoothing ?
if c# able to do that using GDI+ (while C# CF cannot support GDI+)and many tutorial out there but i cannot find any image processing tutorial regarding C# in compact framework for pocket pc ... pls help me any input are welcome
|
|
|
|