473,383 Members | 1,859 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,383 software developers and data experts.

SendMessage and Handles

I have an app that includes two side by side Rich Text controls. What I need
to do is keep both controls synchronised, such that if I scroll the left rtb
up or down then the right one scrolls by the same amount in the same
direction.

In my simplistic mind, I believe that this can be achieved by sending an
EM_GetScrollPos message to the left rtb and using the results to send an
EM_SetScrollPos message to the right one. Problem is that I'm converting
over from VB6 and have no idea how to

a) Call the SendMessage API,
b) Code a "POINT" structure in C# for use in the call, or
c) Find the windows handle of the Rich Text box.

All of which means that I have a very long way to go to achieve a very
simple function. Can anyone please point me at some code that does this
please? Better still, can I achieve this in native C# code?

Thanks
Steve
Nov 17 '05 #1
3 6112
Steve,
a) Call the SendMessage API,
You first declare it like this

[DllImport("user32.dll", CharSet=CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr wParam,
ref Point lParam);

then call it like any other method.

b) Code a "POINT" structure in C# for use in the call, or
You can use System.Drawing.Point in its place.

c) Find the windows handle of the Rich Text box.


Each control has a Handle property that returns it.
Mattias

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

See inline:
a) Call the SendMessage API,
Check out http://www.pinvoke.net. It will have the declaration of
SendMessage. You might have to tweak it for your specific message. In the
case of SetScrollPos, you will want to use this:

[DllImport("user32.dll", CharSet = CharSet.Auto, EntryPoint = "SendMessage",
ExactSpelling = false)]
static extern int SendEmSetScrollPosMessage(
IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)]
int Msg,
IntPtr wParam,
ref System.Drawing.Point lParam);
b) Code a "POINT" structure in C# for use in the call, or
You can use System.Drawing.Point. It will marshal correctly.
c) Find the windows handle of the Rich Text box.
The RichTextBox control exposes a Handle property which you can use to
get the handle. Actually, the Control class exposes it, so all controls
expose their handle.

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

All of which means that I have a very long way to go to achieve a very
simple function. Can anyone please point me at some code that does this
please? Better still, can I achieve this in native C# code?

Thanks
Steve

Nov 17 '05 #3
Much appreciated guys.

Steve

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:O%******************@tk2msftngp13.phx.gbl...
Steve,

See inline:
a) Call the SendMessage API,


Check out http://www.pinvoke.net. It will have the declaration of
SendMessage. You might have to tweak it for your specific message. In
the case of SetScrollPos, you will want to use this:

[DllImport("user32.dll", CharSet = CharSet.Auto, EntryPoint =
"SendMessage", ExactSpelling = false)]
static extern int SendEmSetScrollPosMessage(
IntPtr hWnd,
[MarshalAs(UnmanagedType.U4)]
int Msg,
IntPtr wParam,
ref System.Drawing.Point lParam);
b) Code a "POINT" structure in C# for use in the call, or


You can use System.Drawing.Point. It will marshal correctly.
c) Find the windows handle of the Rich Text box.


The RichTextBox control exposes a Handle property which you can use to
get the handle. Actually, the Control class exposes it, so all controls
expose their handle.

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

All of which means that I have a very long way to go to achieve a very
simple function. Can anyone please point me at some code that does this
please? Better still, can I achieve this in native C# code?

Thanks
Steve


Nov 17 '05 #4

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

Similar topics

6
by: Daniel Kaffee | last post by:
Please, please, please can somebody post here how to use the Sendmessage API call to send the keystrokes Alt B, "Y", Tab (*7), "Danny" to an application that I have the windows handles and PID's...
3
by: Sn | last post by:
Does anyone know how to use the SendMessage() function to save a text file in UTF-8 format. what are the Msg, Wparam and the lParam parameters passed to the function?
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(). ...
4
by: paraidy | last post by:
Hi all, reading some examples in this group i'm trying to send a text to notepad, but it doesn't work, can someone to correct my code? Thx Private Declare Function FindWindow Lib "user32.dll"...
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...
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...
3
by: deepthi82 | last post by:
Hi All, I'm trying to close a browser window either by sending Alt+f4 or Alt+f to open the file menu and then 'x' to exit and am trying to achieve this using win32api.SendMessage(). I tried all...
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.