Partage
  • Partager sur Facebook
  • Partager sur Twitter

Probleme

wxWidgets

Sujet résolu
    16 décembre 2007 à 9:53:16

    BOn depuis peux je me suis lance dans wxWidgets et je suis en train de concevoir un programme qui lira des animations...Mais avant que le programme s'ouvre, une autre fenetrte Shaped() s'ouvre et avec un double click sur elle la fenetre principale s'ouvre...Je sus sous Dev-cpp et g quatre erreurs de compil:
    1)[Linker Error] undefined reference to 'MyFrame::GetEventTable const'
    2)[Linker Error]undefined reference to 'MyFrame::GetEventHashTable() const'
    3)Id returned 1 exit status
    4)[Build Error][AniBox.exe]Error 1
    Et voici le code(3 fichiers):
    main.cpp:
    1. #include "wx/wxprec.h"
    2. #ifdef __BORLANDC__
    3.     #pragma hdrstop
    4. #endif
    5. #ifndef WX_PRECOMP
    6.     #include "wx/app.h"
    7.     #include "wx/log.h"
    8.     #include "wx/frame.h"
    9.     #include "wx/panel.h"
    10.     #include "wx/stattext.h"
    11.     #include "wx/menu.h"
    12.     #include "wx/layout.h"
    13.     #include "wx/msgdlg.h"
    14.     #include "wx/image.h"
    15. #endif
    16. #ifndef WX_PRECOMP
    17.     #include "wx/wx.h"
    18. #endif
    19. #ifndef __WXMSW__
    20.     #include "sample.xpm"
    21. #endif
    22. #include "wx/aboutdlg.h"
    23. #include "wx/artprov.h"
    24. #include "wx/colordlg.h"
    25. #include "anitest.h"
    26. #if !wxUSE_ANIMATIONCTRL
    27.     #error Cannot compile this sample if wxAnimationCtrl is not enabled
    28. #endif
    29. #include "wx/dcclient.h"
    30. #include "wx/image.h"
    31. enum
    32. {
    33.     ID_PLAY = 1,
    34.     ID_SET_NULL_ANIMATION,
    35.     ID_SET_INACTIVE_BITMAP,
    36.     ID_SET_NO_AUTO_RESIZE,
    37.     ID_SET_BGCOLOR
    38. };
    39. class ShapedFrame : public wxFrame
    40. {
    41. public:
    42.     ShapedFrame();
    43.     void SetWindowShape();
    44.     void OnDoubleClick(wxMouseEvent& evt);
    45.     void OnLeftDown(wxMouseEvent& evt);
    46.     void OnLeftUp(wxMouseEvent& evt);
    47.     void OnMouseMove(wxMouseEvent& evt);
    48.     void OnExit(wxMouseEvent& evt);
    49.     void OnPaint(wxPaintEvent& evt);
    50.     void OnWindowCreate(wxWindowCreateEvent& evt);
    51. private:
    52.     bool     m_hasShape;
    53.     wxBitmap m_bmp;
    54.     wxPoint  m_delta;
    55.     DECLARE_EVENT_TABLE()
    56. };
    57. BEGIN_EVENT_TABLE(ShapedFrame, wxFrame)
    58.     EVT_LEFT_DCLICK(ShapedFrame::OnDoubleClick)
    59.     EVT_LEFT_DOWN(ShapedFrame::OnLeftDown)
    60.     EVT_LEFT_UP(ShapedFrame::OnLeftUp)
    61.     EVT_MOTION(ShapedFrame::OnMouseMove)
    62.     EVT_RIGHT_UP(ShapedFrame::OnExit)
    63.     EVT_PAINT(ShapedFrame::OnPaint)
    64.     EVT_MENU(ID_PLAY, MyFrame::OnPlay)
    65.     EVT_MENU(ID_SET_NULL_ANIMATION, MyFrame::OnSetNullAnimation)
    66.     EVT_MENU(ID_SET_INACTIVE_BITMAP, MyFrame::OnSetInactiveBitmap)
    67.     EVT_MENU(ID_SET_NO_AUTO_RESIZE, MyFrame::OnSetNoAutoResize)
    68.     EVT_MENU(ID_SET_BGCOLOR, MyFrame::OnSetBgColor)
    69.     EVT_MENU(wxID_STOP, MyFrame::OnStop)
    70.     EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
    71.     EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
    72. #if wxUSE_FILEDLG
    73.     EVT_MENU(wxID_OPEN, MyFrame::OnOpen)
    74. #endif // wxUSE_FILEDLG
    75.     EVT_SIZE(MyFrame::OnSize)
    76.     EVT_UPDATE_UI(wxID_ANY, MyFrame::OnUpdateUI)
    77. #ifdef __WXGTK__
    78.     EVT_WINDOW_CREATE(ShapedFrame::OnWindowCreate)
    79. #endif
    80. END_EVENT_TABLE()
    81. IMPLEMENT_APP(MyApp)
    82. bool MyApp::OnInit()
    83. {
    84.     wxInitAllImageHandlers();
    85.     ShapedFrame *frame = new ShapedFrame();
    86.     frame->Show(true);
    87.     SetTopWindow(frame);
    88.     return true;
    89. }
    90. ShapedFrame::ShapedFrame()
    91.        : wxFrame((wxFrame *)NULL, wxID_ANY, wxEmptyString,
    92.                   wxDefaultPosition, wxSize(100, 100),
    93.                   0
    94.                   | wxFRAME_SHAPED
    95.                   | wxSIMPLE_BORDER
    96.                   | wxFRAME_NO_TASKBAR
    97.                   | wxSTAY_ON_TOP
    98.             )
    99. {
    100.     m_hasShape = false;
    101.     m_bmp = wxBitmap(_T("star.png"), wxBITMAP_TYPE_PNG);
    102.     SetSize(wxSize(m_bmp.GetWidth(), m_bmp.GetHeight()));
    103.     SetToolTip(wxT("Hello and...right-click to exit"));
    104. #ifndef __WXGTK__
    105.     SetWindowShape();
    106. #endif
    107. }
    108. void ShapedFrame::SetWindowShape()
    109. {
    110.     wxRegion region(m_bmp, *wxRED);
    111.     m_hasShape = SetShape(region);
    112. }
    113. void ShapedFrame::OnDoubleClick(wxMouseEvent& WXUNUSED(evt))
    114. {
    115.      MyFrame* frame = new MyFrame((wxFrame *)NULL, wxID_ANY, _T("AniBox"),
    116.                                  wxDefaultPosition, wxSize(500, 400),
    117.                                  wxDEFAULT_FRAME_STYLE);
    118.     // Give it an icon
    119.     frame->SetIcon(wxICON(sample));
    120.     // Make a menubar
    121.     wxMenu *file_menu = new wxMenu;
    122. #if wxUSE_FILEDLG
    123.     file_menu->Append(wxID_OPEN, _T("&Open Animation...\tCtrl+O"), _T("Loads an animation"));
    124. #endif // wxUSE_FILEDLG
    125.     file_menu->Append(wxID_EXIT);
    126.     wxMenu *play_menu = new wxMenu;
    127.     play_menu->Append(ID_PLAY, _T("Play\tCtrl+P"), _T("Play the animation"));
    128.     play_menu->Append(wxID_STOP, _T("Stop\tCtrl+P"), _T("Stop the animation"));
    129.     play_menu->AppendSeparator();
    130.     play_menu->Append(ID_SET_NULL_ANIMATION, _T("Set null animation"),
    131.                       _T("Sets the empty animation in the control"));
    132.     play_menu->AppendCheckItem(ID_SET_INACTIVE_BITMAP, _T("Set inactive bitmap"),
    133.                                _T("Sets an inactive bitmap for the control"));
    134.     play_menu->AppendCheckItem(ID_SET_NO_AUTO_RESIZE, _T("Set no autoresize"),
    135.                                _T("Tells the control not to resize automatically"));
    136.     play_menu->Append(ID_SET_BGCOLOR, _T("Set background colour..."),
    137.                       _T("Sets the background colour of the control"));
    138.     wxMenu *help_menu = new wxMenu;
    139.     help_menu->Append(wxID_ABOUT);
    140.     wxMenuBar *menu_bar = new wxMenuBar;
    141.     menu_bar->Append(file_menu, _T("&File"));
    142.     menu_bar->Append(play_menu, _T("&Animation"));
    143.     menu_bar->Append(help_menu, _T("&Help"));
    144.     // Associate the menu bar with the frame
    145.     frame->SetMenuBar(menu_bar);
    146. #if wxUSE_STATUSBAR
    147.     frame->CreateStatusBar();
    148. #endif // wxUSE_STATUSBAR
    149.     frame->Show(true);
    150.     if (m_hasShape)
    151.     {
    152.         wxRegion region;
    153.         SetShape(region);
    154.         m_hasShape = false;
    155.     }
    156.     else
    157.         SetWindowShape();
    158. }
    159. void ShapedFrame::OnLeftDown(wxMouseEvent& evt)
    160. {
    161.     CaptureMouse();
    162.     wxPoint pos = ClientToScreen(evt.GetPosition());
    163.     wxPoint origin = GetPosition();
    164.     int dx =  pos.x - origin.x;
    165.     int dy = pos.y - origin.y;
    166.     m_delta = wxPoint(dx, dy);
    167. }
    168. void ShapedFrame::OnLeftUp(wxMouseEvent& WXUNUSED(evt))
    169. {
    170.     if (HasCapture())
    171.     {
    172.         ReleaseMouse();
    173.     }
    174. }
    175. void ShapedFrame::OnMouseMove(wxMouseEvent& evt)
    176. {
    177.     wxPoint pt = evt.GetPosition();
    178.     if (evt.Dragging() && evt.LeftIsDown())
    179.     {
    180.         wxPoint pos = ClientToScreen(pt);
    181.         Move(wxPoint(pos.x - m_delta.x, pos.y - m_delta.y));
    182.     }
    183. }
    184. void ShapedFrame::OnExit(wxMouseEvent& WXUNUSED(evt))
    185. {
    186.     Close();
    187. }
    188. void ShapedFrame::OnPaint(wxPaintEvent& WXUNUSED(evt))
    189. {
    190.     wxPaintDC dc(this);
    191.     dc.DrawBitmap(m_bmp, 0, 0, true);
    192. }
    193. void ShapedFrame::OnWindowCreate(wxWindowCreateEvent& WXUNUSED(evt))
    194. {
    195.     SetWindowShape();
    196. }
    197. #include "wx/wfstream.h"
    198. // Define my frame constructor
    199. MyFrame::MyFrame(wxWindow *parent,
    200.                  const wxWindowID id,
    201.                  const wxString& title,
    202.                  const wxPoint& pos,
    203.                  const wxSize& size,
    204.                  const long style)
    205.        : wxFrame(parent, id, title, pos, size,
    206.                           style | wxNO_FULL_REPAINT_ON_RESIZE)
    207. {
    208.     // use a wxBoxSizer otherwise wxFrame will automatically
    209.     // resize the m_animationCtrl to fill its client area on
    210.     // user resizes
    211.     wxSizer *sz = new wxBoxSizer(wxVERTICAL);
    212.     sz->Add(new wxStaticText(this, wxID_ANY, wxT("AniBox Control:")),
    213.             wxSizerFlags().Centre().Border());
    214.     m_animationCtrl = new wxAnimationCtrl(this, wxID_ANY);
    215.     if (m_animationCtrl->LoadFile(wxT("throbber.gif")))
    216.         m_animationCtrl->Play();
    217.     sz->Add(m_animationCtrl, wxSizerFlags().Centre().Border());
    218.     SetSizer(sz);
    219. }
    220. MyFrame::~MyFrame()
    221. {
    222. }
    223. void MyFrame::OnPlay(wxCommandEvent& WXUNUSED(event))
    224. {
    225.     if (!m_animationCtrl->Play())
    226.         wxLogError(wxT("Invalid animation"));
    227. }
    228. void MyFrame::OnStop(wxCommandEvent& WXUNUSED(event))
    229. {
    230.     m_animationCtrl->Stop();
    231. }
    232. void MyFrame::OnSetNullAnimation(wxCommandEvent& WXUNUSED(event))
    233. {
    234.     m_animationCtrl->SetAnimation(wxNullAnimation);
    235. }
    236. void MyFrame::OnSetInactiveBitmap(wxCommandEvent& event)
    237. {
    238.     if (event.IsChecked())
    239.     {
    240.         // set a dummy bitmap as the inactive bitmap
    241.         wxBitmap bmp = wxArtProvider::GetBitmap(wxART_MISSING_IMAGE);
    242.         m_animationCtrl->SetInactiveBitmap(bmp);
    243.     }
    244.     else
    245.         m_animationCtrl->SetInactiveBitmap(wxNullBitmap);
    246. }
    247. void MyFrame::OnSetNoAutoResize(wxCommandEvent& event)
    248. {
    249.     // recreate the control with the new flag if necessary
    250.     long style = wxAC_DEFAULT_STYLE |
    251.                     (event.IsChecked() ? wxAC_NO_AUTORESIZE : 0);
    252.     if (style != m_animationCtrl->GetWindowStyle())
    253.     {
    254.         // save status of the control before destroying it
    255.         wxAnimation curr = m_animationCtrl->GetAnimation();
    256.         wxBitmap inactive = m_animationCtrl->GetInactiveBitmap();
    257.         wxColour bg = m_animationCtrl->GetBackgroundColour();
    258.         // destroy & rebuild
    259.         wxAnimationCtrl *old = m_animationCtrl;
    260.         m_animationCtrl = new wxAnimationCtrl(this, wxID_ANY, curr,
    261.                                               wxDefaultPosition, wxDefaultSize,
    262.                                               style);
    263.         GetSizer()->Replace(old, m_animationCtrl);
    264.         delete old;
    265.         // load old status in new control
    266.         m_animationCtrl->SetInactiveBitmap(inactive);
    267.         m_animationCtrl->SetBackgroundColour(bg);
    268.         GetSizer()->Layout();
    269.     }
    270. }
    271. void MyFrame::OnSetBgColor(wxCommandEvent& WXUNUSED(event))
    272. {
    273.     wxColour clr = wxGetColourFromUser(this, m_animationCtrl->GetBackgroundColour(),
    274.                                        wxT("Choose the background colour"));
    275.     if (clr.IsOk())
    276.         m_animationCtrl->SetBackgroundColour(clr);
    277. }
    278. void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
    279. {
    280.     Close();
    281. }
    282. void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
    283. {
    284.     wxAboutDialogInfo info;
    285.     info.SetName(_("AniBox"));
    286.     info.SetDescription(_("AniBox opens animations."));
    287.     info.SetCopyright(_T("(C) 2008 OpenS Co."));
    288.     info.AddDeveloper(_T("Alenas3(Alexander Naskos)"));
    289.     wxAboutBox(info);
    290. }
    291. #if wxUSE_FILEDLG
    292. void MyFrame::OnOpen(wxCommandEvent& WXUNUSED(event))
    293. {
    294.     wxFileDialog dialog(this, _T("Please choose an animation"),
    295.                         wxEmptyString, wxEmptyString, wxT("*.gif;*.ani"), wxFD_OPEN);
    296.     if (dialog.ShowModal() == wxID_OK)
    297.     {
    298.         wxString filename(dialog.GetPath());
    299.         // enable one of the two chunk of codes to test different parts of wxAnimation/wxAnimationCtrl
    300. #if 0
    301.         if (m_animationCtrl->LoadFile(filename))
    302.             m_animationCtrl->Play();
    303.         else
    304.             wxMessageBox(_T("Sorry, this animation is not a valid format for AniBox."));
    305. #else
    306.     #if 0
    307.         wxAnimation temp;
    308.         if (!temp.LoadFile(filename))
    309.         {
    310.             wxLogError(wxT("Sorry, this animation is not a valid format for AniBox."));
    311.             return;
    312.         }
    313.         m_animationCtrl->SetAnimation(temp);
    314.         m_animationCtrl->Play();
    315.     #else
    316.         wxFileInputStream stream(filename);
    317.         if (!stream.Ok())
    318.         {
    319.             wxLogError(wxT("Sorry, this animation is not a valid format for AniBox."));
    320.             return;
    321.         }
    322.         wxAnimation temp;
    323.         if (!temp.Load(stream))
    324.         {
    325.             wxLogError(wxT("Sorry, this animation is not a valid format for AniBox."));
    326.             return;
    327.         }
    328.         m_animationCtrl->SetAnimation(temp);
    329.         m_animationCtrl->Play();
    330.     #endif
    331. #endif
    332.         GetSizer()->Layout();
    333.     }
    334. }
    335. #endif // wxUSE_FILEDLG
    336. void MyFrame::OnUpdateUI(wxUpdateUIEvent& WXUNUSED(event) )
    337. {
    338.     GetMenuBar()->FindItem(wxID_STOP)->Enable(m_animationCtrl->IsPlaying());
    339.     GetMenuBar()->FindItem(ID_PLAY)->Enable(!m_animationCtrl->IsPlaying());
    340.     GetMenuBar()->FindItem(ID_SET_NO_AUTO_RESIZE)->Enable(!m_animationCtrl->IsPlaying());
    341. }

    anitest.h:
    1. #include "wx/animate.h"
    2. class MyApp : public wxApp
    3. {
    4. public:
    5.     bool OnInit();
    6. };
    7. // Define a new frame
    8. class MyFrame : public wxFrame
    9. {
    10. public:
    11.     MyFrame(wxWindow *parent, const wxWindowID id, const wxString& title,
    12.             const wxPoint& pos, const wxSize& size, const long style);
    13.     ~MyFrame();
    14.     void OnAbout(wxCommandEvent& event);
    15.     void OnQuit(wxCommandEvent& event);
    16.     void OnPlay(wxCommandEvent& event);
    17.     void OnSetNullAnimation(wxCommandEvent& event);
    18.     void OnSetInactiveBitmap(wxCommandEvent& event);
    19.     void OnSetNoAutoResize(wxCommandEvent& event);
    20.     void OnSetBgColor(wxCommandEvent& event);
    21.     void OnStop(wxCommandEvent& event);
    22.     void OnUpdateUI(wxUpdateUIEvent& event);
    23. #if wxUSE_FILEDLG
    24.     void OnOpen(wxCommandEvent& event);
    25. #endif // wxUSE_FILEDLG
    26.     wxAnimationCtrl* GetAnimationCtrl() const { return m_animationCtrl; }
    27. protected:
    28.     wxAnimationCtrl*    m_animationCtrl;
    29. private:
    30.     DECLARE_EVENT_TABLE()
    31. };

    main.rc:
    1. // RESOURCES OF THIS PROJECT
    2. // DO NOT REMOVE THIS LINE (WXWIDGETS RESOURCE)
    3. #include "wx/msw/wx.rc"
    • Partager sur Facebook
    • Partager sur Twitter
      16 décembre 2007 à 10:01:53

      J'ai l'impression que ça vient du fait que tu n'as pas fait la table d'événements pour MyFrame.
      • Partager sur Facebook
      • Partager sur Twitter
        16 décembre 2007 à 10:03:59

        on peut pas avoir une table pour deux frames? o.O
        • Partager sur Facebook
        • Partager sur Twitter
          16 décembre 2007 à 10:11:38

          Oui mais tu dois avoir deux tables d'événement distinctes:
          1. BEGIN_EVENT_TABLE(ShapedFrame, wxFrame)
          2.     ...
          3. END_EVENT_TABLE()
          4. BEGIN_EVENT_TABLE(MyFrame, wxFrame)
          5.     ...
          6. END_EVENT_TABLE()


          Pour éviter ce genre de problème et toutes ces macros un peu lourdes, je te conseille d'utiliser Connect() qui est plus pratique ;)
          • Partager sur Facebook
          • Partager sur Twitter
            16 décembre 2007 à 10:31:56

            :D merci :)
            [EDIT]:Merci ca a marche :D bientot le programme sera disponible sur mon site :) (les sources aussi)
            • Partager sur Facebook
            • Partager sur Twitter

            Probleme

            × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
            × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
            • Editeur
            • Markdown