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?
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.
Related
It's maybe stupid question, but what happens behind the scenes when i double click the word app, or .exe app?
For 'Non-Developer' it just opens the file in right environment after doubleclicking. But I would like to know, how is it done, how can the file manager know what to open? (.docx in word, .txt in texteditor,etc...)
+ I would like to know how can I do that in Node.js, is it the best way to use child_process and if statements for every suffixes?
There is a file association to tell Windows how to treat a certain file extension. You can type assoc in a Windows Command Prompt to see them. As an example:
C:\test>assoc .txt
.txt=txtfile
So Windows knows now, that the file with the extension .txt is a txtfile.
ftype defines, how that filetype is to be handled:
C:\test>ftype txtfile
txtfile=%SystemRoot%\system32\NOTEPAD.EXE %1
So whenever you doubleclick on a file, Windows checks if it is associated with any filetype. Then it looks up, how to handle that filetype and executes that command (in the example above, it opens Notepad with the filename as a parameter).
Both assoc and ftype are able to change the settings (for example to open .txt files with another editor). But if you try that, do yourself a favor and note the original settings, so you are able to revert your changes when needed.
The changes can also be done directly in the registry (not recommended, when you are not experienced in handling the registry)
For Node.js, you can use child_process to shell out to the start command which does similar things as the File Explorer.
E.g. start some/path/to/file.docx will open that file in the default program associated with the format.
Here's my problem:
I want to open an Excel file which serves as a template. This file should be edited and then saved. The name is a variable, so it should always change. I.e. variable A that changes all the time.
With the function [xlsread] I open the template and with the function [xlswrite] I can change it as I like and it works without problems. The problem is I can't save the file separately, that means that after editing the template I only get 1 file back, but I want to keep the template and get an edited file so I can use the template again. I could not find a way to save the edited Excel file.
Please help me
There is a mistake in your thinking. xlsread reads the whole file and keeps it in memory. When you use xlswrite your variables from memory are written to a file, with no link to the file read (as long as you change the file name).
That having said, please note that Matlab recommends to use writetable/writematrix/writecell instead of xlswrite. The same is true for xlsread => readtable/readmatrix/readcell.
I work on a custom project system and I have an issue with renaming items. The project system implementation is based on MPF and renaming items via the solution explorer worked more or less without any problems, but...
When an item gets renamed, I also update information which are stored in the file itself. In case the document is opened by the code editor, the text in the editor doesn´t get refreshed (only the document window´s caption changes to the new filename). If I save the open document all changes applied by the rename operation are overriden, of course.
How can I force the editor to reload the document, so that the automatic changes will be shown?
Assuming it's a text file versus some custom designer, use the IVsRunningDocumentTable interfaces to get the text buffer for the file that's currently open. The fourth iteration of the interface is the easiest one to use from managed code. You can call IsMonikerValid (where the "moniker" is the file name) to see if the file is open, and if so then call GetDocumentData to get the IVsTextBuffer for the file. That type itself is fairly annoying to work with, so if you're only supporting Visual Studio 2010 or later, then pass that to this function to get the newer editor APIs version of it.
As far as they "why" it's a good idea to do this: if you edit the file on disk and then try to force a reload, there are various problems you might run into. If the file wasn't saved before the rename, you might accidentally lose those unsaved edits. The reload might cause the undo history of the file to be lost, and any other extensions/features that were tracking points in the file with editor tracking spans or markers might lose the points they're tracking. Performance should be a bit better too if the file is a large file.
I'm looking for a way to have Excel files in my Matlab folder open 'outside Matlab' (i.e., by MS Excel in most cases) directly by double-clicking the file, rather than right-clicking and selecting 'Open Outside Matlab'.
The .xls files reader built in Matlab can be terribly slow for large files, and an unwanted double-click on a file can cost quite some time in which Matlab is unresponsive.
Thanks.
When you click something in the Current Folder tab, it's actually running the open command, which itself calls finfo to determine what it means by "open" for a given extension. You can see this by creating a breakpoint in open.m directly after the line [~, openAction] = finfo(fullpath); and double clicking - when it hits the breakpoint you'll see it returns openAction as uiimport.
In theory, you can create custom methods for extensions by creating on the path a function openabc where abc is the extension, which should be returned as the openAction.
However, if I look at my finfo.m it first searches for said functions and then regardless of whether or not it finds them if there is an inbuilt method it overwrites them with the standard behaviour. There's even a comment:
% this setup will not allow users to override the default EXTread behavior
If you are willing to muck about in the inbuilts, you may be able to do it like this (backup first! - this could affect other things). I did it temporarily by shadowing the existing finfo like this:
edit finfo.m (Now save a copy to the current folder)
Add these lines after the loop that defines the openAction (in my version, around line 85):
if any(strcmp(['.' ext], matlab.io.internal.xlsreadSupportedExtensions))
openAction = 'winopen';
end
From the folder containing your edited finfo.m, type which finfo -all. You should see two copies, the MATLAB one labelled as shadowed. Opening something from the current folder window should now open Excel externally.
I don't believe there's any straightforward way to do that. It's built in to MATLAB that Excel files will open in the import tool when you double click on them, and there's no way to change that.
You might be able to get around it by changing the file extension on your Excel files to something other than .xls or .xlsx. That would stop MATLAB from opening it in the import tool. Then in Windows, you could associate the new file extension with Excel.
I have a specific requirement in our organization.
We are using a third-party tool to convert excel to pdf. Our excel files contain financial data and charts and the tool converts them to pdf files. Once converted, they are sent for printing.
Now I need to write a vb code which tampers with the printer configuration. After conversion to pdf, when I click on print in the tool, it should not go to default printer to print the physical file, nor should it display the dialog box asking for printer to choose, rather it should pop-up a custom dialog box indicating file being saved in the network drive. The drive and file name should be pre-configured.
I know there are quite a few solutions which caters to this problem of saving a file without displaying the default dialog box but my problem is, I am not printing files from the same application. Files are prepared by a third-party application and print option is pressed from here itself. When the file leaves for printing, I want my code to take effect. In a way, if this application is configured in a computer, no matter which tool you are using to print, the files should get saved to a network drive without popping up the default print dialogue box.
Thanks in advance. Any guidance is much appreciated.