Hi,
I am trying to find text in a window. I can get the handle to the
window but when I try using SendMessage the return value is very large
number. When I use Spy++ to see the return value it is FFFFFFFF. I
don't think SendMessage is working correctly to find the text. Can
somebody help me out here with the parameters that need to be passed
and if I am passing them correctly.
How do i specify the pointer to string member in the FindText
structure in C#?
My code is as follows:
public long FindTextW()
{
RichEdit.FindTe xt tEx;
sText = "John\0";
IntPtr lstrPtr = Marshal.StringT oCoTaskMemAuto( sText);;
//tEx is the FINDTEXT structure
tEx.lpstrText =lstrPtr;
tEx.chrg = tCR;
tEx.chrg.cpMax = -1;
tEx.chrg.cpMin = 0;
IntPtr lPtr = Marshal.AllocCo TaskMem(Marshal .SizeOf(tEx));
Marshal.Structu reToPtr(tEx, lPtr, true);
lR = RichEdit.SendMe ssage((IntPtr)m _hWnd,RichEdit. EM_FINDTEXT,0,l Ptr);
return lR;
}
The value I get for lR is 922281240691107 4303 which doesn't seem
right!!
Any help will be really appreciated!
Thanks,
jbhan 4 2351 The value I get for lR is 922281240691107 4303 which doesn't seem right!!
Then you've probably declared the return type as long, which is
incorrect. It should be more like
[DllImport("user 32.dll", CharSet=CharSet .Auto)]
static extern IntPtr SendMessage(Int Ptr hwnd, uint msg, IntPtr wParam,
IntPtr lParam);
Also, I don't thing Windows will marshal the parameters of this
message cross process boundaries, so you can probably only expect it
to work if you send it to a control in your own process.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Thanks for the info. I changed the return type for SendMessage to IntPtr and I get a return value of -1
I am basically trying to FindText in an open Outlook window (I am able to get the handle to the window) from my windows application.I can even get the total number of text lines in the Outlook window using SendMessage. But the same api fails for FINDTEXT
Do you have an idea what is wrong with my parameters and if there is any other way I can pass them
Really appreciate your help
Thanks
jbha Do you have an idea what is wrong with my parameters and if there is any other way I can pass them?
There's probably nothing wrong with your parameters. It just doesn't
work to send this message cross process boundaries. You'd have to get
code running inside the Outlook process one way or another to do this.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
I am running this code in an Outlook addin, so I presume it is running in the same process as Outlook
Even there I get a constant error "Object reference not set to an instance of an object"
What am I missing here?
Any pointers would be really great
Thanks
jbhan. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: none |
last post by:
Hello all, I wrote a shell program a few years ago in VB6 that needs
to be modified. The problem I have is this:
The SysAdmin uses this shell in place of Explorer, so there is no
taskbar. When his users run PC Anywhere from the shell, and minimize
it, it minimizes to the system tray. With no task bar, there is no
system tray, so there is no way to restore the PC Anywhere window.
The shell starts PC Anywhere using ShellExecute. I...
|
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 = Win32API.SendMessage(hWndYesButton,Win32API.BM_SETSTATE,0,null);
response = Win32API.SendMessage(hWndYesButton,Win32API.WM_LBUTTONDOWN,1,"11");
response = Win32API.SendMessage(hWndYesButton,Win32API.WM_LBUTTONDOWN,1,null);
response =...
|
by: jbhan |
last post by:
I am trying to find text in a window. I can get the handle to th
window but when I try using SendMessage the return value is very larg
number. When I use Spy++ to see the return value it is FFFFFFFF.
don't think SendMessage is working correctly to find the text. Ca
somebody help me out here with the parameters that need to be passe
and if I am passing them correctly
How do i specify the pointer to string member in the FindTex
structure...
|
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 at it and let me know what I need to change. I
have tried changing the "hwnd" type into intptr's but there seem to be
other problems too, like it won't allow "lParam As Any" to be
declared.
|
by: Frederik Vanderhaegen |
last post by:
Hi,
I'm trying change the layout of a combobox when f.e. a certain property is
set to true.
My problem is the following: when I execute the code, the combobox is
repainted but there always stays an area unpainted.
After soms research I discovered that a combobox also contains a textbox.
With the windows api function GetComboBoxInfo I can retrieve a handle to
that textbox.
When I create a graphics object with that handle and try to...
| |
by: Abubakar |
last post by:
Hi all,
My solution consists of 2 projects, 1 is a dll (contains sockets
functionality, multithreaded), and the other is a wtl gui project. Both are
totally unmanaged. The gui app has a edit box, acting as a console, where I
send messages from dll to be displayed. The way I am sending messages is:
for sending the message:
void CGlobal::SendMessage(char * chptr )
{
|
by: Mayur |
last post by:
I tried followinf but working fine fo int but how to do it for string using
user custome message
in c#
public static extern int FindWindow(string strClassName,string
strWindowName);
|
by: d-42 |
last post by:
Hi,
I'm pretty sure I've just got a Marshalling problem, but I'm
completely stumped. If there is a better newsgroup to post this in,
please point me towards it.
First I'm trying to use SendMessage() with WM_COPYDATA to send a
string data between two instances of a program. As part of the
debugging I've written two methods one where a given instance will
obtain its own hWnd and send itself the message, one where it accepts
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |