Basic Controller Question
Hi,
I've been programming C++ in my spare time for a year or two, but am new to windows programming. I've been looking at a tutorial about programming stuff for windows, which is available here:
Windows API Tutorial: Generic
I have a question which I think is pretty simple. I doubt you guys would even need to download the example to understand the problem. Say if you add the following to the top of control.cpp:
#include <time.h>
#include <ctime>
Then, at the top of your MainWndProc function,
time_t seconds;
time(&seconds);
int timenow = clock() / CLOCKS_PER_SEC;
And, after pCtrl is declared in MainWndProc,
if (timenow > 1)
pCtrl->Paint ();
And finally, you delete pCtrl->Paint (); from beneath case WM_PAINT: in the message loop.
What happens is, instead of it displaying a line/ some text when the program starts, it waits a couple of seconds and then displays it. And then, when you close the program, it crashes, presumably because pCtrl has been deleted. OK, so if that's the case, is there a way to check if pCtrl is in existence when I do this? By the way the reason I check if timenow is over 1 is because it doesn't work otherwise.
if (timenow > 1)
pCtrl->Paint ();
Thanks.