How to select specfic txt file... if more then one is opened!

G

Guest

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
 
G

Guest

solution

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

Problem:

If the same file name .txt file is opened then what? means from different
directory the same file name is opened then.... it will select the first file.

How to get full path of all .txt file, so then we compare and write ? or How
to select specfic file in that v want to write?
 
M

Mihajlo Cvetanovic

Sandy said:
solution

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

Problem:

If the same file name .txt file is opened then what? means from different
directory the same file name is opened then.... it will select the first file.

How to get full path of all .txt file, so then we compare and write ? or How
to select specfic file in that v want to write?

You could use CreateProcess() to run Notepad, with the file you want. In
the structure PROCESS_INFORMATION you will get the handle of the process
and the handle of the main thread.

Use the handle of the process in WaitForInputIdle(). After that use
handle of the main thread in EnumThreadWindows(). You need to define
your callback function of type WNDENUMPROC, like this:

BOOL CALLBACK EnumNotepadProc(HWND hwnd, LPARAM lParam)
{
if ( <hwnd is of class Notepad> ) // I'm not exactly sure how...
{
*(HWND*)lParam = hwnd;
return FALSE;
}
else return TRUE;
}

Call EnumThreadWindow like this:

HWND hNotepadWnd;
EnumThreadWindow( dwThreadId, EnumNotepadProc, &hNotepadWnd );

Now you're sure you have the real Notepad window.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top