Thread: Configuration Function "How to link different .exe program" for a .txt file

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    48

    Smile Configuration Function "How to link different .exe program" for a .txt file

    Hi GOOD DAY!

    I a a newbie to C++.
    I got a question. Could you give me some suggestion?

    i am modify a small edit tool now.
    How to improve a new function that user could configure a different edit tool which user installed at their local OS to Open "*txt" file?
    My program default take us Notepad to open *.txt file.
    But i want to imporve the function which user could open the explore and select one edit tool(such as my local editplus) ,Save the change. and user coudl open view file (.txt) with the new editplus now.


    (I find that "WinSCP" improved the fucntion, it is really very cool.)

    Thanks!

    pingz

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Does your program call notepad explicitly? If so, then don't do that.

    Does your program call on the OS to use the default text editor? If so, then you'll have to change the default text editor in the OS.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    48
    Quote Originally Posted by tabstop View Post
    Does your program call notepad explicitly? If so, then don't do that.


    Does your program call on the OS to use the default text editor? If so, then you'll have to change the default text editor in the OS.
    I have my tool source code writed by my colleague, but he already quit now.
    i just want modify source code and improve the new feature.

    i don't want to modify OS and set the default text ediotr. for the tool also will release to more user, i juat want to enhance the new open .txt function.

    Current function, the log.txt will be open by notepad defaultly
    Code:
    
    void CSECS_AMECDlg::OnBnClickedButtonViewLog()
    {
    	// TODO: Add your control notification handler code here
    	CString logFilePath(Util::GetModulePath().c_str());
    	logFilePath += "\\\secslog.txt";
    	ShellExecute(NULL,NULL,logFilePath,NULL,NULL,SW_SHOWDEFAULT); 
    }
    i want to call OnBnClickButtonViewLog() and jump our a configuration windown, user could set the default view log tool to editplus.

    My OS is WINXP and my C++ IDE is Visual Studio 2005 Pro



    thanks!
    Last edited by userpingz; 05-17-2009 at 10:56 PM.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, you can't use ShellExecute to do that, you need to use CreateProcess Function (Windows) or something like that. And of course, you pass along the configured editor program. You may also want to have a fall-back option: if there is no editor configured, or if the CreaeteProcess fails, you will want to call ShellExecute to use the system configured text editor.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Why is the tool passing off the editing to another editing program in the first place? Should not an edit tool....support editing?

  6. #6
    Registered User
    Join Date
    Mar 2009
    Posts
    48
    // Q. why i need the new feature (e.g. Configure view log tool from notepad to editplus)
    // A. - Mainly for performance reason. Now the tool will creat daily YYYYMMDD.TXT log file realtime, and sometime the log file is bigger than 10M. when we click log view button (default notepad launched now), it will take a long time to open it. if i open the log file folder from the windows explorer with Editplus, it is very fast:-)
    Another reason, the tool will be realeased to another lab group user. There is no Editplus in their OS. Based on this condition, i plan to develop the new function still support open the Log file via Notepad defaultly.

    // i just tried to take use ShellExecute()... and i will try to learn CreateProcess Function (Windows) too. :-)
    -----------------------------------------------------
    Menu Click To Configuration.
    I just try to save the Editplus Folder Path to a config.ini file.
    Code:
    void CSECS_AMECDlg::OnMenuConfigviewlog()
    {
    	// TODO: add user configuration for view log edit tool selection
    	// m_ViewLogDlg.MoveWindow(100, 100, 300, 300);
    
    		CFileDialog m_ViewLogDlg(
    		TRUE,
    		"exe",
    		NULL,
    		OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_NOREADONLYRETURN,
    		"Exe files (*.exe)|*.exe||");
    
    		// Set initial path
    		m_ViewLogDlg.m_ofn.lpstrInitialDir = "c:\\Program Files";
    
    		// Set title of dialog
    		m_ViewLogDlg.m_ofn.lpstrTitle = "Like to your favorite view tool . e.g. editplus...";
    
    		// Show file open dialog
    		if (m_ViewLogDlg.DoModal() == IDOK)
    		
    		// Get selected path name
    		CString editToolInstallPath = m_ViewLogDlg.GetPathName();
    		
    		// Save the Path to Config.ini
    		ofstream SavePath("config.ini "); 
    		SavePath << m_ViewLogDlg.GetPathName();
    		SavePath.close();
    		
    		
    
    }



    -------------------------------------------------------------------------
    View Log Button Function.
    Code:
    void CSECS_AMECDlg::OnBnClickedButtonViewLog()
    {
    	// TODO: Add your control notification handler code here
    	CString logFilePath(Util::GetModulePath().c_str());
    	logFilePath += "\\\secslog.txt";
    	
    	CString EditToolConfigPath;
    
    	// debug need
    
    	if (EditToolConfigPath == "")
    	// View Log with Notepad defaultly
    	{
    		ShellExecute(NULL,NULL,logFilePath,NULL,NULL,SW_SHOWDEFAULT);
    	}
    	else
    	// View Log With Editplsu, UltraEdit, etc...
    	// Should be more flexiable, no hardcode - the 3rd part edit tool path should be replaced!
    	{
    		// editToolInstallPath = "c:\\Program Files\\EditPlus 3\\editplus.exe";
    		ShellExecute(NULL,NULL,EditToolConfigPath,logFilePath,NULL,SW_SHOWDEFAULT); 
    	}
    }
    ------------------------------------------------------------------
    i tested the top related function, it worked well.
    But i still have two problems.
    ONE:
    I can't save the Edit Tool Name Path to local .INI config file, i don't know why?

    TWO:
    I creaed a small script to try the C++ IO function.
    Why it is Octal(e.g. 0015BD68 ) format record from my config.ini ?
    Code:
    #include "stdafx.h"
    #include "atlstr.h"
    
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    int main () {
      
    	CString NamePath;
    	NamePath = "C:\\Program\\Editplus 3\\editplus.exe";
    	ofstream f("config.ini"); 
    	f << NamePath;
    	f.close();
    	return 0;
    }
    Last edited by userpingz; 05-19-2009 at 06:41 PM.

  7. #7
    Registered User
    Join Date
    Mar 2009
    Posts
    48
    Write the editplus path to the config.ini code test pass.
    Code:
    // IOFileTestProj.cpp : main project file.
    #include "stdafx.h"
    
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    void main()
    {
    	char PathDirectory[] = "C:\\Program\\Edit Plus3\\Editplus.exe";
    
    	ofstream SaveFile("config.ini");
    	SaveFile << PathDirectory;
    	SaveFile.close();
    	// return 0;
    
    }

    --------------------------------------------------------
    Read the editplus path from the config.ini code sample test pass too.
    [code]
    void main() //the program starts here
    {

    ifstream OpenFile("config.ini");
    char ch;
    int i;
    while(OpenFile >> ch)
    {
    cout << ch;
    }
    cout << endl;
    OpenFile.close();

    cin >> i;
    }


    --------------------------------------------
    i will try to integrate the sample code to my tool :-)
    project on going ^_^ ....
    Last edited by userpingz; 05-19-2009 at 04:00 AM. Reason: while(OpenFile >> ch) {...}

  8. #8
    Registered User
    Join Date
    Mar 2009
    Posts
    48
    fyi
    My ugly code, but functional now.
    Cheer!


    OnMenuConfigviewlog // for Config the View Log too. e.g. editplus.
    Code:
    void CSECS_MYDlg::OnMenuConfigviewlog()
    {
    	// TODO: Add your command handler code here
    	CFileDialog fileDlg(
    		TRUE,
    		"exe",											  // no default extension
    		NULL,											  // ..or file name
    		OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT,
    		_T("Exe Files (*.exe)|*.exe"	)
    	);
    
    	CString fileName;
    	if(fileDlg.DoModal() == IDOK)
    	{
    		fileName = fileDlg.GetPathName();
    		// m_ViewLogConfigFolderPath = fileName;
    	}
    	
    	/* 
    	'CString' to 'std::string':
    		CString cs("Hello");
    		std::string s((LPCTSTR)cs);
    
    	'std::string' to 'CString':
    		std::string s("Hello");
    		CString cs(s.c_str());
    	*/
    
    	string strInfo((LPCTSTR)fileName);
    
    	CString configFilePath(Util::GetModulePath().c_str());
    	configFilePath += "\\\config.ini";
    	
    	ofstream SaveFile(configFilePath);
    	SaveFile << strInfo;
    	SaveFile.close();
    
    
    }

    OnBnClickedButtonViewLog Function for View Log Action.
    Code:
    void CSECS_MYDlg::OnBnClickedButtonViewLog()
    
    {
    	// TODO: Add your control notification handler code here
    	CString logFilePath(Util::GetModulePath().c_str());
    	logFilePath += "\\\secslog.txt";
    
    	CString fileName(Util::GetModulePath().c_str());
    	fileName += "\\\config.ini";
    	
    	string strInfo;
    
    	ifstream OpenFile(fileName);
    	if (OpenFile.is_open())
    	{
    		while (getline (OpenFile, strInfo))
    		{
    			getline (OpenFile, strInfo);
    		}
    		OpenFile.close();
    	}else 
    		cout << "Unable to open file"; 
    
    	CString PathName(strInfo.c_str());
    
    	if (PathName == "")
    	// View Log with Notepad defaultly
    	{
    		ShellExecute(NULL,NULL,logFilePath,NULL,NULL,SW_SHOWDEFAULT);
    	}
    	else
    	// View Log With Editplsu, etc...
    	{
    		ShellExecute(NULL,NULL,PathName,logFilePath,NULL,SW_SHOWDEFAULT); 
    	}
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM