Question on Dialog co-ordinates and mouse cursor (answer2000?)

Hi there,
         This question has been previously asked and answer2000 has provided me with an explicit solution, can answer2000 post ur solution again because I seem to have problem with my old account (MrMFC) thanx!
Just for a recall for this question... I hope to set and get the dialog's co-ordinates and wish to set the mouse's cursor position to be the center co-ordinates of the dialog box... and also the dialog box should moves when my mouse moves.

Any help offered is very much appreciated!!!
         
Mr_MFCAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
pagladasuConnect With a Mentor Commented:
I didn't use MoveWindow because it would be requiring 2 more parameters - the width and height. By setting the SWP_NOSIZE these 2 parameters will be ignored by SetWindowPos. MoveWindow() also works:
MoveWindow(newx,newy,rectdlg.Width(),rectdlg.Height());
There is a small correction you have to make though. Instead of declaring CPoint point, give the variable name as something like pnt. Remove the if block and you will not have to click the mouse anymore. Your revised code would be in OnMouseMove:

      CRect rectdlg;
      GetWindowRect(&rectdlg);
      CPoint pnt;
      ::GetCursorPos(&pnt);
      int newx=pnt.x-(rectdlg.Width()+1)/2;
      int newy=pnt.y-(rectdlg.Height()+1)/2;
      SetWindowPos(NULL,newx,newy,0,0,SWP_NOZORDER|SWP_NOSIZE);
     SendMessage(DM_REPOSITION,0,0);
     CDialog::OnMouseMove(nFlags, point);

That's about all. Try the MoveWindow solution.

0
 
pagladasuCommented:
Just a few questions first.
Do you want the mouse cursor to be always centred in the dialog box when it moves?
Do you want the mouse cursor to be centred whenever the dialog box shows up?
What if the mouse cursor is moved near the edge of the screen - do you want the dialog box always within the screen or part of it disappearing?

Thanks
pagladasu
0
 
Mr_MFCAuthor Commented:
Good question pagladasu... hehee...
1) yes
2) yes
3) I'm really interested to know both the solutions.

Thanks pagladasu for helping to make my question more explicit :P
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
pagladasuCommented:
Look Mr_MFC,
I don't know what Answer2000 had provided to you. I haven't seen it, neither can I find it anywhere here in the locked or answered questions. So I will proceed to offer you my solution. You think if it deserves points, then go ahead.
To answer the first part you have to map the WM_MOUSEMOVE and add the following code in the OnMouseMove() function of the dialog:

if(nFlags & MK_LBUTTON){
 CRect rectdlg;
 GetWindowRect(&rectdlg);
 CPoint point;
 ::GetCursorPos(&point);
 int newx=point.x-(rectdlg.Width()+1)/2;
 int newy=point.y-(rectdlg.Height()+1)/2;
 SetWindowPos(NULL,newx,newy,0,0,SWP_NOZORDER|SWP_NOSIZE);
}
SendMessage(DM_REPOSITION,0,0); //if you want the dialog to always be in the screen
CDialog::OnMouseMove(nFlags, point);

Similarly in the OnInitDialog() function, write the same code starting from
CRect rectdlg;
and ending in
SetWindowPos(....);

Thanks, and hope this will help
pagladasu

0
 
Mr_MFCAuthor Commented:
Okay, good effort! Pagladasu! Take ya points!
Since I can't split the points I guess I'll double the points
the next question answered by answer2000 :)
Good job both of ya! heheee...
0
 
Mr_MFCAuthor Commented:
Oh yes... what about MoveWindow()? Does this function move the dialog box also? and why is it not implemented in your solution?
Please advice thanks!
0
 
Mr_MFCAuthor Commented:
Ok.. I've implemented your solution but it seems that I've to click the mouse button in order to move the dialog box.
Is it possible to implement the same thing but the dialog box moves as my mouse move without clicking any of the mouse button?

0
 
Mr_MFCAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.