MFC 开机启动

  1. //开机启动函数 
  2. void CCommWizardDlg::OnBnClickedCheckStart() 
  3.     CString   str; //添加注册表路径  
  4.  
  5. WCHAR*     CurrentPath= new WCHAR[sizeof(WCHAR)*100];//程序当前路径 
  6. HKEY   hRegKey;   //注册key 
  7. BOOL   bResult;   //打开注册表返回值 
  8. str=_T("Software\\Microsoft\\Windows\\CurrentVersion\\Run");//注册表    
  9. GetModuleFileName(NULL,(LPSTR)CurrentPath,MAX_PATH); //获得运用程序路径 
  10.  
  11. if ( BST_CHECKED == IsDlgButtonChecked( IDC_CHECK_START ) ) 
  12. // 勾选 
  13.     if(bResult=RegOpenKey(HKEY_LOCAL_MACHINE,   str,   &hRegKey)   !=   ERROR_SUCCESS)//打开注册表      
  14. {    
  15.    //free(CurrentPath); //打开不成功就释放内存并返回 
  16.    delete[] CurrentPath; 
  17.    return;    
  18. }    
  19. if(bResult=::RegSetValueEx(hRegKey,_T("StarBySelf"),0,REG_SZ,    
  20.    (const   unsigned   char   *)CurrentPath,    
  21.    MAX_PATH)!=   ERROR_SUCCESS)   //打开成功写信息到注册表 
  22. {   //写入失败 
  23.    RegCloseKey(hRegKey);   //关闭注册表key 
  24. //   free(CurrentPath);   //释放内存资源 
  25.    delete[] CurrentPath; 
  26.    return;   //返回 
  27. else  
  28.     //写入成功后执行释放内存 
  29. ifChecked = true
  30.  
  31. RegCloseKey(hRegKey);    
  32. // free(CurrentPath); 
  33. delete[] CurrentPath; 
  34.  
  35.  
  36.  
  37. else 
  38.     if(bResult=RegOpenKey(HKEY_LOCAL_MACHINE,   str,   &hRegKey)   !=   ERROR_SUCCESS)//打开注册表      
  39. {    
  40.    //free(CurrentPath); //打开不成功就释放内存并返回 
  41.    delete[] CurrentPath; 
  42.    return;    
  43. }    
  44.  
  45. if(!RegDeleteValue(hRegKey,_T("StarBySelf"))) 
  46.    { 
  47. //    MessageBox(_T("删除注册表成功!")); 
  48.     ifChecked = false
  49.     RegCloseKey(hRegKey); 
  50.     delete[] CurrentPath; 
  51.    } 
  52.    else 
  53.    { 
  54.     MessageBox(_T("注册表删除失败!")); 
  55.     RegCloseKey(hRegKey); 
  56.     delete[] CurrentPath; 
  57.    } 
  58.  
  59.  
  60.  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值