473,387 Members | 1,321 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,387 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 6113
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...
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:
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?
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.