[MFC / DirectX 9] CSplitterWnd - Mouse Position inside...

Started by
13 comments, last by Devil9000 18 years, 2 months ago
Hi guys, i am programming a level editor for a commercial game project but temporary i have got a little problem: I want to know how to get the mouse position inside a CSplitterWnd. I have used MFC and our DirectX Engine for this Level Editor. If someone has an idea, please tell me! Deviloper Devil Entertainment [Edited by - Devil9000 on January 30, 2006 2:27:33 PM]
Advertisement
I think, that i can get a pointer to the CWnd of the active Frame with the following code:
CPoint point; GetCursorPos(&point); CWnd* pWnd = ChildWindowFromPoint(point, CWP_ALL); 

But I can't get the mouse position inside the SplitterFrame...

Any Ideas?

Deviloper
Devil Entertainment
Once you've got both the cursor position in screen coordinates and a CWnd* to the window below you can call pWnd->ScreenToClient on the coordinates to get them transformed to client coordinates.

Alternatively you can use GetPane from the CSplitterWnd to get the CWnd handles to a specific pane.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Quote:
Alternatively you can use GetPane from the CSplitterWnd to get the CWnd handles to a specific pane.

Hmm, yes, that will be posible when you have a handle to the CSplitterWnd... but i have no handle in that class....

Quote:
Once you've got both the cursor position in screen coordinates and a CWnd* to the window below you can call pWnd->ScreenToClient on the coordinates to get them transformed to client coordinates.

Thx... i will try it... and reply :)

Deviloper
Devil Entertainment

[Edited by - Devil9000 on January 30, 2006 2:06:10 PM]
So, i have tryed it, but i didn't get the right Coordinates. I have used the following source:
void CMainFrame::OnIndicatorPos(CCmdUI *pCmdUI){	pCmdUI->Enable();	CPoint point;	char cText[128];    GetCursorPos(&point);	ScreenToClient(&point);	CWnd* pWnd = ChildWindowFromPoint(point, CWP_ALL); 	if(!pWnd)		sprintf(cText, "-, -");	else	{		pWnd->ScreenToClient(&point); 		GetCursorPos(&point); 		sprintf(cText, "%d, %d", point.x, point.y);	}	pCmdUI->SetText(cText);}


Have you got any ideas?

Someone i.O. Deviloper
Devil Entertainment
You're using ScreenToClient twice, that won't work out. The coordinates are relative to the client area of the main window after the first call.

Inside your if clause exchange the GetCursorPos and ScreenToClient call.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

Quote:
You're using ScreenToClient twice, that won't work out.

Sry guy, but i dont agree with you. The first ScreenToClient is for the CMainFrame.... cause of the menu...

But I have tryed the way you descibed... but it didn't work :D

void CMainFrame::OnIndicatorPos(CCmdUI *pCmdUI){	pCmdUI->Enable();	CPoint point;	char cText[128];    GetCursorPos(&point);	// ScreenToClient(&point);	CWnd* pWnd = ChildWindowFromPoint(point, CWP_ALL); 	if(!pWnd)		sprintf(cText, "-, -");	else	{		GetCursorPos(&point);		pWnd->ScreenToClient(&point); 		sprintf(cText, "%d, %d", point.x, point.y);	}	pCmdUI->SetText(cText);}

The Pos which is returned by the GetCursorPos() function is still not the wanted value...

Have you got any ideas?

Deviloper
Devil Entertainment

[Edited by - Devil9000 on January 31, 2006 1:46:42 PM]
Sorry, misunderstanding.

The first ScreenToClient is necessary to get the child window below the mouse. The only thing off then was the switching of GetCursorPos and ScreenToClient inside the if clause.

So it ought to look like this:

void CMainFrame::OnIndicatorPos(CCmdUI *pCmdUI){	pCmdUI->Enable();	CPoint point;	char cText[128];    GetCursorPos(&point);	ScreenToClient(&point);	CWnd* pWnd = ChildWindowFromPoint(point, CWP_ALL); 	if(!pWnd)		sprintf(cText, "-, -");	else	{		GetCursorPos(&point);		pWnd->ScreenToClient(&point); 		sprintf(cText, "%d, %d", point.x, point.y);	}	pCmdUI->SetText(cText);}

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

what exactly are you doing that you want the mouse coordinates inside a splitterwindow instead of inside the views of the splitterwindow?

http://www.8ung.at/basiror/theironcross.html
Quote:
what exactly are you doing that you want the mouse coordinates inside a splitterwindow instead of inside the views of the splitterwindow?

;) You are right.. sry. i want the mouse coordinates inside the views of the SplitterWindow cause of the Picking function and the model drag and drop... If already wondered why the middel of Splitter has with the code above the coordinates 0,0 :D

This topic is closed to new replies.

Advertisement