find window text and save txt to file named that wont work.
- by blood
hi, my code wont work and idk why. the point of my code is to find the top window and save a text file with the name the same as the text on the top menu bar (task bar i think?). then save some data to that text file. but everytime i try to use it the write fails if i set the name of the text file before hand so it wont change it will write the data to the file. but if i don't set it before hand it will make the text doc but not write anything to it. or sometimes it will just write numbers for the name (i think it's the handle number) then it will write the data. :\ it's odd can anyone help?
#include <iostream>
#include <windows.h>
#include <fstream>
#include <string>
#include <sstream>
#include <time.h>
using namespace std;
string header_str = ("NULL");
#define DTTMFMT "%Y-%m-%d %H:%M:%S "
#define DTTMSZ 21
char buff[DTTMSZ];
fstream filestr;
string ff = ("C:\\System logs\\txst.txt");
TCHAR buf[255];
int main()
{
GetWindowText(GetForegroundWindow(), buf, 255);
stringstream header(stringstream::in | stringstream::out);
header.flush();
header << ("C:\\System logs\\");
header << buf;
header << (".txt");
header_str = header.str();
ff = header_str;
cout << header_str << "\n";
filestr.open (ff.c_str(), fstream::in | fstream::out | fstream::app | ios_base::binary | ios_base::out);
filestr << "dfg";
filestr.close();
Sleep(10000);
return 0;
}