Basic C++ GUI – TextOut trouble
The buttons start a 5 and 10 minute count-down, respectively, and the text is the remaining time.
I’m using CreateWindowEx for the buttons (in my WM_CREATE), and handling the time via SetTime and WM_TIMER messages (basically once every second taking down my time value).
Now for the problem.. my time shows as 0:0 (which is of course what it should be)… however it shows it all the time. It won’t update.
Please see the stripped down WndProc, and be so kind as to tell me what I’m doing wrong.
I appologise for the lack of indentation.. it appears that the forum trims it out.
LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps;
HDC hDC;
HWND FiveTimer,TenTimer,Panic;
HWND EditBox;
char time[]="xx:xx";
char mins[]="00";
char secs[]="00";
switch(Message) {
case WM_CREATE:
FiveTimer = CreateWindowEx(
NULL,
TEXT("Button"),
TEXT("5 MIN"),
WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
10,10,
100,50,
hWnd,(HMENU)ID_BUT_FIVE,
ghInstance,NULL);
if (FiveTimer==NULL){
MessageBox(hWnd,TEXT("Error – Could not create FiveTimer Button"),TEXT("Error"),MB_OK);
}
TenTimer = CreateWindowEx(
NULL,
TEXT("Button"),
TEXT("10 MIN"),
WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON,
10,70,
100,50,
hWnd,(HMENU)ID_BUT_TEN,
ghInstance,NULL);
if (TenTimer==NULL){
MessageBox(hWnd,TEXT("Error – Could not create TenTimer Button"),TEXT("Error"),MB_OK);
}
break;
case WM_PAINT:
itoa(MyMins,mins,10);
itoa(MySecs,secs,10);
strcpy(time,mins);
strcat(time,":");
strcat(time,secs);
hDC = BeginPaint(hWnd,&ps);
TextOutA(hDC,160,10,time,strlen(time));
EndPaint(hWnd,&ps);
break;
case WM_COMMAND:
switch(LOWORD(wParam)){
case ID_BUT_FIVE:
MyMins=0;
MySecs=4;
SetTimer(hWnd,ID_BUT,1000,NULL);
break;
case ID_BUT_TEN:
MyMins=0;
MySecs=9;
SetTimer(hWnd,ID_BUT,1000,NULL);
break;
default:
;
}
break;
case WM_TIMER:
if (MySecs==0){
if (MyMins==0){
KillTimer(hWnd,ID_BUT);
MessageBox(NULL,TEXT("TIMER EXPIRED!!"),TEXT("ALERT"),MB_OK);
}
else {
MyMins–;
MySecs=59;
SetTimer(hWnd,ID_BUT,1000,NULL);
}
}else if (MySecs>=1){
MySecs–;
SetTimer(hWnd,ID_BUT,1000,NULL);
}
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, Message, wParam, lParam);
}
return 0;
}
Here is the original:
Basic C++ GUI – TextOut trouble
30
