Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / February 2005

Tip: Looking for answers? Try searching our database.

sending data to opened notepad file in desktop

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sandy - 03 Feb 2005 06:29 GMT
can mfc application, send text data to opened notepad file in desktop?(live
transfer of data) . can anybody help
William DePalo [MVP VC++] - 03 Feb 2005 07:04 GMT
> can mfc application, send text data to opened notepad
> file in desktop?(live transfer of data) . can anybody help

I'm not sure if I understand what the crux of your question is. Is it how to
manipulate Notepad or how to do data transfer?

The former question is easy to answer. This little hack will do the job. It
is a command line application whose first parameter is the title (caption)
of the instance of Notepad to which you want to deliver the text and the
second is the text itself. If either contains spaces you'll need to quote
it.

#include <windows.h>
#include <iostream>

int main(int argc, char **argv)
{
HWND hNotepad, hEdit;

if ( argc != 3 )
{
 std::cout << "Enter xxx \"title\" \"text\"" << std::endl;
 std::cout << "   where title is the caption of Notepad's window" <<
std::endl;
 std::cout << "   and text is the text you want to insert" << std::endl;
}

hNotepad = FindWindow("Notepad", argv[1]);

if ( hNotepad == 0 )
{
 std::cout << "Failed to find Notepad's main window" << std::endl;
 exit(0);
}

hEdit = FindWindowEx(hNotepad, NULL, "edit", NULL);

if ( hEdit == 0 )
{
 std::cout << "Failed to find Notepad's edit control" << std::endl;
 exit(0);
}

SendMessage(hEdit, WM_SETTEXT, 0, (LPARAM) argv[2]);

return 0;
}

If you are asking about live data transfer in general then the answer could
(and has) filled entire books. The example above uses Windows to do the
heavy lifting - its WM_SETTEXT message is designed to move character data
into a Window. If you want to move something other than text to something
other than a window post some more details for some ideas.

Regards,
Will
Sandy - 03 Feb 2005 08:35 GMT
Dear William

1. Suppose "abc.txt"(notepad) file is already open in desktop.
2. My VC++6 mfc, application wants to write the data in abc.txt.

example...when u open abc.txt then...  in notepad there are 5line of text ,
then new data should be display in 6th line... that 6th line coming in
notepad is seen by user. that 6th line data is coming from your vc++ appln.

Thanks

> > can mfc application, send text data to opened notepad
> > file in desktop?(live transfer of data) . can anybody help
[quoted text clipped - 52 lines]
> Regards,
> Will
Antti Keskinen - 03 Feb 2005 09:36 GMT
Hello !

There is a small misunderstanding. Writing data to 'abc.txt' is not the same
thing as writing data to Notepad's edit control.

To hack Notepad, use the code piece that William posted. But before sending
WM_SETTEXT, send WM_GETTEXT, which will retrieve the currently written text
on Notepad's edit control. Then to this local string, append the results you
want to write (the 6th line) and use WM_SETTEXT to update changes in
Notepad. This result is an effect of 'new line appearing in Notepad',
although what you actually did was rewrite the entire contents of the edit
control.

Note that Notepad will not save the changes into 'abc.txt' unless you
command it seperately (via UI or sending another message) to save the file.
The process outlined above will only update the text displayed in Notepad's
edit control. It will not affect the actual file unless changes are
explicitly saved.

-Antti Keskinen

> Dear William
>
[quoted text clipped - 69 lines]
>> Regards,
>> Will
Steve Alpert - 03 Feb 2005 17:34 GMT
> can mfc application, send text data to opened notepad file in desktop?(live
> transfer of data) . can anybody help

to be most general, why don't you simply offer to copy the text to the
clipboard and the user can do whatever they want with it?

/steveA

Signature

Steve Alpert
my email Fgrir_Nycreg @ vqk.pbz is encrypted with ROT13 (www.rot13.org)
and spaces

Sandy - 07 Feb 2005 05:05 GMT
Hi!

Writing to opened (.txt file) notepad is solved.
PROBLEM :  when vc++ application,  is writing data to opened notepad, then
small
------------   rectangle are coming in .txt file & "\n" is also not working.

Using following code:
               
               ::SendMessage(hEdit, WM_GETTEXT, iLength+1, (LPARAM)textData);
    CString temp = textData;
    temp += "\n";
    temp += "MFC";
               sprintf(textData,"%s",temp);
               ::SendMessage(hEdit, WM_SETTEXT, 0,(LPARAM)textData);

               
               

> > can mfc application, send text data to opened notepad file in desktop?(live
> > transfer of data) . can anybody help
[quoted text clipped - 3 lines]
>
> /steveA
William DePalo [MVP VC++] - 07 Feb 2005 05:29 GMT
> Writing to opened (.txt file) notepad is solved.
> PROBLEM :  when vc++ application,  is writing data to opened notepad, then
> small
> ------------   rectangle are coming in .txt file

Those are likely to be "control" codes

> "\n" is also not working.

Try using

   "\r\n"

instead.

Regards,
Will
Sandy - 07 Feb 2005 06:33 GMT
Dear William

You are Great Man
Thanks, Now its working well

Regards
Sandeep

> > Writing to opened (.txt file) notepad is solved.
> > PROBLEM :  when vc++ application,  is writing data to opened notepad, then
[quoted text clipped - 13 lines]
> Regards,
> Will
Sandy - 07 Feb 2005 14:01 GMT
Hi!

If more than one notepad is opened in desktop.. then its work for "top"
notepad only
Want to ... write a data in specfic .txt file. for example abc.txt, but if
"top.txt" is at top at desktop then, the data is written in top.txt.... not
in abc.txt.

code: working for only when one notepad is opend / for top notepad at desktop
HWND hNotepad, hEdit;
hNotepad = ::FindWindow("Notepad",NULL);
hEdit = ::FindWindowEx(hNotepad, NULL,"edit", NULL);

int iLength = (int)::SendMessage(hEdit, WM_GETTEXTLENGTH, 0, 0);   
::SendMessage(hEdit, WM_GETTEXT, iLength+1, (LPARAM)textData);

CString temp = textData;
    temp += "\r\n";
    temp += "MFC";
::SendMessage(hEdit, WM_SETTEXT,0,(LPARAM)textData);

I had try..... ( Not working.. if more then one / abc.txt is not at top in
desktop)
hNotepad = ::FindWindow("Notepad","abc.txt");
hNotepad = ::FindWindow("Notepad","abc");

HWND FindWindow( LPCTSTR lpClassName, LPCTSTR lpWindowName); //syntax
If the lpWindowName parameter is not NULL, FindWindow calls the
GetWindowText function to retrieve the window name for comparison.

GetWindowText cannot retrieve the text of a control in another application.

How to select specfic txt file... if more then one is opened!
I want to write the data in specfic file that i supply in program
Help Me Please

> Dear William
>
[quoted text clipped - 21 lines]
> > Regards,
> > Will
William DePalo [MVP VC++] - 07 Feb 2005 15:17 GMT
> If more than one notepad is opened in desktop.. then its work for "top"
> notepad only
> Want to ... write a data in specfic .txt file. for example abc.txt, but if
> "top.txt" is at top at desktop then, the data is written in top.txt....
> not
> in abc.txt.

OK.

To answer the question you asked, what you need to do is to change this
line:

   hNotepad = ::FindWindow("Notepad",NULL);

to

   hNotepad = ::FindWindow("Notepad","abc.txt - Notepad");

Notepad is little more than a frame window with an edit control child and a
menu. You might want to think about using your own frame and edit control so
that you could maintain an association between window handles and file names
and note have to use FindWindow().

Regards,
Will
Sandy - 19 Feb 2005 07:17 GMT
Hi

In the same discussion... Can i get current cursor position in open notepad
hNotepad = ::FindWindow("Notepad","abc.txt - Notepad");

Bcoz i want insert data at current cursor position..
Example; if notepad file having 10 line and my cursor is at 5 line... can i
get it?

> > If more than one notepad is opened in desktop.. then its work for "top"
> > notepad only
[quoted text clipped - 21 lines]
> Regards,
> Will
William DePalo [MVP VC++] - 20 Feb 2005 01:09 GMT
> In the same discussion... Can i get current cursor position in open
> notepad
[quoted text clipped - 4 lines]
> i
> get it?

Notepad contians an edit control. Edit controls provide messages both to
report on and change the current selection.

Check the docs for EM_GETSEL. It gets the "selection range". The end of the
range is where the caret (what you call cursor) is. You can use
EM_LINEFROMCHAR and the end of the selection range to get the line number
containing the caret. EM_LINEINDEX can be used to get the first character of
a given line. Subtracting the two positions will yield the offset from the
start of the line.

You should either post follow-up in a UI group or check the docs for the
messages that edit controls support. The messages that are specific to edit
controls have names that begin with "EM_"

Regards,
Will

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.