1

I want to open and read a file which has not been saved. I would like to do this in Windows OS with VC++ or by means of a batch file only.

If I open up the file by normal method of fopen or fopen_s, the file is opened in the last saved manner which is not what I want. I want all the data which is present in the file but not yet saved.

I have read something on this in this link. Similar question. But I am unable to follow the scripts. Can someone please convert it into a batch and give it to me?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Prasad
  • 5,946
  • 3
  • 30
  • 36
  • If the file hasn't been saved, I don't see how it could be opened and read because that would imply that the file was being read *before* it was written. If you want to read a file into one program while it is being written by another program, perhaps your need would be met better by using a [pipe](http://stackoverflow.com/questions/6877697/communicating-between-two-child-processes-with-pipes) between the two processes? – Simon Jan 25 '13 at 04:59
  • I can't use pipe because I have don't have control over the process which is writing the data into the file. – Prasad Jan 25 '13 at 06:47

1 Answers1

0

I believe you mean read the contents from a window or control. Files are made only after data is saved.

To read contents of a window like the edit control in Notepad, you first have to get a handle to the control. You can do this using FindWindow to first get the handle of the main window and then use it in FindWindowEx to get the handle of the edit control.

Once you have the handle of the control, you can send it WM_GETTEXT message using SendMessage to read the text it contains.

Please note that this may not work for all applications. For example, MS-Word uses a rich edit control which had its own methods to fetch text.

Superman
  • 3,027
  • 1
  • 15
  • 10
  • Thanks for the reply. But the problem is FindWindow works only for those applications which have a window. My software writes into the notepad in the background and doesn't appear in the foreground in form of any window. Please can you tell me how should I go about it? – Prasad Jan 25 '13 at 06:46
  • If you mean that the notepad window is not visible or is hidden, you can still use `FindWindow`. – Superman Jan 25 '13 at 12:20