Advertisement
AntonioVillanueva

Bind wxMouseEvent EVT_LEFT_DCLICK a un wxFrame

Jul 10th, 2018
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.71 KB | None | 0 0
  1. //Bind  wxMouseEvent  EVT_LEFT_DCLICK a un wxFrame Antonio Villanueva segura
  2. //g++ -Wall -static-libstdc++ -std=c++11 -Wunused-but-set-variable `wx-config --cxxflags` -o hola *.cpp `wx-config --libs`
  3. //Declara la clase aplicacion
  4.  
  5. //#include "imagen.xpm" //Imagen en formato xpm
  6. #include <iostream>
  7. #include "wx/wx.h"
  8. #include <wx/popupwin.h>
  9. #include <wx/menu.h>
  10. #include <wx/event.h>
  11. //using namespace std;
  12.  
  13. //Declaraciones
  14.  //Cada aplicacion wxWidget define una clase derivada de wxApp
  15. class MiApp:public wxApp
  16. {
  17.     public:
  18.     //Llamado al inicio startup, es como el main en c
  19.     virtual bool OnInit();//main wxWidgets , mas abajo se implementa
  20. };
  21.  
  22. //Declaracion de la clase frame principal
  23.  
  24. //----------------------------------------------------------------------
  25.  
  26. class MiFrame:public wxFrame
  27. {
  28.     public:
  29.     //Constructor de la clase
  30.     MiFrame();
  31.    
  32.     // Dos "event handlers" , gestion de eventos
  33.     void OnQuit(wxCommandEvent& event);
  34.     void OnAbout(wxCommandEvent& event);  
  35.     void OnButtonOk(wxCommandEvent& event);//Click boton OK
  36.     void EventosRaton (wxMouseEvent& event);//Eventos de raton Doble Click
  37.    
  38.     private:
  39.     wxMenu* m_menu;//Crea menu ..
  40.     /*Macro para informar a wxWidgets de la gestion de eventos
  41.     *Declara la tabla de eventos en esta clase ,mas abajo
  42.     * la implemento entre BEGIN_ y END_EVENT_TABLE
  43.     */
  44.     DECLARE_EVENT_TABLE()
  45. };
  46.  
  47. //----------------------------------------------------------------------
  48.  
  49. /*Implementacion , MiApp
  50. *Cuando se crea el objeto MiApp se asigna a la variable global wxTheApp
  51. * pero mejor que hacer un CAST emplear el MACRO  DECLARE_APP despues de
  52. * la declaracion de la clase , wxGetApp retorna una ref. al objeto MiApp
  53. */
  54. DECLARE_APP(MiApp)
  55.  
  56. //Macro que Proporciona a wxWidgets los medios de crear el objeto MiApp
  57. IMPLEMENT_APP(MiApp)
  58.  
  59. //----------------------------------------------------------------------
  60.  
  61. //Implementacion OnInit,Inicializa la aplicacion
  62.  
  63. bool MiApp::OnInit()
  64. {
  65.     //Crea la ventana principal , una instancia de nuestra clase MiFrame
  66.     //El titulo lo pasamos al constructor envuelto en el macro wxT
  67.     //macro de conversion de strings y char al tipo apropiado
  68.     MiFrame *frame=new MiFrame();
  69.    
  70.     //Mostrar la ventana
  71.     frame->Show(true);
  72.    
  73.     //Arranca el bucle de eventos
  74.     return true ;//Si false limpia sus estructuras y sale
  75. }
  76.  
  77. //----------------------------------------------------------------------
  78.  
  79. //Tabla de eventos para MiFrame DECLARE_EVENT_TABLE() en MiFrame
  80. //Deteccion de los clicks de raton con wxID_ABOUT y wxID_EXIT
  81. //Que se dirigen a MiFrame::OnAbout y OnQuit
  82. BEGIN_EVENT_TABLE ( MiFrame, wxFrame)
  83.     //EVT_MENU(wxID_ABOUT,    MiFrame::OnAbout)
  84.     //EVT_MENU(wxID_EXIT,     MiFrame::OnQuit)
  85.     EVT_BUTTON(wxID_OK,     MiFrame::OnButtonOk)
  86.     //EVT_LEFT_DCLICK(MiFrame::EventosRaton)
  87. END_EVENT_TABLE()
  88.  
  89. //Declaracion de OnAbout conectado al click del raton desde la EVENT_TABLE
  90. void MiFrame::OnAbout(wxCommandEvent& event)
  91. {
  92.     wxString mensaje;
  93.     //Contenido dentro de la ventana abierta
  94.     mensaje.Printf(wxT("La version wxWidgets es %s"),wxVERSION_STRING);
  95.     //Nombre de la barra de titulo Antonio Villanueva
  96.     wxMessageBox (mensaje,wxT("Antonio Villanueva"),wxOK | wxICON_INFORMATION,this);
  97.    
  98. }
  99. //Declaracion de OnQuit conectado al click del raton desde la EVENT_TABLE
  100. void MiFrame::OnQuit(wxCommandEvent& event)
  101. {
  102.     //Destruccion del Frame , de hecho va generar un wxEVT_CLOSE_WINDOW
  103.     //wxWidgets gestiona por defecto este evento
  104.     Close();
  105. }
  106.  
  107.  
  108. void MiFrame::OnButtonOk(wxCommandEvent& event)//Manipula boton OK
  109. {
  110.     //Abre ventana informando ....
  111.     wxMessageBox( wxT("Has hecho click en el boton OK !") );
  112. }
  113.  
  114. //Constructor de MiFrame implementa un icono una barra status y menu
  115. //wxID_ANY le dice a Widgets de generar un identificador por su cuenta
  116. MiFrame::MiFrame():wxFrame(NULL,wxID_ANY,"Mi Ventana")
  117. {
  118.  
  119.     //Test wxBoxSizer wxPanel wxButton ....
  120.     //Crea un wxBoxSizer
  121.     wxBoxSizer* Box=new wxBoxSizer(wxHORIZONTAL);
  122.    
  123.     //Crea un wxPanel
  124.     wxPanel* Panel1=new wxPanel(this,wxEXPAND);    
  125.  
  126.     //Crea un boton OK y lo coloca en el centro de la ventana
  127.     wxButton* boton=new wxButton(Panel1,wxID_OK,wxT("1"));
  128.     wxButton* boton2=new wxButton(Panel1,wxID_OK,wxT("2"));    
  129.    
  130.     //Anade los bootones al sizer
  131.     Box->Add(boton);
  132.     Box->Add(boton2);
  133.    
  134.     //wxPanel (Panel1) utiliza el wxBoxSizer (Box)
  135.     Panel1->SetSizer(Box);    
  136.    
  137.     //Bind evento de RATON DOBLE CLICK
  138.     Panel1->Bind(wxEVT_LEFT_DCLICK,&MiFrame::EventosRaton,this);
  139. }
  140.  
  141. void MiFrame::EventosRaton(wxMouseEvent& event){// Evento raton Doble Click
  142.      
  143.           wxMessageBox( wxT("Raton ") );
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement