///////////////////////////////////////////////////////////////////////////////// // / // +++ Copyright ©1998 Bjørn Larsen. +++ / // +++ " (c) " " " +++ / // / ///////////////////////////////////////////////////////////////////////////////// // // Thanks to the SNILLE for a copy of the demo. // // CENVI /BIND=netimer.EXE netimer.CMM // 22:06 11/02/00 #include #include #include testval = 0; count = 0; xxx = "0"; x = 1; DialHwnd.store = 0; jah.in = "jan"; jah.out = "jan"; jah.log = 0; // "0:00:00" NetTime.session = "0:00:00"; NetTime.cum = "0:00:00"; FileName = file_date(0); printf("\n Welcome to Netimer.\n\n"); Windowhandle = ScreenHandle(); // Windowhandle = GetWindowHandle("CEnvi - TEST"); // = Info().WinHandle; Left = 13; Top = 39; Right = 285; // lWidth = 269 // (Right - Left) Bottom = 500; // 520 lHeight = (Bottom - Top) x = SetWindowRect(WindowHandle,Left,Top,Right,Bottom); main() { // GoOnline(); printf("\n Checking...\n\n ...please wait...\n"); fq = fopen(FileName,"rt"); NetTime.cum = fgets(fq) // x = fread(fq, 8, NetTime.session); fclose(fq); printf("\n Netime:\n Total this month is %s\n", NetTime.cum); if (GoOnline()) { // x = 1; do{ x = loopo(x) } while (!x); printf("\n\n Netime:\n Total for %s : %s.\n", jah.in, NetTime.cum); printf("\n This Session is %s.\n",NetTime.session ); // NetTime.cum printf("\n EXIT: Press and hold any key.\n") while (!getch()) { suspend ( 1234 ) } } file_date(1); suspend (2345); printf("\t Thank you!") suspend (1234); exit(EXIT_SUCCESS); } loopo(inn) { if (inn) waiting() // COUNT IS THE HWND OF THE PASSWORD OR LOGON TIME SUBWINDOW count = ShowWindowAndChildren(0,GetDesktopWindow(),0); dialer = GetWindowHandle("Netscape Personal Edition"); if( dialer ){ // gets the hwnd prior to count p = DialHwnd.store; Title = GetWindowText(p); // printf("\nFound:%d\n",x); if (IsMatch(Title,"Connected:")){ // Connected: &Number to Dial: while (IsVis(p)) { xxx = GetWindowText(count); // we don't lose it if ((xxx)) NetTime.session = xxx; // if (NetTime.session) printf("logged on:%s\n",NetTime.session); suspend (4000); } NetTime.cum = NumbCrunch(NetTime.cum, NetTime.session, 1); IsMonth(); waiting(); } // end if connected NetTime.session = "0:00:00"; // try it here to stop doubletime if (IsMatch(Title,"Pa&ssword:")){ suspend (9876); // wait for logon while((IsVis(p))) { suspend (4000); // 9000 too slow } } } if ( GetWindowHandle("Netscape") ) { x = 0 } else { x = 1 } return (x); } NumbCrunch(net_time, net_twotime, add) // add = 1 add; add = 0 subtract. { // printf("\nInto NumbCrunch.\n\n \|%s\| + \|%s\|\n", net_time, net_twotime); t1me = 1; t2me = 2; t3me = "3"; x = 0; len.time = 0 // going to be 7,8,[or9] len.twotime = 0 len.time = strlen( net_time ); // going to be 7,8,[or9] len.twotime = strlen( net_twotime ); if ( len.time != len.twotime ) { if ( len.time < len.twotime ) { length = len.twotime } else { length = len.time } } else { length = len.time } // printf("%d length", length); diff = (len.time - len.twotime) if (diff) { if (diff > 0) { // net_time is longer // shift data by difference, the shorter to the right net_twotime = net_twotime - diff; net_twotime[0] = 48 ; // sets a zero instead of a NULL value // printf("%s %s %d damn",net_time, net_twotime, length); // y = getch(); } else { // net_twotime is longer net_time = net_time + diff; net_time[0] = 48 } // try ` => 96 48 => 0 } t1me = net_time; t2me = net_twotime; //*********************************************************************** do{ if ( t1me[x] != 58 ) { // t = 116 58 = : ? if (add) { t3me[x] = ( t1me[x] + t2me[x] ) - 48 } else{ t1me[x] = t1me[x] + 48; // subtract t3me[x] = t1me[x] - t2me[x] } // printf("1 %d , %d , %d\n",t1me[x], t2me[x], t3me[x]); } else { t3me[x] = 58 } // colon 116 = 58 * 2 // printf("2 %d , %d , %d\n",t1me[x], t2me[x], t3me[x]); x ++; } while ( x < length ); // printf("\nMid Sum: \'%s\'.\n\n", t3me); do{ // while (x) x --; // if ( t2me[x] != 58 ) { // printf("%d\t%d\n",x, t3me[x]); if (x != (length - 3) && x != (length - 6)) { // not ":" ( t2me[x] != 58 ) do{ chk=0; if (t3me[x] < 48 ) { chk = 1; t3me[x] = t3me[x] + 10; if (x == length - 2 || x == length - 5 ){ y = 2 } else { y = 1 } t3me[(x - y)] = t3me[(x - y)] - 1} // else {chk = 0} if (t3me[x] > 57 ) { chk = 1; t3me[x] = t3me[x] - 10; if (x == length - 2 || x == length - 5 ){ y = 2 } else { y = 1 } t3me[(x - y)] = t3me[(x - y)] + 1} // else {chk = 0} if (x == length - 2 || x == length - 5 ) { if (t3me[x] > 53) { chk = 1; t3me[x] = t3me[x] - 6; t3me[(x - 2)] = t3me[(x - 2)] + 1} } // else {chk = 0} }while (chk); } // end if ( not the colons ) // printf("%d\t%d\n\n",x, t3me[x]); } while (x); // printf("\nFinal Sum/diff: \'%s\'.\n", t3me); // getch(); // ********************************************************************* fq = fopen(FileName,"wt"); // ' OpenFile() Flags "wt" // "write, text" fprintf(fq,"%s", t3me); fclose(fq); return t3me; } ShowWindowAndChildren(ChildDepth,ParentHandle,count) { if (count < 0){ xxx = ParentHandle; // xxx = pHand; // printf("\n\n%d = xxx.\n", xxx ); //printf("Return this. ShowWindowAndChildren\(\).\n"); } count ++; if ( Title = GetWindowText(ParentHandle) ){ // use an if! formula? } else { Title = "none" } if (!(testval)) { testval = IsMatch(Title, "Netscape Personal Edition") } // once dialer found [testval = 1] until "Connected:" found if (testval == 1){ x = IsMatch(Title, "Connected:"); // Connected: &Number to Dial: if (x){ count = (-1); // get return value next Hwnd DialHwnd.store = ParentHandle; // Stop looking for Netscape, testval = 2; // jah.log = strncpy(jah.log,(ctime(time(t)) + 11),9); jah.log = time(d); printf("\n Logged on!\n"); // "Connected:" logon look for other first, then this one... // "Pa&ssword:" logoff find both if both valid hwnds } else { if ( IsMatch(Title, "Pa&ssword:")) { DialHwnd.store = ParentHandle; // ...but this will do count = 0; xxx = 0 } // count will be set to 0 except when Title matches "Connected:" // if (count == -1) { // printf("In ShowWin...\(\). We found : %d = %s\n",ParentHandle,Title); // } } } // Do this same routine for each child window of this window for ( ChildWindow = GetWindow(ParentHandle,GW_CHILD); ChildWindow; ChildWindow = GetWindow(ChildWindow,GW_HWNDNEXT) ) ShowWindowAndChildren(ChildDepth+1,ChildWindow,count); return (xxx); } file_date(out) { time = ctime(time(t)); xxx = strncpy(xxx,(time + 4),4); // month filename = FullPath(`net0feb.cum`); // FullPath(`\netimer\net_`); <=delete inset\=<***&&&%%% // printf ("%s",filename); //len = (strlen(FileName) - 6); FileName = strncpy(FileName, FileName, (strlen(FileName) - 6)); // FileName = FullPath(`net_ filename = strcat(filename, xxx); filename = strcat(filename,`.cum`); // string strcat(string dest,string src) // printf ("%s",filename); getch(); if (out) { printf("\n\n %s",time ); y = rand(); if ( y / 1600 < 6 && IsMatch(strlwr(jah.in), "dec") ) { // dec printf("\n Prepare for the New Year.\n\ Renew your *.cum files.") } // end if (out) } else { printf(" => %s",time ) ; jah.in = xxx; } // In return filename; } GetDesktopWindow() { return DynamicLink("USER","GETDESKTOPWINDOW",UWORD16,PASCAL); } IsMatch(sStr, str) { ok = 1; n = 0; do { if ( ( str[n] != sStr[n] ) ) { ok = 0; } n++; } while ( str[n] ) // <== while ( str[n] != NULL ) if ( sStr[n] ) { ok = 0; } return(ok); } IsVis(lHwnd) { // a short form of IsVisible() return DynamicLink("USER","ISWINDOWVISIBLE",SWORD16,PASCAL,lHwnd); } GetWindowText(pHwnd) { lText[0] = lText[500] = '\0'; if ( (lTextLen = SendMessage(pHwnd,WM_GETTEXT,499,lText)) < 0 ) return NULL; lText[lTextLen] = 0; return lText; } GoOnline() { xxx = Directory(`c:\nav\netscape.exe`); if (xxx == 0 ) { // printf("xxx\n"); getch() // printf("%d", xxx); getch(); F1 = strncpy(F1, FileName, (Strlen(FileName) - 18) ); F2 = strcpy(F2,F1); F3 = strcpy(F3,F1); F4 = strcpy(F4,F1); F5 = strcpy(F5,F1); F3 = strcat(F3, `dialer\default.sr`); F2 = strcat(F2, `dialer\dialer.exe`); F4 = strcat(F4, `netscape.exe`); F5 = strcat(F5, `bookmark.htm`); // puts(F1);puts(F2);puts(F3);puts(F4);puts(F5); getch(); spawn(P_NOWAIT, F2, F3); spawn(P_NOWAIT, F4, F5); } else { // default paths F2 = `c:\nav\dialer\dialer.exe`; F3 = `c:\nav\dialer\default.sr`; F4 =`c:\nav\netscape.exe`; F5 =`c:\nav\bookmark.htm` spawn(P_NOWAIT, F2, F3); spawn(P_NOWAIT, F4, F5); } // end second try to spawn if (!(GetWindowHandle("Netscape Personal Edition"))){ printf(" I'll wait while\n you start Netscape.\n"); puts(" ...or... Press Q to quit."); WaitForKeysHeld(); } x = GetWindowHandle("Netscape Personal Edition"); return (x) } IsMonth() { jah.out = ctime(time(t)); // full Date & Time String ntime = strncpy(ntime,(jah.out + 4),4); // the month // printf("%s %s\a\n",NetTime.cum, NetTime.session ); getch(); // string strncpy(string dest,string src,int MaxLen) if (!(IsMatch(jah.in, ntime))) { // is it a new month? NetTime.session = strncpy(NetTime.session,(jah.out + 11),9); // time // strlen = 8 + 1 for NULL terminator xxx = NumbCrunch(NetTime.cum, NetTime.session, 0); // printf("%s temp lilne",xxx); getch(); printf(" Adjusted %s Total is %s\n Netimer Month-end Audit.\n",jah.in, xxx); NetTime.cum = "Session time." FileName = FullPath(`net0feb.cum`); // FullPath(`\netimer\net_`); <=delete inset\=<***&&&%%% // printf ("%s",FileName); getch() FileName = strncpy(FileName, FileName, (strlen(FileName) - 6)); // FileName = FullPath(`net_ FileName = strcat(FileName, ntime); FileName = strcat(FileName,`.cum`); // string strcat(string dest,string src) // printf ("%s",FileName); getch() fq = fopen(FileName,"wt"); // ' OpenFile() Flags "wt" // "write, text" fprintf(fq,"%s", NetTime.session); fclose(fq); } // return (); } waiting() { printf("\n Not Logged on.\n\n ...waiting for connection...\n" ); } WaitForKeysHeld() // wait for keys to be held { do { suspend( 1000 ); } while (!KeyPressed(81) && !GetWindowHandle("Netscape Personal Edition") ); // !KeyPressed(113) } KeyPressed(pKey) // return boolen TRUE if keypressed now, else FALSE { return( 0x80 & DynamicLink("USER","GETKEYSTATE",SWORD16,PASCAL,pKey) ); }