Page 1 of 1

I don't know how to link "wxfiledialog" and "wxlistctrl"

Posted: Tue Jul 14, 2015 10:25 am
by manggae
i don't know how to link "wxfiledialog" and "wxlistctrl"....
select the wav file(use wxfiledialog) and add to wxlistctrl..., but i'm beginner about wxwidgets....
please help me...please!!! :oops:

Code: Select all

void testdrawFrame::OnButton1Click(wxCommandEvent& event)
{
   wxFileDialog* FileDialog1 =new wxFileDialog (this);
   wxListCtrl ListCtrl1;
   if(FileDialog1->ShowModal() == wxID_OK)
   {
     wxString strfile = FileDialog1->GetPath();
     wxString strname = FileDialog1->GetTitle();
     wxListItem itemCol;
     itemCol.m_text=strname;
     ListCtrl1.InsertItem(itemCol);
   }
}

Re: I don't know how to link "wxfiledialog" and "wxlistctrl"

Posted: Tue Jul 14, 2015 10:51 am
by doublemax
The problem is that you're creating ListCtrl1 as a local variable. When the method is done, it will be destroyed again.

You have to create the wxListCtrl in the constructor of the frame and store the pointer in a member variable. Then you can fill the control in the button event handler.

Re: I don't know how to link "wxfiledialog" and "wxlistctrl"

Posted: Tue Jul 14, 2015 3:40 pm
by manggae
please show me the example............i don't know.. :oops:

Re: I don't know how to link "wxfiledialog" and "wxlistctrl"

Posted: Tue Jul 14, 2015 7:03 pm
by doublemax
This is based on the "minimal" sample and it's as simple as it gets. Your original code didn't show what kind of list control you wanted, so i used the wxLC_LIST style.

This is elementary stuff, i recommend to study a wxWidgets tutorial and some of the samples so you get an idea of the basic structure of a wxWidgets application.
http://zetcode.com/gui/wxwidgets/

Re: I don't know how to link "wxfiledialog" and "wxlistctrl"

Posted: Wed Jul 15, 2015 3:33 am
by manggae

Code: Select all

#include "testdrawMain.h"
#include <wx/msgdlg.h>
#include <wx/filedlg.h>
#include <wx/wx.h>
#include "openfile.h"
#include <wx/msgdlg.h>
#include <wx/msw/dialog.h>
#include <stdio.h>
#include "wx/listctrl.h"

//(*InternalHeaders(testdrawFrame)
#include <wx/intl.h>
#include <wx/string.h>
//*)

//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )
    {
#if defined(__WXMSW__)
        wxbuild << _T("-Windows");
#elif defined(__UNIX__)
        wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
        wxbuild << _T("-Unicode build");
#else
        wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
    }

    return wxbuild;
}

//(*IdInit(testdrawFrame)
const long testdrawFrame::ID_BUTTON1 = wxNewId();
const long testdrawFrame::ID_BUTTON2 = wxNewId();
const long testdrawFrame::ID_BUTTON3 = wxNewId();
const long testdrawFrame::ID_PANEL1 = wxNewId();
const long testdrawFrame::ID_LISTCTRL1 = wxNewId();
const long testdrawFrame::idMenuQuit = wxNewId();
const long testdrawFrame::idMenuAbout = wxNewId();
const long testdrawFrame::ID_STATUSBAR1 = wxNewId();
//*)

BEGIN_EVENT_TABLE(testdrawFrame,wxFrame)
    //(*EventTable(testdrawFrame)
    //*)

END_EVENT_TABLE()

testdrawFrame::testdrawFrame(wxWindow* parent,wxWindowID id)
{
    //(*Initialize(testdrawFrame)
    wxMenuItem* MenuItem2;
    wxMenuItem* MenuItem1;
    wxMenu* Menu1;
    wxMenuBar* MenuBar1;
    wxMenu* Menu2;

    Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
    SetClientSize(wxSize(772,385));
    openfile = new wxButton(this, ID_BUTTON1, _("openfile"), wxPoint(16,16), wxSize(64,23), 0, wxDefaultValidator, _T("ID_BUTTON1"));
    Button2 = new wxButton(this, ID_BUTTON2, _("Label"), wxPoint(208,16), wxSize(64,24), 0, wxDefaultValidator, _T("ID_BUTTON2"));
    Button3 = new wxButton(this, ID_BUTTON3, _("Label"), wxPoint(112,16), wxSize(64,24), 0, wxDefaultValidator, _T("ID_BUTTON3"));
    Panel1 = new wxPanel(this, ID_PANEL1, wxPoint(144,56), wxSize(592,256), wxTAB_TRAVERSAL, _T("ID_PANEL1"));
    ListCtrl1 = new wxListCtrl(this, ID_LISTCTRL1, wxPoint(8,56), wxSize(120,256), wxLC_LIST, wxDefaultValidator, _T("ID_LISTCTRL1"));
    MenuBar1 = new wxMenuBar();
    Menu1 = new wxMenu();
    MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
    Menu1->Append(MenuItem1);
    MenuBar1->Append(Menu1, _("&File"));
    Menu2 = new wxMenu();
    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
    Menu2->Append(MenuItem2);
    MenuBar1->Append(Menu2, _("Help"));
    SetMenuBar(MenuBar1);
    StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
    int __wxStatusBarWidths_1[1] = { -1 };
    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
    StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
    StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
    SetStatusBar(StatusBar1);
    FileDialog1 = new wxFileDialog(this, _("Select file"), wxEmptyString, wxEmptyString, _("WAV | *.wav"), wxFD_OPEN, wxDefaultPosition, wxDefaultSize, _T("wxFileDialog"));

    Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&testdrawFrame::OnButton1Click);
    Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&testdrawFrame::OnQuit);
    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&testdrawFrame::OnAbout);
    //*)
}

testdrawFrame::~testdrawFrame()
{
    //(*Destroy(testdrawFrame)
    //*)
}

void testdrawFrame::OnQuit(wxCommandEvent& event)
{
    Close();
}

void testdrawFrame::OnAbout(wxCommandEvent& event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}


void testdrawFrame::OnButton1Click(wxCommandEvent& event)
{

   wxFileDialog* FileDialog1 =new wxFileDialog (this);

   if(FileDialog1->ShowModal() == wxID_OK)
   {
     wxString strname = FileDialog1->GetTitle();
     wxString fileName = FileDialog1->GetPath();
     wxListItem item;
     item.m_itemId = 0;
     item.m_col = 0;
     item.m_text = fileName;
     ListCtrl1->InsertItem(item);
   }


}
it is my source , just Add a list of the base frame,
i want click the "openfile"button and select wav file(use filedialog)
so, the wave file name adding the listctrl

As you advice, Learning to watching the tutorial. but It takes longer to learn how to use.
sorry.....i'm really beginner.....Earnestly ask for your help.

Re: I don't know how to link "wxfiledialog" and "wxlistctrl"

Posted: Wed Jul 15, 2015 7:30 am
by doublemax
Please take a closer look at the sample i posted, it does exactly what you want.

Re: I don't know how to link "wxfiledialog" and "wxlistctrl"

Posted: Tue Jul 21, 2015 11:15 am
by manggae
thank you!!!!!!!!!