Thread: How to run a .exe file in MFC GUI?

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    163

    How to run a .exe file in MFC GUI?

    Can anyone pls help me? I'm now developing a GUI using MFC, and when I click a button, it will call this function OnAdd(). In OnAdd, it is suppose to run my application "clusters.exe" but it doesn't. Does anyone knows why?

    Code:
    void CDialog1Dlg::OnAdd() 
    {
    	// TODO: Add your control notification handler code here
    	CString strTitle ;
    	int nIndex, minsup;
    	double delta;
    	char str_cmd[100];
    
    	UpdateData(); 		// Transfer data from controls to variables
    
    	//get currently selected text
    	nIndex = GetDlgItemText(IDC_TITLE, strTitle);  //assigning selected 
    	m_strFullName = strTitle + " " + m_strFirstName + " " + m_strLastName;
    	minsup = atoi(m_strFirstName);
    	delta = atof(m_strLastName);
    
    	sprintf(str_cmd, "clusters.exe input.txt %d %d %f 2 1 result.txt", minsup, minsup, delta);
    	printf("%s\n", str_cmd);
    	system(str_cmd);
    	UpdateData(FALSE); 	// Transfer data from variables to controls
    }

  2. #2
    Registered User
    Join Date
    Dec 2004
    Posts
    163
    i'm an idiot. i put clusters.exe in the wrong directory!

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    system()? Danger will Robinson, danger. There are better ways to do this through Win32 API.

  4. #4
    Registered User
    Join Date
    Dec 2004
    Posts
    163
    why danger? I'm a beginner, Bubba, care to elaborate more about API? I asked my colleague, he told me another way is to convert the application cluster into a ddl, so that the MFC, or Java GUI can call it

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Maybe Bubba was referring to ShellExecute.

    I think your colleague meant a DLL.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  6. #6
    Registered User
    Join Date
    Dec 2004
    Posts
    163
    any difference between apl (shell execute) and dll? and good websites that teach them? thanks!

  7. #7
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    A DLL is like different way of compiling code; you'd have to have access to the source code to be able to create a DLL before you can use one. ShellExecute can execute any program or document (if you use ShellExecute to open whatever.txt, it launches notepad or whatever program you use to open .txt files, much like the DOS command start).

    [edit] Here's a FAQ on the subject: http://faq.cprogramming.com/cgi-bin/...&id=1043284392

    It has some information about ShellExecute().
    [/edit]
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  8. #8
    Registered User
    Join Date
    Dec 2004
    Posts
    163
    thanks! i'm actually doing shellexecute =)

  9. #9
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I never knew MFC is that bad...

  10. #10
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Quote Originally Posted by maxorator
    I never knew MFC is that bad...
    I don't think anyone here said MFC was bad. It's actually quite decent; it can handle about 80% of everything I've ever needed to do in GUI, and it does it with minimal development time.

    The "bad" was in reference to system() to execute a second program, when there are other ways to execute programs (including ones that will let you know if the program succeeded or failed, and if it is still running or not).
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  11. #11
    Registered User
    Join Date
    Dec 2004
    Posts
    163
    i got to rush a prototype in 2 days time, so using mfc and shellexecute. any suggestions for a large gui application? I heard using java or visual basic is better than mfc

  12. #12
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    If you know those languages, I suppose they're fine. I've done very large applications with MFC and in general it's been exceedingly helpful and easy to use. It does sacrifice a small amount of power and a slightly less small amount of speed, however, but in general, on non-game applications it's irrelevant.

  13. #13
    Registered User
    Join Date
    Dec 2004
    Posts
    163
    thanks cat! but does mfc supports stock chart drawing? i heard java is great for interactive stock chart.
    and any good books to pick up mfc? right now i'm learning it from codeproject.com, which is great!

  14. #14
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    Don't believe there's a built in class for stock chart drawing, but it is not hard at all to derive your own class and do your own OnPaint() method.

    Not sure about MFC books, I learned by experience.
    Last edited by Cat; 08-30-2006 at 09:20 PM.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  15. #15
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    MFC is not hard at all. If you stay away from the doc-view architecture you should be able to complete your project in time.

    I only use doc/view but it took a long time to figure out how to use it, and more importantly, how not to use it.

    Essentially:

    App - application specific class
    Frame - handles the main frame window
    Document - handles all the data
    View - renders the display based on the data

    This is extremely powerful but extremely hard to follow unless you are used to the paradigm.

    I've got a very large tile editor coded in MFC and I love it. W/o MFC the whole thing would have taken 10 to 20 times as long to do and still would not have been as good. Using MFC does confine you to code in 'what were the designers thinking' mode instead of what you are thinking, but you get used to it. It is slower than some apps, but on modern systems it is really not that bad. Besides most graphically intensive MFC apps use DirectX or OGL for drawing instead of GUI. The 'slow' is really not MFC's fault (except for all the virtual function calls) but more a fault of Windows GDI.

    Most people who hate MFC here, at least, are those who have little to no experience with it. Check some professional boards and I think you will find it's about 50/50 right down the middle. Some swear by it, and some just swear at it.

    I've purchased 4 books on MFC and not one of them has been all that useful. You can learn MFC quite well by just dabbling in it and using it.
    Last edited by VirtualAce; 08-31-2006 at 12:44 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM