CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2007
    Posts
    28

    SetWindowPos in CDialog

    I have a modeless CDialog and im using WM_SIZING and overriding OnSizing(UINT, LPRECT) and SetWindowPos to resize it.
    On my dialog there are about 20 buttons, which are also resized, using SetWindowPos. The problem im having is that i need to keep a gap between all controls. The controls are lined in 5 rows,
    with a gap between all controls( ie above, to the sides and below). If i resize the controls, they overlap each other therefore removing all gaps.
    Basically, how can i position the buttons once resized, to avoid overlapping?
    Any help appreciated!

    code so far:

    void CMyDlg::OnSizing(UINT nSide, LPRECT lpRect)
    {
    CDialog::OnSize(nSide, lpRect)
    CRect rect(lpRect);
    GetClientRect(lpRect);

    //Loop through all controls on the dialog - id's are in consequetive order
    for (int i = IDC_CONTROL1; i < IDC_CONTROL20; i++)
    {
    CWnd* aWnd = GetDlgItem(i);
    aWnd->SetWindowPos(NULL,0,0,rect.Width()/10, rect.Height()/10, SWP_NOMOVE);
    }

    }

  2. #2
    Join Date
    Apr 1999
    Posts
    3,585

    Re: SetWindowPos in CDialog

    Have you thought about enforcing a minimum size for the dialog? One that would prevent the buttons from overlapping?
    Gort...Klaatu, Barada Nikto!

  3. #3
    Join Date
    Jan 2007
    Posts
    28

    Re: SetWindowPos in CDialog

    How will this help? i simply need to maintain a gap around all controls

  4. #4
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: SetWindowPos in CDialog

    Quote Originally Posted by Laurio
    How will this help? i simply need to maintain a gap around all controls
    You need to both resize AND reposition controls.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  5. #5
    Join Date
    Jan 2007
    Posts
    28

    Re: SetWindowPos in CDialog

    If i set a min size rect, how do i go about repositioning the controls then? this is what i need help with!

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: SetWindowPos in CDialog

    Quote Originally Posted by Laurio
    ... code so far:[/CODE]
    void CMyDlg::OnSizing(UINT nSide, LPRECT lpRect)
    {
    CDialog::OnSize(nSide, lpRect)
    CRect rect(lpRect);
    GetClientRect(lpRect);

    }[CODE]
    if it is your actual code then it is wrong!
    You should not call [B]CDialog::OnSize from CMyDlg::OnSizing handler !

    Now about your "resizing" problem. As Mike and Vladimir mentuioned you probably need to handle WM_GETMINMAXINFO message to set the minimal possible size of the dialog window to prevent the child control overlap.
    A ggod start coulb be checking out some article about this problem in www.codeguru.com / www.codeproject.com, for example:
    ResizableLib
    http://www.codeproject.com/dialog/#Control+Positioning
    EasySize - Dialog resizing in no time!

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