469,568 Members | 1,397 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

sending data to opened notepad file in desktop

can mfc application, send text data to opened notepad file in desktop?(live
transfer of data) . can anybody help

Nov 17 '05 #1
9 2797
"Sandy" <Sa***@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com...
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

Nov 17 '05 #2
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

"William DePalo [MVP VC++]" wrote:
"Sandy" <Sa***@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com...
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

Nov 17 '05 #3
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
"Sandy" <Sa***@discussions.microsoft.com> wrote in message
news:79**********************************@microsof t.com...
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

"William DePalo [MVP VC++]" wrote:
"Sandy" <Sa***@discussions.microsoft.com> wrote in message
news:FD**********************************@microsof t.com...
> 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

Nov 17 '05 #4
Sandy wrote:
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

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

Nov 17 '05 #5
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);



"Steve Alpert" wrote:
Sandy wrote:
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

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

Nov 17 '05 #6
"Sandy" <Sa***@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
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
Nov 17 '05 #7
Dear William

You are Great Man
Thanks, Now its working well

Regards
Sandeep

"William DePalo [MVP VC++]" wrote:
"Sandy" <Sa***@discussions.microsoft.com> wrote in message
news:F1**********************************@microsof t.com...
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

Nov 17 '05 #8
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?
"William DePalo [MVP VC++]" wrote:
"Sandy" <Sa***@discussions.microsoft.com> wrote in message
news:EE**********************************@microsof t.com...
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



Nov 17 '05 #9
"Sandy" <Sa***@discussions.microsoft.com> wrote in message
news:5D**********************************@microsof t.com...
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?


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
Nov 17 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Buddy Ackerman | last post: by
reply views Thread by Buddy Ackerman | last post: by
38 posts views Thread by Tom | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.