How to (move && drag) wxdialog without caption?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
emarti
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 210
Joined: Sat May 07, 2005 8:24 pm
Location: Eskisehir, TURKEY
Contact:

How to (move && drag) wxdialog without caption?

Post by emarti » Sat May 14, 2005 11:08 pm

How to (move && drag) wxdialog without caption with mousedown event?
Thanks!

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Re: How to (move && drag) wxdialog without caption?

Post by upCASE » Tue May 17, 2005 7:26 am

Hi!
emarti wrote:How to (move && drag) wxdialog without caption with mousedown event?
Thanks!
Check if the mouse entered the dialog and catch mouse events for the dialog. If left button is down, use Move() for the dialog.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

emarti
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 210
Joined: Sat May 07, 2005 8:24 pm
Location: Eskisehir, TURKEY
Contact:

Post by emarti » Tue May 17, 2005 10:01 pm

thanks answer to me.

I am thinking..... for Windows

Code: Select all

/*
 * movetheDlgMouseEvents
 */
void movetheDlg::movetheDlgMouseEvents(wxMouseEvent& event)
{
	// insert your code here
 if (event.LeftDown())
    {
   	                  HWND Handle;
	                  ReleaseCapture();
                      SendMessage(Handle,WM_SYSCOMMAND,SC_MOVE,0);        
                      }
	event.Skip();
}
if leftdown event is done, dialog window not move. What's wrong?
OR
Your advice?

emarti
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 210
Joined: Sat May 07, 2005 8:24 pm
Location: Eskisehir, TURKEY
Contact:

Post by emarti » Tue May 17, 2005 10:19 pm

Use wxFrame in Windows OS

Code: Select all

/*
 * movewindowFrmMouseEvents
 */
void movewindowFrm::movewindowFrmMouseEvents(wxMouseEvent& event)
{
	// insert your code here
 if (event.LeftDown())
    {
ReleaseCapture();
SendMessage((HWND)this->GetHandle(),WM_SYSCOMMAND,SC_MOVE+1,0);        
                      }
	event.Skip();
}

That's all folks. Thank again!

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Wed May 18, 2005 6:37 am

Hi!
This works with dialogs too. Try using wxWindow::Move() to have a cross platform implementation.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

emarti
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 210
Joined: Sat May 07, 2005 8:24 pm
Location: Eskisehir, TURKEY
Contact:

Post by emarti » Thu May 19, 2005 7:50 pm

Hi,
I tried with wxWindow::Move(wxPoint).

How to set wxPoint while leftdown()?

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Fri May 20, 2005 6:59 am

Hi!
emarti wrote: I tried with wxWindow::Move(wxPoint).

How to set wxPoint while leftdown()?
I suggest the following:
1. Get the x/y coordinates of the mouse event. Store them somewhere.
2. Set capture to the dialog.
3. Check if the mouse has been moved during the next event using the stored x/y values while the left button is pressed.
4. If so, it was a "drag" event. You'll have to recalculate the x/y values to get the actual position of the dialogs upper left corner, then use the stored and the event x/y values to get how many pixels it should be moved.
5. Use the actual positon +/- the x/y moved values and use Move() to move the dialog.

This might look complicated, but it isn't :D

Code: Select all

void MyDialog::OnLeftDown(wxMouseEvent& evt)
{
	CaptureMouse();
	wxPoint pos = ClientToScreen(evt.GetPosition());
	wxPoint origin = GetPosition();
	int dx =  pos.x - origin.x;
	int dy = pos.y - origin.y;
	m_delta = wxPoint(dx, dy);
}

Code: Select all

void MyDialog::OnMouseMove(wxMouseEvent& evt)
{
	wxPoint pt = evt.GetPosition();
	if (evt.Dragging() && evt.LeftIsDown())
	{
		wxPoint pos = ClientToScreen(pt);
	        Move(wxPoint(pos.x - m_delta.x, pos.y - m_delta.y));
 	}
}

Code: Select all

void MyDialog::OnLeftUp(wxMouseEvent& evt)
{
    if (HasCapture())
    {
        ReleaseMouse();
    }
}
These are separate handlers for left down, left up and motion events. Note that m_delta is an internal wxPoint. If this doesn't work for the dialog directly, use these for a wxPanel on the dialog and do GetParent()->Move().
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

emarti
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 210
Joined: Sat May 07, 2005 8:24 pm
Location: Eskisehir, TURKEY
Contact:

Post by emarti » Fri May 20, 2005 10:55 pm

Thank you very much for interesting.

Regards,
emarti

aquawicket
Earned some good credits
Earned some good credits
Posts: 103
Joined: Sun Aug 05, 2007 5:49 am

Post by aquawicket » Mon Oct 01, 2007 2:04 pm

I use this method to move my parent window. This method works, but as I drag the window, I get a smear effect. It's as if the previous windows are not deleted fast enough when I drag. I've got it stripped down to a simple wxFrame and this code.

Any Ideas?

HeReSY
Earned some good credits
Earned some good credits
Posts: 120
Joined: Fri Sep 17, 2004 8:58 pm
Location: Germany

Post by HeReSY » Tue Oct 02, 2007 5:19 am

Look at the shape sample of the wxWidget-distri.
You can find there some source how to do this.

HeReSY

Post Reply