Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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

Posted on 1998-12-04
Medium Priority
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!!!
Question by:Mr_MFC
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3

Expert Comment

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?


Author Comment

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

Expert Comment

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;
 CPoint point;
 int newx=point.x-(rectdlg.Width()+1)/2;
 int newy=point.y-(rectdlg.Height()+1)/2;
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

Thanks, and hope this will help

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

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...

Author Comment

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!

Author Comment

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?


Accepted Solution

pagladasu earned 800 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:
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;
      CPoint pnt;
      int newx=pnt.x-(rectdlg.Width()+1)/2;
      int newy=pnt.y-(rectdlg.Height()+1)/2;
     CDialog::OnMouseMove(nFlags, point);

That's about all. Try the MoveWindow solution.


Author Comment

ID: 1325786

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

604 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