Solved

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

Posted on 1998-12-04
8
230 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
not able to insert into temp table 68 174
Process filename extension 3 209
List out all word 7 339
My project did see openJDK that I installed. What could be the problem 7 162
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

696 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