Logging button clicks etc

Hi,

I'm writing two programs at the moment. One is for an administrator and the other is for a user. The admin program is essentially a form that someone fills in using richtextboxes etc. This information is then written to a file that the user program reads and displays the information that the administrator has set up.... Fairly simple stuff to a seasoned programmer.

My next function is something that I am unsure of the correct terminology. Hence my google searchs are going nowhere. The user program has some buttons and I would like the admin program to see how many times a particular button has been clicked. The way I'm thinking is for this information (user button clicks) to be written to say a text file and the admin program then reads this file to get this information.

I know how to read and write to files but I don't know how to code recording the number of button clicks... Can someone please point me in the right direction?

Thanks.
you want the clicks cout to be updated and stored as the user clicks? or only when he quits the program? process the WM_LBUTTONDOWN message to increment a variable each time the user clicks on the button with the specific ID (HMENU)
to update the clicks live. you can write the WriteFile() function inside the WM_LBUTTONDOWN message, or set it as global variable (static) and put the WriteFile() function in the closing message of the program. and dont forget to set the variable to 0 before the counting.
Last edited on
Hi igor1985,

Live would ideal because I'm guessing that the same format of code would be needed to run another idea of my which is an instant message function type of thing which is stored as a log file too....

Anyway, yes live click updates would be good so the admin program can check at any time how the user is going (clicking buttons etc).

Thanks
Could the term you're looking for be interprocess communication?

http://msdn.microsoft.com/en-us/library/windows/desktop/aa365574%28v=vs.85%29.aspx
Hi igor1985 and knn9.

I haven't used WM_LBUTTONDOWN at this stage as you suggested, igor1985.

However this is what i've managed so far...

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
\\global variable
static int iNumberOfClicks = 0;

...

\\All code below is within the button click event
iNumberOfClicks ++;
textBox1->Text = "Number of Clicks:	" + iNumberOfClicks;


\\Writes number of clicks to file
StreamWriter^ sw = gcnew StreamWriter("C:\\ClickLog.txt");
sw->Write(textBox1->Text);
sw->Close();

\\Reads file to display number of clicks:
ifstream fin("C:\\ClickLog.txt");
string str;
String^ str2;
if (fin.is_open())
{
   while (fin.good() )
	{
		getline (fin,str);
		str2 = gcnew String(str.c_str());
		textBox2->Text = str2;
	}
   fin.close();
}
else 
	{  
		textBox2->Text = "Unable to open ClickLog.txt"; 
	}


As you can see I have textBox1 that the changing variable is displayed in. This string is then written to the file ClickLog.txt. Then I read that file and display the string into textBox2. I'm just simulating what the two programs would do in the one form to test. Simple stuff...

However, the reading of the file occurs when the button is clicked. As I said in the first post that I have two programs. The 'admin' program needs to recieve the number of clicks as they happen in the 'user' program. Would a 'looped' and 'timed' (of say a 100 millisecond or so) function work in the form load event of the admin program?

i.e. every 100 milliseconds, the form reload and re - reads the file to get an update of the number of clicks...

Cheers
Last edited on
Don't bother with the file, altough it will work, not without proper syncronization. I'd use a named pipe or shared memory to directly comunicate with the server (admin) program.

If you insist on using a file (or you need permanent storage) use SQLite library, do not use plain WriteFile/ReadFile directly, as you will get into trouble very soon due to lack of proper syncronization (locking). Needless to say that polling every 100ms or so requires (wastes) CPU power.
http://www.sqlite.org/
Thanks Morodan.

You suggested a named pipe or shared memory rather than my own suggestion. I don't know what these are. Do you recommend any resources that I could read up about these? I'm relatively new to programming...

Ultimately there would be the one admin program running while up to 30 user program's. These user program's would be on separate machines but all running of the same network.

Cheers
You suggested a named pipe or shared memory rather than my own suggestion. I don't know what these are. Do you recommend any resources that I could read up about these? I'm relatively new to programming...

You didn't actually read the link I posted, did you?
Topic archived. No new replies allowed.