⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 autorundlg.cpp

📁 AppWizard has created this autorun application for you. This application not only demonstrates the
💻 CPP
📖 第 1 页 / 共 2 页
字号:
						ddd=a;
			            m_list.AddString("关机!"+cc+ddd);
					}
					else
					{
			            nu++;
			            goto top;
					}
				}
	            else
			      	m_list.AddString("即将运行程序位置: "+path[nu]);
			SetTimer(nu,m_sec*1000,NULL);
		}
    	else
	    	AfxMessageBox("请选择自动关机或自动运行程序!");
	}
	else
		AfxMessageBox("任务数量不能超过10,如果要添加任务,请删除现有任务!");
	
}

void CAutorunDlg::OnTimer(UINT nIDEvent) 
{
	switch(nIDEvent)
	{
	   case 1:TimeRun(1); break;
	   case 2:TimeRun(2); break;
	   case 3:TimeRun(3); break;
       case 4:TimeRun(4); break;
       case 5:TimeRun(5); break;
	   case 6:TimeRun(6); break;
	   case 7:TimeRun(7); break;
	   case 8:TimeRun(8); break;
	   case 9:TimeRun(9); break;
	   case 10:TimeRun(10); break;
	}

	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnTimer(nIDEvent);
}

void CAutorunDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	int panduan=0;
	for(int k=1;k<11;k++)
	{
		if(path[k].IsEmpty())
			panduan++;
		
	}
    CFileDialog dlg(TRUE,NULL,"请选择一个文件");
    if (dlg.DoModal()==IDOK)
	{
		if(panduan>0)
		{
cc:
	        if(nu>10)                                                 //如果settimer序号大于10 就该它重新值1
			    nu=1;
	        if(path[nu].IsEmpty())                                    //如果该数组为空 把就可以往里面存储数据
			{  
			    char a[100];                                           //设置缓冲区域为100个字符
		        itoa(nu,a,100);                                 
	    	    path[nu]=dlg.GetPathName()+"                   $"+a;   //在路径字符后面加上settimer序号, 因为不想在LISTBOX里把以$开头的序号显示出来,所以在$前面有少许空格"  "
		        m_radio.SetCheck(0);                                   //设置RADIO控件为未选中
			}
		    else
			{
			    nu++;                            
			    goto cc;                                               //跳转到cc 相当于一个循环
			}
        }
		else
		{
			AfxMessageBox("任务数量不能超过10,如果要添加任务,请删除现有任务!");
			CRect rcDialogWindow;
            GetWindowRect (rcDialogWindow);
            AfxGetMainWnd()->MoveWindow(rcDialogWindow.left,rcDialogWindow.top,330,170, true);
		    xs=true;
		    SetDlgItemText(IDC_BUTTON2,"隐藏[&H]");
		}
		}
}

void CAutorunDlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
	if(xs)
	{
	    CRect rcDialogWindow;                         
        GetWindowRect (rcDialogWindow);                                                    //获取窗口大小数据
        AfxGetMainWnd()->MoveWindow(rcDialogWindow.left,rcDialogWindow.top,330,90, true);    //改变窗口大小
		xs=false;
		SetDlgItemText(IDC_BUTTON2,"显示[&D]");
	}
	else
	{
		CRect rcDialogWindow;
        GetWindowRect (rcDialogWindow);
      AfxGetMainWnd()->MoveWindow(rcDialogWindow.left,rcDialogWindow.top,330,170, true);
		xs=true;
		SetDlgItemText(IDC_BUTTON2,"隐藏[&H]");
	}
}

void CAutorunDlg::ganji()
{
	    HANDLE handle;                                //↓关机代码 
        CString pszName= "SeShutdownPrivilege";
        CString pszSysName;
        LUID Luid;
        TOKEN_PRIVILEGES TkPriv;
        TOKEN_PRIVILEGES TkPriv2;
        unsigned long ulLen;
        handle = GetCurrentProcess();
        OpenProcessToken(handle,40,&handle);
        memset(&Luid,0x00,sizeof(Luid));
        LookupPrivilegeValue(pszSysName,pszName,&Luid);
        memset(&TkPriv,0x00,sizeof(TkPriv));
        TkPriv.PrivilegeCount = 1;
        TkPriv.Privileges[0].Luid = Luid;
        TkPriv.Privileges[0].Attributes = 2;
        memset(&TkPriv2,0x00,sizeof(TkPriv2));
        AdjustTokenPrivileges(handle,FALSE,&TkPriv,16,&TkPriv2,&ulLen);
        ExitWindowsEx (EWX_POWEROFF,0);	
    
}

void CAutorunDlg::DelStr(CString str)                            //根据str删除LISTBOX里选种的字符项
{  
    TCHAR a[100];
    CString ss; 
	for(int i=0;i<m_list.GetCount();i++)                         //循环LISTBOX控件 
	{                 
		m_list.GetText(i,a);
		ss=a;                                                     //获取LISTBOX选择的字符数据
		ss.Delete(0,18);                                          //删除 即将运行程序位置 18个字符
		ss=ss.Mid(0,ss.Find("$")-1);                              //筛选出$以前的字符
        ss.TrimRight();
		str.TrimRight();                                          //去掉变量右边空格
		if(ss==str)
		{
		     m_list.DeleteString(i);                              //删除LISTBOX上的一项数据
		}
	}
}

void CAutorunDlg::OnDblclkList1() 
{
	// TODO: Add your control notification handler code here
	char str[100];CString aaa,bbb;
	if((AfxMessageBox("是否要删除该任务?",MB_OKCANCEL|MB_DEFBUTTON2))==IDOK)
	{ 
		m_list.GetText(m_list.GetCurSel(),str);                                   //获取LISTBOX选择的字符数据      
  		TCHAR a[100];                                         	//设置缓冲区
	    CString ss;
	    for(int i=0;i<m_list.GetCount();i++)                                      //虚幻LISTBOX控件
		{ 
		    m_list.GetText(i,a);                                                  //根据序号获取LISTBOX字符控件
		    ss=a;
			bbb=str;
		    if(ss==bbb)                                                           //判断选取的字符和LISTBOX里的字符是否相同
			{   m_list.DeleteString(i);                                           //如果相同在LISTBOX上删除
				bbb.Delete(0,18);                                                 //删除 即将运行程序位置 18个字符
				for(int j=1;j<11;j++)                                             //循环PATH数组
				{   
                     CString zr(path[j]);
				     zr.TrimLeft();
				     bbb.TrimLeft();
					 if(zr==bbb)                                              //如果数组里的字符等于bbb(LISTBOX控件里的字符)
					 {
					 	 CString zr(path[j].Mid(path[j].Find("$")+1,1));
						 KillTimer(atoi(zr));      //根据字符里$后的序号 释放SETTIMER所设定的时间控件
						 path[j].Empty();                                          //把该数组项设为NULL
					 }
				}
			}
		 
		}
	
	}
}
void CAutorunDlg::TimeRun(int i)
{
          CString lin;
	      lin=path[i];
		  lin.Delete(lin.Find("$"),2); 
		  lin.TrimLeft();
		  if(lin=="1")
		  {    
			  ganji();
			  DelStr(lin);
		      path[i].Empty();
		      KillTimer(i);
		  }
		  else
		  {
		      lin.Replace("//","///");
		      ShellExecute(NULL,"open",lin,NULL,NULL,SW_SHOWNORMAL);
              DelStr(lin);
		      path[i].Empty();
		      KillTimer(i);       
		  }
}


void CAutorunDlg::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
    CAboutDlg ccc;
	ccc.DoModal();
	CDialog::OnRButtonDown(nFlags, point);
}

void CAboutDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
		// TODO: Add your control notification handler code here
	if(xxss)
	{
	    CRect rcDialogWindow;                         
        GetWindowRect (rcDialogWindow);                                                    //获取窗口大小数据
        this->MoveWindow(rcDialogWindow.left,rcDialogWindow.top,359,103);
		xxss=false;
		SetDlgItemText(IDC_BUTTON1,"说明[&S]");
	}
	else
	{
		CRect rcDialogWindow;                         
        GetWindowRect (rcDialogWindow);                                                    //获取窗口大小数据
        this->MoveWindow(rcDialogWindow.left,rcDialogWindow.top,359,260);
		xxss=true;
		SetDlgItemText(IDC_BUTTON1,"隐藏[&H]");
	}
}

BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CRect rcDialogWindow;                         
        GetWindowRect (rcDialogWindow);                                                    //获取窗口大小数据
        this->MoveWindow(rcDialogWindow.left,rcDialogWindow.top,359,103);
		xxss=false;
		SetDlgItemText(IDC_BUTTON1,"说明[&S]");
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	
	if (nCode == HC_ACTION)
    {
        KBDLLHOOKSTRUCT *pkbdllhook = (KBDLLHOOKSTRUCT *)lParam;
        switch (wParam)
        {
          case WM_KEYDOWN:
	           	 
			  if ( pkbdllhook->vkCode==VK_F9)
				 {
				     if(tftf)
					 {
						 ::ShowWindow(AfxGetMainWnd()->m_hWnd,SW_HIDE);
						 AfxGetMainWnd()->MoveWindow(450,300,0,0, true);
						 tftf=false;
					 }
					 else
					 {
						 ::ShowWindow(AfxGetMainWnd()->m_hWnd,SW_SHOW); 
						 AfxGetMainWnd()->MoveWindow(450,300,330,90, true);
						 tftf=true;
					 }
					 
					 break;
				 }
	 		     break;
        }
    }
 
	return CallNextHookEx( hkb, nCode, wParam, lParam ); 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -