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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
case WM_TIMER:
{
corsel=0;
GetSystemTime(&st);
curTime = st.wHour * 10000 + st.wMinute * 100 + st.wSecond;
curRegion = DetectRegion(x,y);
if (curRegion != -1){ //cursor not in picture region
sprintf(buff,"%d %d\n",curRegion,preRegion);
OutputDebugStr(buff);
if (curRegion != preRegion) { //In a new region
startTime = curTime;//start time equal to current time
preRegion = curRegion;
}
}else{//cursor is in picture region
startTime = curTime;
}
if ((curTime - startTime) > 3){//time interval is longer than 3 sec
selectedRegion = curRegion;
if (selectedRegion == correct_integer){
attempt = 0;//selected is same as correct integer
if (loginFlag == false){
loginFlag=true;
corsel++;
if(corsel>=2)
{
KillTimer(hwnd, ID_TIMER);
sprintf(buff,"Correct Login!",selectedRegion);//correct login indicated in the selected region
MessageBox(NULL, buff, "Success", MB_OK);
exit(0);
//sprintf(buff,"Correct Login!",selectedRegion);//correct login indicated in the selected region
//MessageBox(NULL, buff, "Success", MB_OK);
//KillTimer(hwnd, ID_TIMER);// kill timer
//exit(0);
}
else
{
sprintf(buff,"correct %d\n",selectedRegion);//correct login indicated in the selected region
OutputDebugStr(buff);
KillTimer(hwnd, ID_TIMER);// kill timer
sprintf(buff,"Correct! %d more correct pic.",2 - corsel);
MessageBox(NULL,buff, "success", MB_OK);
ret = SetTimer(hwnd, ID_TIMER, 1000, NULL);
initPicture();
InvalidateRect(hwnd,NULL,true);
startTime = curTime;
corsel++;
}
sprintf(buff,"correct %d\n",selectedRegion);//correct login indicated in the selected region
OutputDebugStr(buff);
//KillTimer(hwnd, ID_TIMER);// kill timer
//sprintf(buff,"Correct! %d One more correct pic.",2 - attempt);
//MessageBox(NULL,buff, "success", MB_OK);
//ret = SetTimer(hwnd, ID_TIMER, 1000, NULL);
//
//initPicture();
//InvalidateRect(hwnd,NULL,false);
//startTime = curTime;
}
}else{
attempt++;
loginFlag=false;
if (attempt >= 3){//if more than 3 retry, exit program
KillTimer(hwnd, ID_TIMER);// kill timer
sprintf(buff,"Lock out!",selectedRegion);//correct login indicated in the selected region
MessageBox(NULL, buff, "Warning", MB_OK);
exit(0);
}
sprintf(buff,"Incorrect %d\n",selectedRegion);//correct login indicated in the selected region
OutputDebugStr(buff);
KillTimer(hwnd, ID_TIMER);// kill timer
sprintf(buff,"Incorrect! Try again. %d retry left.",3 - attempt);
MessageBox(NULL,buff, "Warning", MB_OK);
ret = SetTimer(hwnd, ID_TIMER, 1000, NULL);
initPicture();
InvalidateRect(hwnd,NULL,false);
startTime = curTime;
}
}
break;
}
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}
Please help I'm really stressed
|