Help Moving Controls (SDI)

There must be an easier way to do all of this!  Please help.

I have an editing application that allows the user to create and edit
custom buttons, listboxes, etc...  I can allow the user to resize the
objects (no problem), but when the user tries to move the objects to a
different location in the View I have issues.

I found one way to allow the user to move a CButton type (yes, I have a
pointer to the current CView object):
void CustomButton::OnMouseMove(UINT nFlags, CPoint point)
{
		if(nFlags & MK_LBUTTON)
		{
			ClientToScreen(&point);
			RECT tmpRect;
			_view->GetWindowRect(&tmpRect);
			SetWindowPos(&CWnd::wndTop, point.x - tmpRect.left, point.y -
tmpRect.top, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
			_view->GetDocument()->SetModifiedFlag();
		}

	CWnd::OnMouseMove(nFlags, point);
}

One drawback of this is that the button initialy positions itself with
the upper left corner where the mouse is and then the movement of the
button is fine.  Now I am trying to do this same operation with a
CListBox and am not having pleasant results.  I can not move the CList
box up or to the right and it repositions itself in strange increments.

Any help?

0
gunblade01 (15)
12/19/2005 6:10:23 PM
vc.mfc 33608 articles. 0 followers. Follow

5 Replies
731 Views

Similar Articles

[PageSpeed] 11

You will need to do a little more than just catch the MouseMove Message.

If I was doing this I would catch the LButtonDown message, where I would
keep track of the offset of the initial grab point in relation to the top
left corner of the control, and also call set capture (so that you don't
lose the control when they move off the view)
Do the moving in the OnMouseMove using the offset point recorded in the
OnLButtonDown,

and finally call ReleaseCapture in OnLButtonUp

(By the way don't need the pointer to the view for this you can use
GetParent())

void CustomButton::OnLButtonDown(UINT nFlags, CPoint point)
{
    CWnd::OnLButtonDown(nFlags, point);

    m_StartPoint = point;
    SetCapture();
}

void CustomButton::OnMouseMove(UINT nFlags,CPoint point)
{
    CWnd::OnMouseMove(nFlags,point)
    if (nFlags & MK_LBUTTON)
    {
        CPoint Diff =  point - m_StartPoint;
        m_StartPoint = point;

        CRect Rect;
        GetWindowRect(Rect);
        Rect.OffsetRect(Diff);
        CWnd *pParentWnd = GetParent();
        ASSERT(pParent != NULL);
        pParent->ScreenToClient(&Rect);

SetWindowPos(NULL,Rect.left,Rect.top,Rect.Width(),Rect.Height(),SWP_NOZORDER
);
    }
}

void CustomButton::OnLButtonUp(UINT nFlags, CPoint point)
{
    CWnd::OnLButtonUp(nFlags, point);

    ReleaseCapture();
}

I hope I got it all right, since I typed in here and didn't compile it
AliR.

"Grimy45" <gunblade01@yahoo.com> wrote in message
news:1135015823.390433.209680@g44g2000cwa.googlegroups.com...
> There must be an easier way to do all of this!  Please help.
>
> I have an editing application that allows the user to create and edit
> custom buttons, listboxes, etc...  I can allow the user to resize the
> objects (no problem), but when the user tries to move the objects to a
> different location in the View I have issues.
>
> I found one way to allow the user to move a CButton type (yes, I have a
> pointer to the current CView object):
> void CustomButton::OnMouseMove(UINT nFlags, CPoint point)
> {
> if(nFlags & MK_LBUTTON)
> {
> ClientToScreen(&point);
> RECT tmpRect;
> _view->GetWindowRect(&tmpRect);
> SetWindowPos(&CWnd::wndTop, point.x - tmpRect.left, point.y -
> tmpRect.top, 0, 0, SWP_NOSIZE|SWP_NOZORDER);
> _view->GetDocument()->SetModifiedFlag();
> }
>
> CWnd::OnMouseMove(nFlags, point);
> }
>
> One drawback of this is that the button initialy positions itself with
> the upper left corner where the mouse is and then the movement of the
> button is fine.  Now I am trying to do this same operation with a
> CListBox and am not having pleasant results.  I can not move the CList
> box up or to the right and it repositions itself in strange increments.
>
> Any help?
>


0
AliR3470 (3236)
12/19/2005 7:30:09 PM
Thanks for the response.

Your code logically makes sense and it almost works.  Two things
happen:

1) If I step into the OnMouseMove function it seems to place the object
in the proper place, but as soon as I don't break into this function
(in order to move the object more than one position) it only moves half
the way to the new location.  So, if I try to drag the object to the
opposite corner of the screen (or View) it gets placed in the middle.
2) The object is no longer redrawn as I move, but is invisible until I
release the Left Mouse button.

0
gunblade01 (15)
12/20/2005 3:04:01 PM
It appears that the OnMouseMove function also gets called by the
framework when the SetWindowPos() is called.  If I record the
coordinates in the OnMouseMove after moving the mouse 1 place to the
left and keeping the mouse held down I see the X position changing from
1 to -1 over and over again until I release the mouse.

0
gunblade01 (15)
12/20/2005 3:47:56 PM
Thanks for the Help.  I corrected several errors based off your
suggestions and found a way to get what I needed.
I calculated the difference values only once in the OnLButtonDown()

void CustomButton::OnMouseMove(UINT nFlags, CPoint point)
{
		if(nFlags & MK_LBUTTON)
		{
			ClientToScreen(&point);
			RECT tmpRect;
			((CView*)GetParent())->GetWindowRect(&tmpRect);

			SetWindowPos(&CWnd::wndTop,
					     point.x - tmpRect.left - m_StartPoint.x,
						 point.y - tmpRect.top - m_StartPoint.y,
						 0,0,SWP_NOSIZE|SWP_NOZORDER);
			((CView*)GetParent())->GetDocument()->SetModifiedFlag();
			Invalidate();
			}

	CButton::OnMouseMove(nFlags,point);
}

void CustomButton::OnLButtonDown(UINT nFlags, CPoint point)
{

    SetCapture();
	CRect Rect;
	GetWindowRect(Rect);
	Rect.OffsetRect(point);
    m_StartPoint = point;


	CButton::OnLButtonDown(nFlags, point);
}

void CustomButton::OnLButtonUp(UINT nFlags, CPoint point)
{
	    ReleaseCapture(); 

	CButton::OnLButtonUp(nFlags, point);
}

0
gunblade01 (15)
12/20/2005 5:48:52 PM
I am sorry here is the fix
remove the line
m_StartPoint = point;
from OnMouseMove and everything should work fine.

Here is what I was using


CMovableStatic::CMovableStatic()
: m_StartPoint(-1,-1)    //this will be used so that the user isn't
                                    //clicking outside the window and then
                                    //when mouse moves inside the window
                                    //it starts dragging.
{
}

CMovableStatic::~CMovableStatic()
{
}


BEGIN_MESSAGE_MAP(CMovableStatic, CStatic)
   ON_WM_LBUTTONDOWN()
   ON_WM_MOUSEMOVE()
   ON_WM_LBUTTONUP()
END_MESSAGE_MAP()



// CMovableStatic message handlers


void CMovableStatic::OnLButtonDown(UINT nFlags, CPoint point)
{
   m_StartPoint = point;
   SetCapture();
   CStatic::OnLButtonDown(nFlags, point);
}

void CMovableStatic::OnMouseMove(UINT nFlags, CPoint point)
{
    //LButton is down, and we did get the WM_LBUTTONDOWN message
   if (nFlags & MK_LBUTTON && m_StartPoint.x >= 0 && m_StartPoint.y >= 0)
   {
      CPoint Diff =  point - m_StartPoint;

      CRect Rect;
      GetWindowRect(Rect);
      Rect.OffsetRect(Diff);
      CWnd *pParentWnd = GetParent();
      ASSERT(pParentWnd != NULL);
      pParentWnd->ScreenToClient(&Rect);


SetWindowPos(NULL,Rect.left,Rect.top,Rect.Width(),Rect.Height(),SWP_NOZORDER
);
   }
   CStatic::OnMouseMove(nFlags, point);
}

void CMovableStatic::OnLButtonUp(UINT nFlags, CPoint point)
{
   ReleaseCapture();
   m_StartPoint.SetPoint(-1,-1);

   CStatic::OnLButtonUp(nFlags, point);
}

AliR.


"Grimy45" <gunblade01@yahoo.com> wrote in message
news:1135093676.090052.303460@z14g2000cwz.googlegroups.com...
> It appears that the OnMouseMove function also gets called by the
> framework when the SetWindowPos() is called.  If I record the
> coordinates in the OnMouseMove after moving the mouse 1 place to the
> left and keeping the mouse held down I see the X position changing from
> 1 to -1 over and over again until I release the mouse.
>


0
AliR3470 (3236)
12/20/2005 6:01:06 PM
Reply:

Similar Artilces:

Help getting SheetName into a cell
I need to refer to the sheet name in a formula and can't figure out how to do it. I can't find a Function which will do this. I did discover ActiveSheet.Name but I have been unsuccessful in getting it work in a function. Specifically I have sheets named "1.a" , "1.b" , "1.c" . . . "99.a" , "99.b" , "99.c" and need to get these names into cell C3 of each sheet. The sheets may not be in order and there may be missing sheets. Thanks in advance for any help. Omar Hi You could put somthing like this in a macro or attatch ...

Help with SQL Query 06-30-10
We have a distinct list of email addresses in alpha order and we need to transform it from a single column into a grid of three columns maintaining the alpha order. The list is contained in a temp table inside of our query. We then use the temp table list and perform case statement with a mod on the row_number in a select statement to columnze the data. However, the columnar data contains a null value in two of the three columns and we are needing to remove the nulls and have the actual values on each row in the output. Here is our current sql: CREATE TABLE #tmpTable ( Email_Add...

Messages not delivered to another Routing Group HELP NEEDED
I have three routing groups ( exchange in the 3 of them are Exch 2k sp3 ). Mail from one server ( in my headquarter routing group ) to another ( in one branch office routing group ) is getting stucked in MESSAGES WITH UNREACHABLE DESTINATION and not routed to that server. Connectors seems to be working just fine. After add my other exchange server from my headqurter group to the connector to be albe to send mail it shows the queue now in the connector but does not sends anything. Otherwise, mail from my branch office to my headquarter correctly sends mail. Any help would be gre...

Problem using Microsoft Web Browser control
I am trying to access the Custom properties of a Web Browser ActiveX control on a form and I keep getting a message telling me that "The Operation on the Microsoft Web Browser object failed. The OLE server may not be registered. To register the OLE server, reinstall it." I searched TechNet and MSDN and could not resolve this. I reinstalled Access 2003 (I have 2003 and 2007 installed on my workstation, XP Pro) and still no resolution. Has anyone else seen this and if so, can you tell me how to resolve this? Jim Does anyone know the name of the file the message...

moving messages from outlook express to outlook
I am trying to move messages from outlook express version 6 to outlook 2003. When I export from outlook express, there is no indication where the export file is stored. Is there a way to move messages or will I have to email them to myself? Thanks ...

Removing RAID controller at XP boot up
I installed a pci card with two ATA 133 HD drive ports it came with drivers, I think I installed the wrong driver (RAID instead of straight). Cant get rid of the Marvel Raid control because it comes up before boot and has presumably tucked itself in the bios somewhere. Is there a solution? Perhaps reflashing the bios? Charlie+ "Charlie+" <charlie@xxx.net> wrote in message news:k47mq55qel8a848nl8u1l7rp31uvvdhg4m@4ax.com... > I installed a pci card with two ATA 133 HD drive ports it came with > drivers, > I think I installed the wrong driver (RAID inste...

Need help with Combo Box?
I would appreciate any help with this. I currently have a form with two combo boxes and a subform. The first combo box lists counties and the second box lists doctors in selected county. After selecting county, doc the subform lists pts for this doc. All this works fine. However, I need to add a couple of more filters. I am stuck and would like to know how to do this. I don't want to mess up what I already have. How can I incorporate a couple more filters? I thought maybe adding an option box to the form????? Can someone please help me to accomplish this? Thank you. Sure...

Moving the Area of Interest across the Video Sequence
Hello, I am capturing a live acquisition of image 1280*1024 and defined a subwindow or Area of Interest (AOI) of size 1280*40 using MFC programming .I want to move this AOI across the 1280*1024 window (across the video sequence). I am thinking of using a timer or a for loop so that it will iterate on each of the frames of the video. Can anyone please kindly help me regarding this. Thanks in advance James. ...

Why is my tab key moving my cursor from column A to column k?
In all of my excel worksheets, when I push Tab, my cursor goes straight from Column A to Column K or the next column not shown to the right of the sheet. From there, if I hit Shift-Tab It always goes back to column A, even if that's not where I started out. Please help, it's driving me crazy!!! Turn off Lotus 1-2-3 Transition options Tools, Options, Transition (tab), turn off all transition options --- HTH, David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001] My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm Search Page: http://www.mvp...

Help making BINGO cards
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel I am quite the novice at using Excel. I'm trying to create a set of BINGO cards for a church group and I'm having trouble figuring it out. I saw a post about something called RAND function but I don't know what that means. <br><br>What I need is 56 unique cards with 5 columns and 5 rows each. The cards will be using the numbers 1-24 leaving the center square blank or &quot;0&quot;. <br><br>Can anyone please assist? This is a multi-part message in MIME format. ----...

Calculating Averages
Hi, I am using the newest version of Excel on Windows 7, and I need some help with a complex calculation. In cells A1-A100, I have dollar amounts ranging from $1-$1000. In cells B1-B100, I have percentages ranging from 0%-100%. I want to break out the cells in A1-A100 in several groups, like follows: $1-$99, $100-$199, $200-$299, and so on up to $1000. Then, I need to calculate the average percentage for jobs in those categories. So, for the category of $1-$99, lets say there are two cells with amounts in that range, A1 and A2. Their percentages in B1 and B2 are 40% and 6...

REALLY NEED HELP
Hi guys, i'm hoping someone could lend me a hand. I'm setting up an excel file to input our fees received from our customers sent to collections. I have a main page with all the customers names, and each name is a hyper link to that customers separate worksheet - where a running tab is kept. I have a button called "update" and i've assigned the following macro (also called UPDATE) move the info over to the respective customers worksheet. I'm trying to get a loop going. A# is the customers name (first name will be starting at A4. B# to F# (first transaction...

Lebans tooltip control 10-28-07
I am trying to use the tooltip control on a form with a tab control, on which are the other controls I want to show information for. On controls that are outside the tab control, it works fine; on controls inside the tab control, the tooltip shows on text boxes only when they have the focus, and on check boxes not at all. I've tried every naming scheme for controls I can think of, without any luck. Anybody have any ideas about this??? Is it the same problem as using a subform???? I am using ACCESS 2003 -- Jack Walsh ...

Workbook there but not visible! Help!
I was working on some VBA code for an excel application I am writing. I switched between the VBE and the spreadsheet and all of a sudden my workbook is no longer visible! In the VBE project explorer window it shows my project and my code but in the excel window...no workbook! Nothing! Ran a test procedure calling IsAddin to see if somehow I accidentally clicked a button/box telling Excel to make this file an addin but it returned false. I did close the file and re-open it. Any ideas? Maybe it's just off the visible screen: Window|Arrange|tiled (and resize manually) or maybe y...

Using arrow keys to move between cells
Hey guys, Sorry for dumb question, but how do I move between cells w/o using my mouse and rather using arrow keys? Do you have use any of shift, alt, ctrl keys at same time? Thanks. If pressing the arrow keys are not moving you between cells, check and see if scroll lock is on on the key board, here is some info from help Arrow keys Move one cell up, down, left, or right. CTRL+arrow key Move to the edge of the current data region. HOME Move to the beginning of the row. CTRL+HOME Move to the beginning of the worksheet. CTRL+END Move to the last cell on the worksheet, in the bottom-most us...

E2K3
We currently have a mixed mode environment with Exchange 5.5 on NT 4.0 and Exchange 2003 on Windows 2000. We have completed the migration of our mailboxes and public folders to E2K3 and are in the process of decommissioning our 5.5 Site. We have a policy setup on our mail stores to send a warning when a user reaches 95MB and to prohibit sending at 100MB. We also have standards in place regarding the storage group/mail store location of our users on the E2K3 servers. The first problem we are experiencing is ESM is reporting a mailbox size that is significantly larger than what Outlook 2002 ...

Please help Password Trouble
I am using outlook 2000 on a DSL line on XP Home. I have chosen to not save my password, and the problem that I am having is that everytime I go to check my mail it makes me type in my password. There must be a way (like in express) that allows you to just type in your password the first time you log into outlook and keeps you logged in until you decide to log out?? Thanks for your help!!!! -- Virtualliance, Inc. Mark Needham 7 Kimball Lane Bldg A Lynnfield, Ma 01940 T 001-781-224-4700 F 001-781-224-2414 C 001-617-799-4597 www.virtuallianceinc.com mneedham@virtuallianceinc.com im: vaincmar...

Spinner Control and Protected Worksheet
I have inserted a SPINNER control in my worksheet > thereafter, I have REMOVED its "Locked" checkmark (format control > protection). Then, I protected the worksheet. When I try to use the spinner after protecting the workseet, the system says: "The cell or chart you are trying to change is protected and therefore read-only"!!! VERY VERY FRUSTRATING. Any suggestions ???? (worksheet enclosed - protected without a password for testing). Attachment filename: test.xls Download attachment: http://www.excelforum.com/attachment.php?postid...

Help! Lost all email from inbox
Hi, hoping someone can advise me. Somehow my fingers fumbled when reaching for mouse to open an email and every email in my inbox disappeared. I have outlook 2000 and do have it set to automatically delete when i highlight and press delete key. But in this case, i didnt highlight anything and must have hit some combination of keys and poof - over 100 emails from inbox disappeared. They are not in deleted items folder and many were not even opened yet. tia kate <kate@discussions.microsoft.com> wrote: > Hi, hoping someone can advise me. Somehow my fingers fumbled when >...

Please help....
I have a question regarding bank reconciliations that I am hoping someone can help me with. It concerns a USD bank account that I use. At the end of the month I prepare the bank reconciliation in GP. After completing the reconciliation I get a print-out called the "Reconciliation Posting Journal". This print-out provides me with the folowing: Bank Statement Balance Oustanding Cheques(-) Depoits in Transit(+) =Adjusted Bank Balance All of these amounts are in USD. Then I go to "Financial - Inquiry - Summary" and pull the summary balance for this GL ...

Sum of calculated controls in footers
I have a report with the following groupings: 1.) Claimant 2.) Group 3.) Carrier in the Claimant footer I have the a control named max_ded with the following calculation =Max([Ded]). I need to be able to sum this field at the "group level", and then sum the "group level sum" at the carrier level. I have tried to sum(max([Ded])) and I get error messages. I have tried Sum([max_ded]) etc. Any ideas would be greatly appreciated. Thanks ...

Edit control
Hi, I have a dialog window to display as modal, in the dialog , there is a edit control, the focus is in edit control, I want to catch the enter key when user press enter in edit control, but the dialog close when I press enter key(I donot want to close the dialog). How can I catch the enter pressed message in dialog? Thanks Jessie Hi Jassie, Note that any time you press enter and if the focus is in an edit ctrl the CDialog::OnOk() func will be called. If you override CYourDlg::OnOk, it means that this func will be called, and, of course, it contains the call of CDialog::OnOk. Hence, y...

Help! New to Publisher
What is the A...at the bottom of a page inside a small box? I am typing a newsletter. Shouldn't one page flow to the next like in Microsoft Office? If it is text overflow, I cannot retrieve. What am I doing wrong? Please advise. That indicates that there is more text inside that area that cannot be seen. If you stretch that text box down, you'll see the rest of your text. To make it flow from one box to another, you need to set it up for that. (I will admit that I break mine manually because I've never taken the time to learn how to do it correctly.) -- The problem with ...

Outlook 2002 backup question...please help!
Hi all, I am having a problem with windows which may require me to reformat. I cannot get into outlook (2002) via windows, but I can access files from dos. Can someone please tell me where the data files for outlook 2002 are stored, and which ones I'd need to copy? Thanks in advance for any help. Jim See if this info helps: http://www.howto-outlook.com/howto/backupandrestore.htm "Jim" <lakerfan426@yahoo.com> wrote in message news:OUhIH0oTGHA.4132@TK2MSFTNGP11.phx.gbl... > Hi all, > > I am having a problem with windows which may require me to reformat. I >...

Need Help Using A Custom Session Manager
Hi. I have some questions about session management. I have decided to use a custom session manager class to have more control over session state in my web site. I have started out by using Stephan Prodan's Session Class here: http://stefanprodan.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&_c=BlogPart&partqs=cat%3DC%2523 You'll need to take a look (which I appreciate immensely) to get a sense of what I am talking about. 1) My first question pertains to how I persist and access my session information after a user authenticates (or doesn't). In his exam...