|
How much more dynamic can you get than what Marc has shown you? Overriding WinProc gives the object the chance to inspect the message and determin what to do including pass it along.
|
|
|
|
|
Ok, suppose I am writting a dll in C#, the dll will send to current window
some message. My customs who will use that dll have to define override WndProc method. So I am thinking of create a function so that customs dont need to explicitly write their WndProc.
|
|
|
|
|
jinzhecheng wrote:
My customs who will use that dll have to define override WndProc method.
Then use an event handler that they can attach to, and if they handle WndProc themselves, you don't. Something like this:
class MyForm : Form
{
public delegate bool WndProcOverrideDlgt(ref Message m);
public event WndProcOverrideDlgt WndProcOverride;
protected override void WndProc(ref Message m)
{
bool handled=false;
if (WndProcOverride != null)
{
handled=WndProcOverride(m);
}
if (!handled)
{
}
}
}
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
Marc, AFAIK, delegates declared as events cannot have a return type except void. This is because more than one client could have subscribed to the event, so there is no way to figure out which of those clients' return values should get back.
I think the best way is to pass another object with WndProcOverride that encapsulates a bool variable and has logic to ensure that once one client has handled, it is set to true etc..
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hi Marc,
your solution is cool, however , you see, you still defined an override version of WndProc INSIDE myForm class,
What I want is like this:
Form a = new Form();
// after this call, the WndProc is overrided!!
overrideWndProc(a);
it looks like crazy, I am now wondering if its possible, maybe I should use
a proxy, that can seize message before the form get it
|
|
|
|
|
A delegate is a lot simpler than a proxy.
And delegates/events can have a return type, it's just not standard.
So yes, the real way to do it is to define your own specialized EventArgs class that has the "handled" flag.
But yes, if you want something that can hook a form that doesn't implement WndProc and gives you a way to hook it, then you have to do something like this:
PreFilter preFilter=new PreFilter();
Application.AddMessageFilter(preFilter);
...
class PreFilter : IMessageFilter
{
public bool PreFilterMessage(ref Message m)
{
}
}
That may be more what you're looking for. You can then test if the message's HWnd is the same as the Form's hWnd that you want to hook, using:
form.Handle
which should be the same thing as the HWnd value.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
Marc ,
Finaly got it .
Yeah , I think a message filter is the best solution.
Thanks!
here is a summary:
1st step:
// create a filter
public class MsgHandler : System.Windows.Forms.IMessageFilter
{public bool PreFilterMessage(ref msg){// do it here}}
2nd step:
//create a method
public void OverrideWndProc(){MsgHandler msgHandler =new MessageHandler();
Application.AddMessageFilter(msgFilter);}
3rd step:
user call this func before App run.
Thats it!
|
|
|
|
|
But Marc is raising an event there...
class MyForm : Form
{
public delegate bool WndProcOverrideDlgt(ref Message m);
public event WndProcOverrideDlgt WndProcOverride;
protected override void WndProc(ref Message m)
{
bool handled=false;
if (WndProcOverride != null)
{
handled=WndProcOverride(m);
}
if (!handled)
{
}
}
}
So
Form a = new MyForm();
a.WndProcOverride += new WndProcOverrideDlgt(WndProc_Handler);
...
bool WndProc_Handler(ref Message m)
{
}
p.s If S. Senthil Kumar is right and you can't have bool delegate (I dunno and lazy to look up) you can do it like public delegate void WndProcOverrideDlgt(ref Message m, ref bool handled);
At least I hope so
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
Hi
I want to delete the particular node from xml file
Supoose i want to delete farm name="ram" it should delete all the contents of element farm
Program should search from the file for particular node and delete
I have written the code for deleting but it deletes from UPPer node only it deletes ram what ever you give the farm name dev2.
my code is given below pls modify it
private void button15_Click(object sender, System.EventArgs e)
{
strtxt_BD_farmName="dev1";
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load("c:/farm-config.xml");
XmlNodeList farm=xmldoc.SelectNodes("//farm");
foreach(XmlNode n in farm)
{
if (n.Attributes.GetNamedItem("name").Value == strtxt_BD_farmName)
{
MessageBox.Show("Enter Farm name found");
XmlNode xNode;
XmlElement xElmntFamily;
// Search for a particular node
xNode = xmldoc.SelectSingleNode("//farm-config");
if (!(xNode == null))
{
xElmntFamily = (XmlElement) (xNode);
xElmntFamily.RemoveChild(xElmntFamily.SelectSingleNode("farm"));
FileStream fsxml = new FileStream("c:/farm-config.xml",FileMode.Truncate,FileAccess.Write,FileShare.ReadWrite);
xmldoc.Save(fsxml);
fsxml.Close();
//xNode=null;
farm=null;
//xmldoc.Save("c:/farm-config.xml");
MessageBox.Show(strtxt_BD_farmName + " deleted");
}
}
}
This is my original XMl structure
<?xml version="1.0" encoding="UTF-8"?>
<root>
<farm-config>
<farm name="ram">
<connection address="localhost" user="ram" password="ram">
<lastjob>Copy-All</lastjob>
<lastconnection startdate="2005-05-10" starttime="12:43:23" enddate="2005-05-10" endtime="12:58:32" />
<state>1</state>
<database start="0" name="bd_plc1_house1_14022005" sourceType="amacs">
<tables state="0" name="feed_delivery">
<columns state="0" name="DATE" />
<columns state="0" name="TIME" />
<columns state="0" name="DAY" />
<columns state="0" name="MONTH" />
<columns state="0" name="YEAR" />
<columns state="0" name="PRODWEEK" />
<columns state="0" name="WEEKDAY" />
<columns state="0" name="SILO" />
<columns state="0" name="CAR" />
<columns state="0" name="PRODUCT" />
<columns state="0" name="VOLUME" />
</tables>
</database>
</connection>
</farm>
<farm name="dev2">
<connection address="localhost1" user="root1" selectedConnection="1" password="daask2">
<lastJob>Copy-All</lastJob>
<lastConnection startdate="2005-05-10" starttime="12:43:23" enddate="2005-05-10" endtime="12:58:32" />
<state>1</state>
</connection>
<database state="0" name="bd_plc1_house1_14022005" sourceType="amacs">
<tables state="0" name="feed_delivery">
<columns state="0" name="DATE" />
<columns state="0" name="TIME" />
<columns state="0" name="DAY" />
<columns state="0" name="MONTH" />
<columns state="0" name="YEAR" />
<columns state="0" name="PRODWEEK" />
<columns state="0" name="PRODDAY" />
<columns state="0" name="WEEKDAY" />
<columns state="0" name="SILO" />
<columns state="0" name="CAR" />
<columns state="0" name="PRODUCT" />
<columns state="0" name="VOLUME" />
</tables>
<tables state="0" name="production_actualbirds">
<columns state="0" name="DATE" />
<columns state="0" name="TIME" />
<columns state="0" name="DAY" />
<columns state="0" name="MONTH" />
<columns state="0" name="YEAR" />
<columns state="0" name="PRODWEEK" />
<columns state="0" name="PRODDAY" />
<columns state="0" name="WEEKDAY" />
<columns state="0" name="SILO" />
<columns state="0" name="CAR" />
<columns state="0" name="PRODUCT" />
<columns state="0" name="VOLUME" />
</tables>
</database>
</farm>
</farm-config>
</root>
after deletetion my xml structure will look like in the given format but according to my program it is deleteing
farm name=ram as i should delete farm name=dev2 pls someone give me code for that
<?xml version="1.0" encoding="UTF-8"?>
<root>
<farm-config>
<farm name="dev2">
<connection address="localhost1" user="root1" selectedConnection="1" password="daask2">
<lastJob>Copy-All</lastJob>
<lastConnection startdate="2005-05-10" starttime="12:43:23" enddate="2005-05-10" endtime="12:58:32" />
<state>1</state>
</connection>
<database state="0" name="bd_plc1_house1_14022005" sourceType="amacs">
<tables state="0" name="feed_delivery">
<columns state="0" name="DATE" />
<columns state="0" name="TIME" />
<columns state="0" name="DAY" />
<columns state="0" name="MONTH" />
<columns state="0" name="YEAR" />
<columns state="0" name="PRODWEEK" />
<columns state="0" name="PRODDAY" />
<columns state="0" name="WEEKDAY" />
<columns state="0" name="SILO" />
<columns state="0" name="CAR" />
<columns state="0" name="PRODUCT" />
<columns state="0" name="VOLUME" />
</tables>
<tables state="0" name="production_actualbirds">
<columns state="0" name="DATE" />
<columns state="0" name="TIME" />
<columns state="0" name="DAY" />
<columns state="0" name="MONTH" />
<columns state="0" name="YEAR" />
<columns state="0" name="PRODWEEK" />
<columns state="0" name="PRODDAY" />
<columns state="0" name="WEEKDAY" />
<columns state="0" name="SILO" />
<columns state="0" name="CAR" />
<columns state="0" name="PRODUCT" />
<columns state="0" name="VOLUME" />
</tables>
</database>
</farm>
</farm-config>
</root>
Warm regards,
sanjeev
|
|
|
|
|
Help!
I am attempting to develop an on demand screen capture daemon under c# .net framework and Windows XP.
I was hoping to use a service to do this but eventually gave up as I could not get bitmap capture to work even with the access to desktop switch being set.
Progressing on, I am trying now to do this in a console application. Capturing images and creating video is fine -apart from the video images in the video being played back being upside down!- but When using the AVISaveOptions to obtain users compression options the dialog dos not display any text/labels on any of the widgets. for example: button labels are invisible and the pulldown Compression selection widget does contain selectionable items when rolled down, though not visible in the pullddown, and the selected item does get displayed.
Please is this a feature of using console applications?
If there is a solution to allow the user to see the texts/labels of the
AVISaveOptions dialog, please, please let me know, it's driving me nuts!
Many thanks in advance.
Peter
|
|
|
|
|
Hi,
I am have a template column in a datagrid with a checkbox... I also have a button on the same form. I want to select index of the row of the datagrid for which the checkbox is selected on the button_click event.
Can anybody give me the solutions for it.
Thanks in Advance
|
|
|
|
|
|
Hi,
I want to remove the focus from a combo box upon choosing an item. The reason being so that the items in the drop-down list can't be changed by the mouse-wheel. How can I achieve this please?
C.N.
|
|
|
|
|
spvemm@hotmail.com wrote:
I want to remove the focus from a combo box upon choosing an item.
Well, the question is, what control do you want to give the focus to? Just call the Focus method of the control you want to set the focus to, and the combobox will lose the focus.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
ok....that solved the problem....10x a lot.
C.N.
|
|
|
|
|
Hi
In VS 2005, there is no .vbproj or .csproj for webprojects. Now how we can identify the existing project is web or local by using c#? In VS 2005 we can use Project.Properties.Item("ProjectType").Value . But in VS 2005 it throws an exception for web projects. If any one know how we can solve this problem, please help me.
Regards,
Rathish P S
|
|
|
|
|
Hi!
i have a Int16 variable and it has the value 0x010C. (little endian).
I want to get highbyte value and lowbyte value but don't know how to go on.
Is it correct to do the following to get the highbyte value?
int highbyte = Int16 & 0x00FF;
I am confused because i read that display of variable value (0x010C) != storing variable in memory (little endian).
Thx for help.
|
|
|
|
|
zuschauer1980 wrote:
int highbyte = Int16 & 0x00FF;
No, the high byte is the byte with the higher numeric value, so, it would be:
Int16 & 0xFF00
because FF00 > 00FF
[edit]Oops! That's actually not why it's the high byte. It's the high byte because it's higher in memory! It's probably less confusing if you talk in terms of the MSB and LSB (most significant byte and least significant byte[/edit]
But this just leaves the byte in the high byte position. What you probably want is something more like:
byte b=(byte)((Int16 & 0xFF00) >> 8);
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
Do this
Int16 val = 0x010C;
byte highVal = (byte)((val >> 8) & 0x00FF);
byte lowVal = ((byte) val & 0x00FF);
You needn't worry about the endianness, as both 0x00FF and your variable will be stored the same way in memory. Even if it is stored as 0C 01 in memory, when your program issues a CPU instruction to read a 16 bit value, you'll get back 0x010C.
So whatever the endianness, in your program, 0x01 is the high byte and 0x0C is the low byte.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
To get the high byte value (i.e. 0x01 in your example) use:
byte highByte = (byte) ( ( Int16 >> 8 ) & 0xFF );
byte lowByte = (byte) ( Int16 & 0xFF ); The right-shift operation moves all the bits in the number rightwards 8 places, moving the bits in the high-byte positions into the low-byte positions. The AND operation masks the bits you want to ignore for this operation.
Whether the memory storage is big- or little-endian doesn't really matter if you're using logic operations like this. What counts is how the processor sees it. In C you can do things like getting the raw addresses and reading the byte at the appropriate offset which is theoretically faster, but is also affected by the endian-ness of the CPU.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Thx for that clear description to you and all others!
now i have the second question...
one of these bytes is two's complement and should be transposed with the other byte. how have i to handle this?
|
|
|
|
|
Two's complement, if I recall it correctly, basically is:
Negate
Add one
If you store an Int16, either both bytes are two's complement of the original integer or both bytes are "plain" integer. There is no "mix".
Additionally, if you have not calculated two's complement yourself, you should not have to "reverse" it by hand.
I mean: If you shove "1823" into a variable and then print it, you will still get "1823", even if "1823" is stored as two's complement in memory.
That also means that the approach written in prior posts will still work, as you are manipulating the "1823", not two's complement of "1823".
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
ah you are right. two`s complement is just a way to store binary negative numbers. so when i make read access i will have the real value in the integer variable.
thx, for your thoughts.
|
|
|
|
|
Hi,
I have a checkedlistbox (clb) which populates on the form_load event and another listbox (lb) which is populated by the choices made in the clb.
The code to populate the lb is as follows
private void lbTerritoryAll_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
{
if( e.NewValue == CheckState.Checked)
{
lbTerritorySelected.Items.Add(lbTerritoryAll.SelectedItem.ToString());
}
else
{
lbTerritorySelected.Items.Remove(lbTerritoryAll.SelectedItem.ToString());
}
}
The problem is that in the 2nd listbox, all that appears is System.Data.DataRowView
My question is how can I make the data in the lb appear as correct text?
This is on a Windows form, not a webform.
Hope someone can help, thanks in advance
Scotty
|
|
|
|
|
Calling ToString on a DataRowView object will give you exactly what you are seeing in the ListBox .
A possible solution would be to cast the SelectedItem to DataRowView and then explicitely tell what info you want to be displayed:
lbTerritorySelected.Items.Add((lbTerritoryAll.SelectedItem as DataRowView)[columnIndexToShow].ToString());
|
|
|
|