How to implement mouse drag using wxWidgets

I have an application without borders so I cannot move the application. This application has a wxPanel so the only way I can click and drag is thru the wxPanel. How to implement mouse drag?

class myFrame : public wxFrame
{
public:
myFrame(const wxString& title, wxWindow *parent=NULL);
wxWindow* parent;

private:
wxDECLARE_EVENT_TABLE();
}

class myPanel : public wxPanel
{
public:
myPanel (wxWindow* parent)
    {
this->parent = parent;
dragging=false;
x=0,y=0;

              Create(parent, wxID_ANY,wxDefaultPosition, *new wxSize(100,100));
    }

void onMouseDown(wxMouseEvent& evt)
{
CaptureMouse();
x = evt.GetX();
y = evt.GetY();
dragging=true;
}

void onMouseUp(wxMouseEvent& evt)
{
ReleaseMouse();
dragging=false;
}

void onMove(wxMouseEvent& evt)
{
if(dragging)
{
wxPoint mouseOnScreen = wxGetMousePosition();
int newx = mouseOnScreen.x - x;
int newy = mouseOnScreen.y - y;
parent->Move(newx, newy);
}
}

private:
wxWindow* parent;
bool dragging;
        int x,y;

wxDECLARE_EVENT_TABLE();
};

wxBEGIN_EVENT_TABLE(myPanel , wxPanel)
EVT_LEFT_DOWN(myPanel ::onMouseDown)
EVT_LEFT_UP(myPanel ::onMouseUp)
EVT_MOTION(myPanel ::onMove)
wxEND_EVENT_TABLE()


wxBEGIN_EVENT_TABLE(myFrame , wxFrame)
wxEND_EVENT_TABLE()


myFrame ::myFrame (const wxString& title, wxWindow *parent)
: wxFrame(NULL, wxID_ANY, title,wxDefaultPosition,wxDefaultSize, wxFULLSCREEN_NOCAPTION)
{
this->parent = parent;
wxPanel* p = new myPanel (this);
}

Comments

Popular posts from this blog

Creating tray application and popup context menu in Windows

How to put an image to wxPanel using wxWidgets

How to build Xerces-c in Windows and Linux