Hi. I'm pretty new to C++ but have been working with regular C for +20 years so this is a new world for me.
I have a question about update of content of a created window. I been trying to make a simple counter that just print out Test = 1 to 9 in a second. Program works fine but don't print anything out until after a second. The result is always the same. Test = 9. So where in the code does the printout actually happen?
Attached is the code of the printout loop. Thanks for the help. This is very different from C.
void Delay(long ulmilliSec)
{
clock_t set = clock();
while((clock() - set) < ulmilliSec); ///loop until time's up
}
void MainWindow::Paint( void )
{
int iCnt;
char csBuffer[] = "Test = 1"; // 8
PAINTSTRUCT ps;
HDC hdc = BeginPaint( hWnd, &ps );
for (iCnt = 0; iCnt < 9; iCnt++) {
TextOut( hdc, 20 /* X */, 20 /* Y */, csBuffer, 8 /* Number of char */);
csBuffer[7]++;
Delay(100);
}
EndPaint( hWnd, &ps );
}
I agree that will work fine in console mode but that is not what I'm doing. The code you saw I copied is only a little piece of the actually program where I create a window and in that window I was trying just to have a number increment between 1 and 9. As far as I can see it does not do the printout in the textout function like a printf or cout. I'm trying to figure out where it actually happen. I have been trying to single step in debug mode but for some reason the program breaks down. I using Borland C++ ver 5.03 compiler and IDE. Thanks for your input anyway.
PS.
I don't know why the code not came out wit the right indent in the printout. Maybe I should replace the tabs with spaces. Ha Ha. Sorry about that. It can be tough to read that way.
Windows are event driven, do not use Sleep() in a GUI thread! Instead, create a timer SetTimer() which updates the text buffer and notifies the window to re-paint InvalideRect(). The paint handler should be responsible for painting only.
Thank you very much Sloppy9. That was exactly what I was looking for. I know it was event driven and thought the event was interrupt driven that's why I made my own delay and didn't use sleep. I guess I been working to much with microcontrollers. Ha Ha. Thanks again.