|
One thing no one really addressed is why you need to be able to do this? What is the problem you are trying to solve where you think you need to know the type of a null object?
Scott Dorman Microsoft® MVP - Visual C# | MCPD
President - Tampa Bay IASA
[ Blog][ Articles][ Forum Guidelines] Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
|
|
|
|
|
Hi All
I have send keys to the application(other) which i have started using my windows form .
By using API and managed code SetForeGroundWindow.. and SendKeys.Send...
This is working fine.But while my application sends keys if a user click on any other window then that(window on which user clicked) get the keys not the window for which it was meant.
So i had to chose other way.
Now I am using SendMeassage API and I want to send a Key to that application
[DllImport("User32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(int hWnd, int Msg, int wParam,int lParam);
I have got the handle(hwnd) of the window to which i want to send a key(for here say F1 key)
public const WM_KEYDOWN =0x100; /which is one of the possible value of msg
/Here It is for keydown event.
public const VK_F1=0x70;
// it is a virtual key code for F1 to be passed in wparam
For lparam i have following inf
lParam
Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table.
0-15
Specifies the repeat count for the current message. The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative.
16-23
Specifies the scan code. The value depends on the OEM.
24
Specifies whether the key is an extended key, such as the right-hand ALT and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value is 1 if it is an extended key; otherwise, it is 0.
25-28
Reserved; do not use.
29
Specifies the context code. The value is always 0 for a WM_KEYDOWN message.
30
Specifies the previous key state. The value is 1 if the key is down before the message is sent, or it is zero if the key is up.
31
Specifies the transition state. The value is always zero for a WM_KEYDOWN message.
Return Value
An application should return zero if it processes this message.
I do not know how to pass lparam to the function.
Note:I have set 0x00 for lparam and i am gettingreturn value 0 which i had stored in a variable.This means the message was processed by the window according to return value condition above.But I did not saw any Help window of that application.
Please guide in using lparam particularly for case of KeyDown msg of F1
Thanks
THE SK
(Sandeep Kalra)
"I am the One"
|
|
|
|
|
In this case, lparam is a 32 bit value that contains a 16 bit int, an 8 bit int, a 1 bit bool, a 4 bit reserved block, then 3 1 bit bools.
0-15 16-23 24 25-28 29 30 31
[16 bit int] [8 bit int] [bool] [reserved] [bool][bool][bool]
0000000000000000 00000000 0 0000 0 0 0
Combined to form a 32 bit (binary) value.
00000000000000000000000000000000
If you want to pass something into one of these you need to work out where in the bit string the value needs to go, and then combine it to form a 32 bit value you can pass.
But I don't think you need to be passing anything on the lparam. none of them look like they are needed. I would instead suggest that you probably need to send a wm_keyup message aftwards. A lot of apps only respond to keydown when it is followed by a keyup message.
Simon
|
|
|
|
|
Hi
Now I have used SendMessage API for both WM_KEYDOWN and WM_KEYUP . But still nothing happens.
I have also included SecurityPermission for unmanaged code.
I am not getting any warning or errors.I have already tried 0 as value for lparam but nothing happens no exception no warning etc.
Please guide
THE SK
(Sandeep Kalra)
"I am the One"
|
|
|
|
|
Then you are doing something wrong.
Does the app you are sending the key two definitely handle F1 key presses?
Are you sending the correct code for the F1 key?
Try writing your own app to receive a key down/up message for the F1 and check it works. That will check that you are doing the sending correctly. If you are, then maybe the receiving app isn't handling keyup/down messages.
Simon
|
|
|
|
|
Hi
Thats the Internet Explorer to which I am sending F1 key.It responds to F1 key if i press it on keyboard.
Is it really the case that IE donot responds to WM_KEYUP or WM_KEYDOWN events.I have tried for WM_CLOSE and for quit too but it did not worked.
I am trying to find.
THE SK
(Sandeep Kalra)
"I am the One"
|
|
|
|
|
Sandeep Kalra wrote: I have tried for WM_CLOSE and for quit too but it did not worked
Then like I said. You are doing something wrong.
Simon
|
|
|
|
|
How do you know you're sending the messages to the right window?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have the handle of that window to which i wanted to send the message.
I have also found that the PostMessage API which has same parameters as that of SendMessage ,is working fine.
Declared this above in code
[DllImport("user32.dll",EnteryPoint="PostMessage"]
public static extern bool PostMessage(int hwnd,int msg,int wparam,int lparam)
[DllImport("user32.dll",EnteryPoint="SendMessage"]
public static extern int SendMessage(int hwnd,int msg,int wparam,int lparam)
I am transferribg same parameters to the PostMessage and SendMessage by declaring them public ,on two different button_click event on my form
Button with a PostMessage is working fine.But button_click with SendMessage is not working at all.I am not getting any warning, error or runtime errror.
Also found that WM_KILLFOCUS,WM_QUIT are not working on PostMessage.However WM_CLOSE ,WM_KEYDOWN,WM_KEYUP worked fine.
I do not know whats wrong(sure not coding).Please suggest.
And I also want to know whic among SendMessage and PostMessage is more reliable
|
|
|
|
|
To make a lParam integer, try this:
public int MakeLParam(int loWord, int hiWord)
{
return ((hiWord << 16) + loWord);
}
public int MakeWParam(int loWord, int hiWord)
{
return ((hiWord << 16) + loWord);
}
Now, all you have to do is construct the two parts of the lParam value, and pass them into one of those functions.
You may also want to look at this page:
http://www.pinvoke.net/default.aspx/user32/SendInput.html[^]
As usual, a little googling would have saved you *and us* HOURS of time.
[EDIT] and the univoter strikes again. I provide an answer and get 1'd. How f***ing pathetic.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
modified on Tuesday, October 14, 2008 7:06 AM
|
|
|
|
|
hi to all,
I m facing a problem with Ajax modalpopupextender.
I'am passing a parameter to the model popup, which gets displayed on the popup,
For the next parameter, the popup is not refreshed, still the previous parameter is
shown on the popup.
Thanks & Regards,
sai krishna
|
|
|
|
|
Hi,
I am having spanish characters as memorystream, when i give this stream to xmldocument.load - it gives me Invalid characters errro. How to solver this isssue.
Be simple and Be sample.
|
|
|
|
|
Which encoding do you use for the characters, and what encoding is specified in the xml header?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
check encoding and update it accordingly.
Cheers!!
Brij
|
|
|
|
|
Make sure the encoding is the same. You should probably use UTF-8
ASCII tables, HTML entities, types, string formats and more info for the serious coder at: www.codecharts.com
|
|
|
|
|
Ok, three people so far have suggested that it's the encoding that is the problem.
Anyone else why want to suggest that it's the encoding that is the problem before we close?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: Anyone else why want to suggest that it's the encoding that is the problem before we close?
Not me.
I'm thinking there's characters in the stream that are invalid for the encoding of the XML.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hai
I am developing an application in C#.NET to control processes in remote machine I successfully started a process in remote machine but it is not visible ,it is visible only in task manager.Please help to make it visible
Sree
|
|
|
|
|
|
hi evreyone
is it possible to use xml file as database ?
if yes, is someone has any sample code in C# that can do Insert,Update and Delete job's ?
thank's alot for any help
|
|
|
|
|
Yes you can. But it doesnt mean you should. Performance wise its even a worse idea.
To do insert/update/delete you will need to load the xml document, find the node that you want as parent (for insert) or the node you want to update/delete, perform the action you need to do and then save the document again.
Loading the document once and keeping it in memory will speed up the process if its small amounts of data, else you'll find yourself running out of memory soon.
Hope this helps.
|
|
|
|
|
thank's for the quick anser
by database is very very small and i think,
that it will be better to use xml insted access or sql server
can i get any sample ?
|
|
|
|
|
As Guffa has said, its easy to load the data in a datatable and then save it as xml. That will increase query performance. That will however increase your xml document size.
If you dont want to use that way, heres a really simplified example of an update to a xml file:
<?xml version="1.0"?>
<Employees>
<Employee>
<ID>1</ID>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
</Employee>
<Employee>
<ID>2</ID>
<FirstName>Peter</FirstName>
<LastName>Pan</LastName>
</Employee>
</Employees>
string xmlFilePath = @"C:\Employees.xml";
int EmployeeIdToUpdate = 2;
string NewEmployeeLastName = "Panne";
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(xmlFilePath);
System.Xml.XmlNode eNode = doc.SelectSingleNode("Employees");
for (int i = 0; i < eNode.ChildNodes.Count; i++)
{
System.Xml.XmlNode employeeNode = eNode.ChildNodes[i];
int ID = int.Parse(employeeNode.SelectSingleNode("ID").InnerText);
if (ID == EmployeeIdToUpdate)
{
//Perform action
employeeNode.SelectSingleNode("LastName").InnerText = NewEmployeeLastName;
}
}
doc.Save(xmlFilePath);
Hope this helps.
|
|
|
|
|
You can save and load a DataTable as xml. Load the DataTable, change the DataRow items, and then save it.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
good.....
can i get code sample ?
|
|
|
|