Sign in to follow this  

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

This topic is 4333 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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);
}

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
usually you enhance your message map of the view where you want to mouse input


BEGIN_MESSAGE_MAP( CMyview, classtype your derive CMyview from)
//{{AFX_MSG_MAP( CMyview)
ON_WM_LBUTTONDOWN( )
//}}AFX_MSG_MAP
END_MESSAGE_MAP( )


and overload afx_msg void OnLButtonDown( UINT, CPoint ); in your view class


this way you get a message whenever you left clicked into the desired view

for additional information have a look at the msdn

google: msdn mfc


as side note:
before you dive too much into MFC id rather suggest you to have a look at wxwidgets

wxwidgets

its a cross platform gui library that is very similar to mfc except with one advantage, the code looks thousand times clear which is why I use wxwidgets in all my gui app projects

Share this post


Link to post
Share on other sites
;) Yeah.. i have programmed a lot in MFC... but normaly i programm in WinAPI... thats the best way :D

hmm... the Problem is that there Renderer is in an other Class... and in this Class i have no Renderer handle...

Maybe i will send the Renderer a message... with the coordinates... aso...

Share this post


Link to post
Share on other sites
I am working on a level editor on my own

The way I do it is giving each window a id
the 3d camera view will use the gluProject unproject functions

the 2d views use the view ids to determine the picking ray


the final information of the ray is then passed to the scene manager that does the rest for me


i do all modifications with modifiers,

those are stored on a stack to support a undo system, pretty important in almost every editor

i simply store a copy of the unmodified object in the modifier instance and a link to the new modified object this way i can easily undo any changes

this might not be the most efficient way but it works and can be enhanced/improved later on

Share this post


Link to post
Share on other sites
Hmm your Ideas sounds good... :)

.. her is the way i get the mouse positon...

i have added a new Window Message in my CMainFrame Class(Header):

// Defination
#define WM_VIEWMOUSEPOS WM_USER+20

// protected Function for the new Message
afx_msg LRESULT OnViewMousePos(WPARAM wParam, LPARAM lParam);
// protected Membervariable
CPoint m_ptMousePos;


than i added in the Class, which contained the Renderer, a OnMouseMove Message an call the SendMessage Function.

In the CMainFrame Source File, i added the following code:

LRESULT CMainFrame::OnViewMousePos(WPARAM wParam, LPARAM lParam)
{
m_ptMousePos.x = (long)wParam;
m_ptMousePos.y = (long)lParam;

return 0;
}
void CMainFrame::OnIndicatorPos(CCmdUI *pCmdUI)
{
pCmdUI->Enable();
char cText[128];

sprintf(cText, "%d, %d", m_ptMousePos.x, m_ptMousePos.y);

pCmdUI->SetText(cText);
}


That is a realy simple way, i belive so, to handle that problem.

Deviloper
Devil Entertainment

Share this post


Link to post
Share on other sites

This topic is 4333 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this