1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Can a Windows Forms 'button' link to ShellExecute?

Discussion in 'MFC' started by Panarchy, Jun 8, 2009.

  1. Panarchy

    Panarchy New Member

    Joined:
    Nov 29, 2007
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    Greetings

    I've created a Windows Forms [Visual C++] project within Microsoft Visual Studio 2008.

    I've been able to create a button.

    Now how do I make that button correspond to a ShellExecute command, eg;

    Code:
    ShellExecute(NULL, TEXT("open"), TEXT("diskmgmt.msc"), NULL, NULL, SW_HIDE);
    Thanks in advance for any suggestions,

    Panarchy

    PS: In case you need it, here's the code: http://www.mediafire.com/?lj2ma33kwmw
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    Moved to MFC forum and what do you meant by correspond ?
     
  3. Panarchy

    Panarchy New Member

    Joined:
    Nov 29, 2007
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    So you click the button and it does the ShellExecute() call...
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    Add the Button Click Event Handler ( Either using the IDE or manually using Message Map Macros ) and then add the needed code for the handler into it.
     
  5. Panarchy

    Panarchy New Member

    Joined:
    Nov 29, 2007
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    Thanks, however I can't find that option within the IDE.

    Can you give me an example of the code for it?

    Thanks in advance,

    Panarchy
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    No. they would link to functions which has a predefined signatures and not to any other function
     
  7. Panarchy

    Panarchy New Member

    Joined:
    Nov 29, 2007
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    Would you please be so kind as to give me an example of a GUI program, written in C++, with a button, which can launch an 'outside' program?

    e.g.: Disk Management

    Thanks in advance,

    Panarchy
     
  8. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    I guess you need to get the basics of MFC handling as its very simple a button click to get the button handler
     
  9. Panarchy

    Panarchy New Member

    Joined:
    Nov 29, 2007
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    I worked it out. Here is the bottom of my code;
    Code:
    }
    #pragma endregion
    	private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {System::Diagnostics::Process::Start("C:\\Windows\\System32\\diskmgmt.msc");
    			 }
    };
    }
    Any ideas on how I can put if & else types onto the above type of command?

    I'd really appreciate it if you could help me work that out.

    Thanks in advance,

    Panarchy

    PS: Some links;
    http://msdn.microsoft.com/en-us/library/system.windows.forms.control.click.aspx
    http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx
     
  10. Panarchy

    Panarchy New Member

    Joined:
    Nov 29, 2007
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    I worked it out. Here is the bottom of my code;
    Code:
    }
    #pragma endregion
    	private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {System::Diagnostics::Process::Start("C:\\Windows\\System32\\diskmgmt.msc");
    			 }
    };
    }
    Any ideas on how I can put if & else types onto the above type of command?

    I'd really appreciate it if you could help me work that out.

    Thanks in advance,

    Panarchy

    PS: Some links;
    http://msdn.microsoft.com/en-us/library/system.windows.forms.control.click.aspx
    http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx
     
  11. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    Thats the function definition and you need to add the event handler in the function body
     
  12. Panarchy

    Panarchy New Member

    Joined:
    Nov 29, 2007
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0
    Okay... how?

    Would appreciate some extra help here.

    Thanks in advance,

    Panarchy
     
  13. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
  14. Panarchy

    Panarchy New Member

    Joined:
    Nov 29, 2007
    Messages:
    86
    Likes Received:
    0
    Trophy Points:
    0

Share This Page