473,386 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

SendMessage API

I am trying to use the SendMessage API function using
EM_POSFROMCHAR to get the x,y location of the current
character. I have declared the function and placed the
call into my code. How do I access the x,y coordinates.
Some example code in C# would be greatly appreciated.
Nov 15 '05 #1
6 4157
Steve,

I think you can get away with this by using the following declaration
for SendMessage:

// Note, you have to set the function name, depending on the platform to do
this. You can't
// just use "SendMessage" for the entry point.
[DllImport("user32.dll", EntryPoint="SendMessageA")]
public static extern int SendPosFromCharMessage(
IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)] int Msg,
ref Point wParam,
IntPtr lParam);

The Point structure in .NET has the same layout as the POINTL structure
that the EM_POSFROMCHAR message expects. Also, declaring it this way should
handle the marshaling of the structure automatically.

If you didn't want to use this method, then you would have to declare a
structure and marshal it using the static StructureToPtr method on the
Marshal class and then pass that to the SendMessage function declared with
the wParam and lParam parameters as IntPtr values.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Steve" <ho******@cmmts.com> wrote in message
news:03****************************@phx.gbl...
I am trying to use the SendMessage API function using
EM_POSFROMCHAR to get the x,y location of the current
character. I have declared the function and placed the
call into my code. How do I access the x,y coordinates.
Some example code in C# would be greatly appreciated.

Nov 15 '05 #2
Nicholas,

thank you for the response. I know this may sound dumb - I
understand how to declare the function (although the
MarshalAs was something I hadn't thought of). My problem
is, I am unsure of how to issue the call and where the
information (point) is for retrieving the information. I
think this may have something to do with my lack of
experience with CALLBACK routines and pointers. Further
explanation of this would be appreciated.
-----Original Message-----
Steve,

I think you can get away with this by using the following declarationfor SendMessage:

// Note, you have to set the function name, depending on the platform to dothis. You can't
// just use "SendMessage" for the entry point.
[DllImport("user32.dll", EntryPoint="SendMessageA")]
public static extern int SendPosFromCharMessage(
IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)] int Msg,
ref Point wParam,
IntPtr lParam);

The Point structure in .NET has the same layout as the POINTL structurethat the EM_POSFROMCHAR message expects. Also, declaring it this way shouldhandle the marshaling of the structure automatically.

If you didn't want to use this method, then you would have to declare astructure and marshal it using the static StructureToPtr method on theMarshal class and then pass that to the SendMessage function declared withthe wParam and lParam parameters as IntPtr values.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Steve" <ho******@cmmts.com> wrote in message
news:03****************************@phx.gbl...
I am trying to use the SendMessage API function using
EM_POSFROMCHAR to get the x,y location of the current
character. I have declared the function and placed the
call into my code. How do I access the x,y coordinates.
Some example code in C# would be greatly appreciated.

.

Nov 15 '05 #3
Nicholas,
// Note, you have to set the function name, depending on the platform to do
this. You can't
// just use "SendMessage" for the entry point.


Why do you say that?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #4
Mattias,

I'm going by the examples. In the examples for using the EntryPoint in
the documentation for the DllImport attribute, the EntryPoint property is
set to "SendMessageA". Trying this out myself, however, it would seem the
documentation is misleading.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:ux**************@TK2MSFTNGP10.phx.gbl...
Nicholas,
// Note, you have to set the function name, depending on the platform to dothis. You can't
// just use "SendMessage" for the entry point.


Why do you say that?

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Nov 15 '05 #5
I'm going by the examples. In the examples for using the EntryPoint in
the documentation for the DllImport attribute, the EntryPoint property is
set to "SendMessageA".
Oh, okay.

Trying this out myself, however, it would seem the
documentation is misleading.


Yep, as long as you don't set ExactSpelling=true you should be able to
specify just SendMessage.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #6
F.Y.I. I ended up using a rich text box and used the
GetPositionFromCharIndex function. This saved me from
using potentially unsafe code.
-----Original Message-----
I'm going by the examples. In the examples for using the EntryPoint inthe documentation for the DllImport attribute, the EntryPoint property isset to "SendMessageA".
Oh, okay.

Trying this out myself, however, it would seem the
documentation is misleading.


Yep, as long as you don't set ExactSpelling=true you

should be able tospecify just SendMessage.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.comPlease reply only to the newsgroup.
.

Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Mark Overstreet | last post by:
I am trying to click a button in another window and I have it's hWnd value so I was trying to use Send message. Here is my code but it doesn't work as expected... response =...
3
by: JSK | last post by:
Hi, As any one worked in VB.NET and made use of Sendmessage API? The Issue I am running into is how to pass pointers of Data Structures (UDT) to the SendMessage. I starting looking at "IntPrt"...
0
by: SamSpade | last post by:
In my C# library I have many SendMessages like the following: public static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, ref PARAFORMAT2 pf2); I use this one like this:
3
by: Rob | last post by:
Hi all, I am having trouble converting the code below (found on http://vbnet.mvps.org/index.html?code/core/sendmessage.htm) into a format that will work using vb .NET. Can anyone have a look...
18
by: Lars Netzel | last post by:
Hello! Thanx to this newgroup I have finally, with the help of you guys, gotten this to work halfway.. but the final action is still not working, clicking the "Button2" thru SendMessage(). ...
3
by: Max M. Power | last post by:
When I use the SendMessage API I can sucessfully send and receive a user defined message. When I use the PostMessage API I can NOT sucessfully send and receive the same user defined message. ...
4
by: Abubakar | last post by:
Hi, My application has a lot of threads which at some point call SendMessage api passing it the handle of the gui window. The calls r a lot. My question is that should I call the SendMessage api...
22
by: SQACSharp | last post by:
I'm trying to get the control name of an editbox in another window. The following code set the value "MyPassword" in the password EditBox but it fail to return the control name of the EditBox. ...
1
by: Necromis | last post by:
Ok, I have gotten my head around things better regarding SendMessage and FindWindow functions. However, I am running into an issue with my code still. The program I am working with is EXTRA! by...
5
by: michelqa | last post by:
Hi, I need to call a lot of different native SendMessage to retreive informations from non managed application. Some win32 messages use struct pointer for lparam....how to create and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.