VC++ to achieve the procedure boot start operation method

  • 2020-04-02 02:34:31
  • OfStack

The example described in this paper mainly introduces how to make the program boot automatically under VC++. Generally speaking, it is added to the boot item, which is the practice of many programs. The specific realization idea is to use the win.in file to realize the automatic boot of related programs. Mainly through WritePrivateProfileString function to achieve. Here's how to implement this.

The main function code is as follows:


HCURSOR CAutoRunDlg::OnQueryDragIcon()
{
 return (HCURSOR) m_hIcon;
}
void CAutoRunDlg::OnBrowse()
{
 //Browse only exe files
 CFileDialog fileDlg(TRUE,_T("EXE"),_T("*.exe"),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,(_T("Executable Files (*.exe) |*.exe ||")));//Displays the open file dialog box
 //When the operator selects OK, the program takes the full path name of the selected file (including the path and file name of the file) and transfers the corresponding value to the relevant control variable.
 if(fileDlg.DoModal()==IDOK)
  {
 m_strFileName=fileDlg.GetPathName();//M_strFileName is the full path that saves the program that needs to be executed automatically
 //Displays the value of a variable to the control.
 UpdateData(FALSE);
  }
}
void CAutoRunDlg::OnApply()
{
 //Update the data
 UpdateData(TRUE);
 //To ini file
 LPCTSTR filename;
 filename=m_strFileName;
 WritePrivateProfileString(_T("windows"),_T("load"),filename,_T("c:windows\win.ini"));
}

Boot up is a useful feature that interested readers can test out for themselves.


Related articles: