Solved

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

Posted on 1998-12-04
8
218 Views
Last Modified: 2013-11-20
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!!!
         
0
Comment
Question by:Mr_MFC
  • 5
  • 3
8 Comments
 
LVL 4

Expert Comment

by:pagladasu
ID: 1325779
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
 

Author Comment

by:Mr_MFC
ID: 1325780
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
 
LVL 4

Expert Comment

by:pagladasu
ID: 1325781
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
 

Author Comment

by:Mr_MFC
ID: 1325782
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Mr_MFC
ID: 1325783
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
 

Author Comment

by:Mr_MFC
ID: 1325784
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
 
LVL 4

Accepted Solution

by:
pagladasu earned 200 total points
ID: 1325785
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
 

Author Comment

by:Mr_MFC
ID: 1325786
Thanks!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to create frequencies of a variable from SAS dataset? 10 121
iSeries FTP Exit Program 8 124
windows 10 how make picture as desktop background 2 58
lucky13 challenge 11 122
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now