11-12-2015 03:51 PM
I try to obtain the file path of an open text file (in Notepad). I don't know what I am doing wrong but I obtain an empty string.
The function is at : https://msdn.microsoft.com/en-us/library/windows/desktop/ms683197%28v=vs.85%29.aspx
11-12-2015 07:08 PM
This function need handle of module as input, not a handle of window.
FindWindow returns the handle of the window.
You also get the input parameter order incorrectly.
The first input is the handle, the second the the output of filename.
11-13-2015 02:50 AM - edited 11-13-2015 02:52 AM
Aside from what Geoge Zou has pointed out to you, you have likely a fundamental problem here. Only the application that opened a file knows its path. If that application supports some Inter Application Communication you MAY be able to query that application for the path of the currently opened file. However Notepad as far as I know does not support any Inter Application Communication interface, not even DDE beyond the minimum neccessary to allow interaction with the Windows shell.
A possibility might be to use an alternate text editor which does allow remote control through interapplication communication. Although Notepad++, my text editor choice, as far as I can see doesn't have such an interface out of the box, but most likely there are plugins that would allow this. Other possible text editors might be Sdriptly, Ultraedit, or TextPad, with the last explicitidly supporting a DDE remote control interface.
But maybe you should rethink the reason for having to know the path of a text file used in an external text editor. Is that really what you need? Might it be possible to integrate a simple text editor component in your LabVIEW application, either through Active X or .Net or simply in a text string on the front panel?
11-13-2015 09:37 AM - edited 11-13-2015 09:40 AM
Thanks Zou and Rolfk, I was afraid of that.
Let me explain what I tried to do.
I want to have a Unicode string control. The problem is that I have lot of crash in LabVIEW (2013 to 2015) and with the executable. The problem came, I think, from that I have the "UseUnicode = true" in the init file (executable and development). I need this key (in the executable init file) because I want to have the VI Title in UTF-16. Whitout the key, the UTF16 title appears like garbage.
I created a XControl to "act like a unicode string control":
1) when I left click the mouse, Notepad opens a file named Unicode.txt (located in the default data directory). If this file don't exist it is created (with the BOM).
2) The XControl monitor the modification of this file. When we save this file, the XControl is automatically updated.
3) If the user don't close Notepad, it will automatically close after a delay (Time before Notepad close (sec)). This delay starts after the last save.
If the user change the encoding of the file (ASCII, UTF16 Big Endian or UTF-8), I manage that.
My problem is if the user use "Save as" and change the name or the location of the file. I have in memory the window handle of this Notepad. This is the reason that I asked if it there a way to retrieve the file path with a particular Notepad window handle, it seems not, thanks.