X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/69c33c6c5812cb51a76e880b888071dc25115bd2..0dfef5a8124ac0f1bb2aed6ef5ddfa833e8e2c6e:/samples/exec/exec.cpp diff --git a/samples/exec/exec.cpp b/samples/exec/exec.cpp index b508cc9efd..add313c026 100644 --- a/samples/exec/exec.cpp +++ b/samples/exec/exec.cpp @@ -35,10 +35,17 @@ #include "wx/app.h" #include "wx/frame.h" #include "wx/utils.h" + #include "wx/menu.h" + #include "wx/msgdlg.h" + #include "wx/textdlg.h" #endif #include "wx/process.h" +#ifdef __WINDOWS__ + #include "wx/dde.h" +#endif // __WINDOWS__ + // ---------------------------------------------------------------------------- // private classes // ---------------------------------------------------------------------------- @@ -69,6 +76,7 @@ public: void OnSyncExec(wxCommandEvent& event); void OnAsyncExec(wxCommandEvent& event); void OnShell(wxCommandEvent& event); + void OnDDEExec(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); @@ -111,9 +119,12 @@ enum Exec_SyncExec = 200, Exec_AsyncExec, Exec_Shell, + Exec_DDEExec, Exec_About = 300 }; +static const wxChar *DIALOG_TITLE = _T("Exec sample"); + // ---------------------------------------------------------------------------- // event tables and other macros for wxWindows // ---------------------------------------------------------------------------- @@ -127,6 +138,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(Exec_SyncExec, MyFrame::OnSyncExec) EVT_MENU(Exec_AsyncExec, MyFrame::OnAsyncExec) EVT_MENU(Exec_Shell, MyFrame::OnShell) + EVT_MENU(Exec_DDEExec, MyFrame::OnDDEExec) EVT_MENU(Exec_About, MyFrame::OnAbout) END_EVENT_TABLE() @@ -178,7 +190,9 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) #endif // set the frame icon +#ifndef __WXGTK__ SetIcon(wxICON(mondrian)); +#endif // create a menu bar wxMenu *menuFile = new wxMenu(_T(""), wxMENU_TEAROFF); @@ -192,6 +206,11 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) execMenu->Append(Exec_Shell, _T("Execute &shell command...\tCtrl-S"), _T("Launch a shell and execute a command in it")); +#ifdef __WINDOWS__ + execMenu->AppendSeparator(); + execMenu->Append(Exec_DDEExec, _T("Execute command via &DDE...\tCtrl-D")); +#endif + wxMenu *helpMenu = new wxMenu(_T(""), wxMENU_TEAROFF); helpMenu->Append(Exec_About, _T("&About...\tF1"), _T("Show about dialog")); @@ -206,7 +225,7 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) #if wxUSE_STATUSBAR // create a status bar just for fun (by default with 1 pane only) - CreateStatusBar(2); + CreateStatusBar(); SetStatusText(_T("Welcome to wxWindows!")); #endif // wxUSE_STATUSBAR } @@ -229,7 +248,7 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnSyncExec(wxCommandEvent& WXUNUSED(event)) { wxString cmd = wxGetTextFromUser(_T("Enter the command: "), - _T("Exec sample"), + DIALOG_TITLE, m_cmdLast); if ( !cmd ) @@ -244,7 +263,7 @@ void MyFrame::OnSyncExec(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnAsyncExec(wxCommandEvent& WXUNUSED(event)) { wxString cmd = wxGetTextFromUser(_T("Enter the command: "), - _T("Exec sample"), + DIALOG_TITLE, m_cmdLast); if ( !cmd ) @@ -266,7 +285,7 @@ void MyFrame::OnAsyncExec(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnShell(wxCommandEvent& WXUNUSED(event)) { wxString cmd = wxGetTextFromUser(_T("Enter the command: "), - _T("Exec sample"), + DIALOG_TITLE, m_cmdLast); if ( !cmd ) @@ -278,6 +297,48 @@ void MyFrame::OnShell(wxCommandEvent& WXUNUSED(event)) m_cmdLast = cmd; } +void MyFrame::OnDDEExec(wxCommandEvent& WXUNUSED(event)) +{ +#ifdef __WINDOWS__ + wxString server = wxGetTextFromUser(_T("Server to connect to:"), + DIALOG_TITLE, _T("IExplore")); + if ( !server ) + return; + + wxString topic = wxGetTextFromUser(_T("DDE topic:"), + DIALOG_TITLE, _T("WWW_OpenURL")); + if ( !topic ) + return; + + wxString cmd = wxGetTextFromUser(_T("DDE command:"), + DIALOG_TITLE, + _T("\"file:F:\\wxWindows\\samples\\" + "image\\horse.gif\",,-1,,,,,")); + if ( !cmd ) + return; + + wxDDEClient client; + wxConnectionBase *conn = client.MakeConnection("", server, topic); + if ( !conn ) + { + wxLogError(_T("Failed to connect to the DDE server '%s'."), + server.c_str()); + } + else + { + if ( !conn->Execute(cmd) ) + { + wxLogError(_T("Failed to execute command '%s' via DDE."), + cmd.c_str()); + } + else + { + wxLogStatus(_T("Successfully executed DDE command")); + } + } +#endif // __WINDOWS__ +} + // ---------------------------------------------------------------------------- // MyProcess // ----------------------------------------------------------------------------