MFC-timed off a software

Source: Internet
Author: User

First one.

How to close a process:

int Terminateprocessfromid ()   //{        BOOL bRet=FALSE;         if (hprocess!=NULL)        {               bRet=::terminateprocess (hprocess,0);        }        :: CloseHandle (hprocess);         return 0 ; }

Event for Start button

voidCchendlg::onbnclickedbtnstart () {//TODO: Add control notification handler code hereCString Currpid; DWORD dwId;//Current PIDM_CURRPID.GETWINDOWTEXTW (currpid); DwId=_ttoi (currpid); Hprocess=:: OpenProcess (PROCESS_ALL_ACCESS,FALSE,DWID); if(hprocess==NULL) {MessageBox (L"No program found, please enter the correct PID"); }    Else{SetTimer (1, +, NULL); MessageBox (L"operation successful, start monitoring"); }}

Operation in the OnTimer

voidCchendlg::ontimer (uint_ptr nidevent) {//TODO: Add Message Handler code and/or call default values hereCdialogex::ontimer (nidevent);     CString localtime; TM=Ctime::getcurrenttime (); inthour =TM.    Gethour ();    CTime Closetm; //Set the end time hereClosetm =ctime (tm. GetYear (), TM. GetMonth (), TM. GetDay (),4,0,0,-1);    CTimeSpan s; if(hour>4)    {        //description to span the number of days//get the time of the last second of the dayCTime finallytime =ctime (tm. GetYear (), TM. GetMonth (), TM. GetDay (), at, -, -,-1); CTimeSpan Finallyspan= finallytime-TM; //Closetm = CLOSETM+FINALLYSPAN+HOUR4;s = Finallyspan + CTimeSpan (0,4,0,1);//4 hours    }    Else{s= closetm-TM; if(s<=0)         {            //that means it's time.Terminateprocessfromid (); M_time. SETWINDOWTEXTW (L"(0 seconds) program is turned off"); KillTimer (1); }    }    intM_hour=s.gethours (); intM_min =s.getminutes (); intm_s =s.getseconds ();    CString Timestr; Timestr.format (_t ("%d minutes%d seconds"), m_hour,m_min,m_s); LocalTime=tm. Format ("%y year%m month%d day%x");    M_CURRTIME.SETWINDOWTEXTW (localtime); M_time. SETWINDOWTEXTW (TIMESTR);}

MFC-timed off a software

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.