CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Dec 2005
    Location
    BANGALORE ,INDIA
    Posts
    19

    MOving a group of buttons in MFC

    Hi all,

    I need to move a group of buttons.I tried with group box and frames but only the frame or group box is moving and not the buttons placed in it.
    Plz help regarding this.

  2. #2
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: MOving a group of buttons in MFC

    Hi!

    There is no magic, you have to move each button individually.

    Regards / Z

  3. #3
    Join Date
    Mar 2002
    Location
    Banglore
    Posts
    322

    Re: MOving a group of buttons in MFC

    where u want to move the group of button?? at the time when application is running or in resource editor?

  4. #4
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: MOving a group of buttons in MFC

    If it is in resource editor, u can select multple objects using the CTRL key
    or draw a window around all the items to select. Then MOVE

    Cheers

  5. #5
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: MOving a group of buttons in MFC

    By the way, in resource editor (VS 6.0) it seems impossible to move controls in steps of just one pixel. They always move two pixels. That sucks

    Is there a fix?

  6. #6
    Join Date
    Mar 2002
    Location
    Banglore
    Posts
    322

    Re: MOving a group of buttons in MFC

    check it out again. they move in steps of one pixel.

  7. #7
    Join Date
    Apr 2003
    Location
    kathmandu, nepal
    Posts
    1,570

    Re: MOving a group of buttons in MFC

    Originally posted by zerver By the way, in resource editor (VS 6.0) it seems impossible to move controls in steps of just one pixel. They always move two pixels. That sucks

    Is there a fix?
    Try to move by using the keyboard arrows and not by using mouse
    If there is no love sun won't shine

  8. #8
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: MOving a group of buttons in MFC

    Not always. I just tried moving a checkbox three times using the right arrow key.

    The first time it moved two pixels, then one, then two.
    (I pasted a screenshot from the resource editor in Paint Shop Pro after each move to confirm this)

    Annoyances galore. I have VS 6.0 SP5.

  9. #9
    Join Date
    May 2005
    Posts
    4,954

    Re: MOving a group of buttons in MFC

    Quote Originally Posted by zerver
    Not always. I just tried moving a checkbox three times using the right arrow key.

    The first time it moved two pixels, then one, then two.
    (I pasted a screenshot from the resource editor in Paint Shop Pro after each move to confirm this)

    Annoyances galore. I have VS 6.0 SP5.
    This is weird i also using VC6 and i didn’t face this problem; it always moves one pixel with arrow keys.

    PS: Unless you hold the key down of course

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  10. #10
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: MOving a group of buttons in MFC

    OK, I have confirmed now that exactly every second move is two pixels long.

    I also tried switching from Metric to U.S. measurement system in Regional Options but that did not help...

  11. #11
    Join Date
    Dec 2005
    Location
    BANGALORE ,INDIA
    Posts
    19

    Re: MOving a group of buttons in MFC

    Hi all,
    I want to move the buttons while application is running and not in resource editor.

    Thank u.

  12. #12
    Join Date
    Mar 2002
    Location
    Banglore
    Posts
    322

    Re: MOving a group of buttons in MFC

    get the handle of all the buttons u want to move and call MoveWindow() for each button at the event when u want to move thosse buttons

  13. #13
    Join Date
    May 2005
    Posts
    4,954

    Re: MOving a group of buttons in MFC

    Quote Originally Posted by harshandu
    Hi all,
    I want to move the buttons while application is running and not in resource editor.

    Thank u.
    Also look at ::SetWindowPos().

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  14. #14
    Join Date
    Feb 2000
    Location
    Indore, India
    Posts
    1,046

    Re: MOving a group of buttons in MFC

    Hello,

    When you add controls from resource editor, it is added on the dialog window and not in group box, though you place it in the group box. Hence moving group box does not result in moving the control.

    But one can attach the group box as parent to the control you want to move together using CWnd::SetParent function. Moving group box will move the control also. Best place to set the parent is in CDialog::OnInitDialog function. There will be movement in control position when you attach another parent to it, which is the offset of the new parent with respect to the old one.

    Here is a code snippet to be included in OnInitDialog function of the parent dialog class, which moves a control (ID = IDC_BUTTON) from parent dialog to a group box (ID = IDC_GROUP), retaining its original position. Once this is included in OnInitDialog function, moving the groupbox will result in moving the control as well.

    Code:
    	// Calculates offset of group box to the parent window
    	CRect Rect;
    	GetDlgItem(IDC_GROUP)->GetWindowRect(Rect);
    	ScreenToClient(Rect);
    	int X = Rect.left, Y = Rect.top;
    
    	// Sets group box as parent to the control
    	GetDlgItem(IDC_BUTTON)->SetParent(GetDlgItem(IDC_GROUP));
    
    	// Retains original position by offsetting control
    	GetDlgItem(IDC_GROUP)->GetDlgItem(IDC_BUTTON)->GetWindowRect(Rect);
    	GetDlgItem(IDC_GROUP)->ScreenToClient(Rect);
    	Rect.OffsetRect(-X, -Y);
    	GetDlgItem(IDC_GROUP)->GetDlgItem(IDC_BUTTON)->MoveWindow(Rect);
    Regards.
    Pravin.
    Last edited by Pravin Kumar; April 6th, 2006 at 04:45 AM.
    Let me know if I have helped by rating this post

    Recent FAQs

    Drag an image
    Area of a window exposed on desktop
    Display rotated bitmap

  15. #15
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: MOving a group of buttons in MFC

    Quote Originally Posted by zerver
    OK, I have confirmed now that exactly every second move is two pixels long.

    I also tried switching from Metric to U.S. measurement system in Regional Options but that did not help...
    Apart from this, when I click on a button in resource editor it says in the left corner that the size is 51x14, but when I make a screen shot and measure the pixel size it is 77x23. So, I can confirm again that there is definitely something fishy about the resource editor units in VS 6.0.

    If someone knows what is going on, plz tell. Thx.
    Nobody cares how it works as long as it works

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured