Solved

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

Posted on 1998-12-04
8
214 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

760 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

21 Experts available now in Live!

Get 1:1 Help Now