CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    [RESOLVED] how calculate nPos when we resize the window?

    the nPos is X. now i resize the window. the nPage and the nMax must be changed. until here it's fine. but how can i calculate, now, the new nPos depending on X?
    (i don't know do these calculation)

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

    Re: how calculate nPos when we resize the window?

    But who knows what nPos, X, nPage and the nMax are?
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2009
    Posts
    1,355

    Re: how calculate nPos when we resize the window?

    Quote Originally Posted by VictorN View Post
    But who knows what nPos, X, nPage and the nMax are?
    nPos, nPage and the nMax are CROLLINFO structure members except the 'X', that was for a sample nothing more

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

    Re: how calculate nPos when we resize the window?

    You do it the same way as you did it earlier. You usually recalculate it under the case WM_SIZE in the window procedure used by the widow you resize.
    Victor Nijegorodov

  5. #5
    Join Date
    Apr 2009
    Posts
    1,355

    Re: how calculate nPos when we resize the window?

    Quote Originally Posted by VictorN View Post
    You do it the same way as you did it earlier. You usually recalculate it under the case WM_SIZE in the window procedure used by the widow you resize.
    but if i'm, for example, on half of the scrollbar, i lose the nMax
    Code:
    void setAutoScroll(bool autoscroll)
            {
                blnAutoScroll=autoscroll;
                if((GetWindowLong(hwnd,GWL_STYLE)& WS_VSCROLL))
                {
                    SetWindowLong(hwnd,GWL_STYLE,GetWindowLong(hwnd,GWL_STYLE) &~WS_VSCROLL);
                }
    
                if((GetWindowLong(hwnd,GWL_STYLE)& WS_HSCROLL))
                {
                    SetWindowLong(hwnd,GWL_STYLE,GetWindowLong(hwnd,GWL_STYLE) &~WS_HSCROLL);
                }
    
                if(blnAutoScroll==true)
                {
                    POINT ws=GetClientWindowSize();//give me the last control position+width
                    RECT rtcParent;
                    GetClientRect(hwnd,&rtcParent);
                    if(ws.y>rtcParent.bottom)
                    {
                        SetWindowLong(hwnd, GWL_STYLE,GetWindowLong(hwnd, GWL_STYLE) | WS_VSCROLL);
                        SCROLLINFO SCinfo;
                        SCinfo.cbSize=sizeof(SCROLLINFO);
                        SCinfo.fMask=SIF_RANGE | SIF_PAGE;
                        SCinfo.nMin =0;
                        SCinfo.nMax =ws.y;
                        SCinfo.nPage=rtcParent.bottom;
                        SetScrollInfo(hwnd,SB_VERT,&SCinfo, TRUE);
                    }
                    if(ws.x>rtcParent.right)
                    {
                        SetWindowLong(hwnd, GWL_STYLE,GetWindowLong(hwnd, GWL_STYLE) | WS_HSCROLL);
                        SCROLLINFO SCinfo;
                        SCinfo.cbSize=sizeof(SCROLLINFO);
                        SCinfo.fMask=SIF_RANGE | SIF_PAGE;
                        SCinfo.nMin =0;
                        SCinfo.nMax =ws.x;
                        SCinfo.nPage=rtcParent.right;
                        SetScrollInfo(hwnd,SB_HORZ,&SCinfo, TRUE);
                    }
                }
                SetWindowPos(hwnd,NULL,0,0,0,0,SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_DRAWFRAME);
            }
    SIF_RANGE is for nMax and nMin;
    the SIF_PAGE is for nPage.
    after resize the window(nPos!=0) and then scroll it to nMax, i can't see the left\top most child control

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

    Re: how calculate nPos when we resize the window?

    Sorry, I have no idea what this function is for and where it is about to call from and when.
    Victor Nijegorodov

  7. #7
    Join Date
    Apr 2009
    Posts
    1,355

    Re: how calculate nPos when we resize the window?

    Quote Originally Posted by VictorN View Post
    Sorry, I have no idea what this function is for and where it is about to call from and when.
    imagine that you have a child control with a position more big than window client size... for calculate that, i use the GetClientWindowSize() function. the rest is for show me scrollbars and give them a nMax( the child control with a position more big than window client size) and nPage.

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

    Re: how calculate nPos when we resize the window?

    Quote Originally Posted by Cambalinho View Post
    imagine that you have a child control with a position more big than window client size... for calculate that, i use the GetClientWindowSize() function. the rest is for show me scrollbars and give them a nMax( the child control with a position more big than window client size) and nPage.
    Victor Nijegorodov

  9. #9
    Join Date
    Apr 2009
    Posts
    1,355

    Re: how calculate nPos when we resize the window?

    Quote Originally Posted by VictorN View Post
    see these image:
    Name:  scroll dimentions.png
Views: 48
Size:  4.9 KB
    the GetClientWindowSize() function see where is the button for give me it's bottom value(scroll dimentions).
    then from return values, i show the scrollbars and give them the nMax and nPos values.
    these code works fine. but when the parent window is resized, i call the setAutoScroll() for change it's values. but i'm getting problems on continues with nPos value, when the form is resized

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

    Re: how calculate nPos when we resize the window?

    Quote Originally Posted by Cambalinho View Post
    ... but when the parent window is resized, i call the setAutoScroll() for change it's values. but i'm getting problems on continues with nPos value, when the form is resized
    See my posts##4 and 6.
    Victor Nijegorodov

  11. #11
    Join Date
    Apr 2009
    Posts
    1,355

    Re: how calculate nPos when we resize the window?

    someone, before, told me that, when the parent is resized, that only the nPage is changed. so thinking on that, more, i change more the code and now works fine:
    Code:
    void setAutoScroll(bool autoscroll)
            {
                blnAutoScroll=autoscroll;
                if((GetWindowLong(hwnd,GWL_STYLE)& WS_VSCROLL))
                {
                    SetWindowLong(hwnd,GWL_STYLE,GetWindowLong(hwnd,GWL_STYLE) &~WS_VSCROLL);
                }
    
                if((GetWindowLong(hwnd,GWL_STYLE)& WS_HSCROLL))
                {
                    SetWindowLong(hwnd,GWL_STYLE,GetWindowLong(hwnd,GWL_STYLE) &~WS_HSCROLL);
                }
    
                if(blnAutoScroll==true)
                {
                    POINT ws=GetClientWindowSize();
                    RECT rtcParent;
                    GetClientRect(hwnd,&rtcParent);
                    if(ws.y>rtcParent.bottom)
                    {
                        SetWindowLong(hwnd, GWL_STYLE,GetWindowLong(hwnd, GWL_STYLE) | WS_VSCROLL);
                        SCROLLINFO SCinfo;
                        SCinfo.cbSize=sizeof(SCROLLINFO);
                        SCinfo.fMask=SIF_RANGE | SIF_PAGE;
                        SCinfo.nMin =0;
                        SCinfo.nMax =ws.y;
                        SCinfo.nPage=rtcParent.bottom;
                        SetScrollInfo(hwnd,SB_VERT,&SCinfo, TRUE);
                    }
                    if(ws.x>rtcParent.right)
                    {
                        SetWindowLong(hwnd, GWL_STYLE,GetWindowLong(hwnd, GWL_STYLE) | WS_HSCROLL);
                        SCROLLINFO SCinfo;
                        SCinfo.cbSize=sizeof(SCROLLINFO);
                        SCinfo.fMask=SIF_RANGE | SIF_PAGE;
                        SCinfo.nMin =0;
                        SCinfo.nMax =ws.x;
                        SCinfo.nPage=rtcParent.right;
                        SetScrollInfo(hwnd,SB_HORZ,&SCinfo, TRUE);
                    }
                }
                SetWindowPos(hwnd,NULL,0,0,0,0,SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE | SWP_DRAWFRAME);
            }
    and when the parent is resized:
    Code:
    case WM_SIZING:
                    case WM_SIZE:
                    {
                        if(inst->getAutoScroll()==true)
                        {
                            RECT a;
                            GetClientRect(inst->hwnd,&a);
                            SCROLLINFO SCinfo;
                            SCinfo.cbSize=sizeof(SCROLLINFO);
                            SCinfo.fMask=SIF_PAGE;
                            GetScrollInfo(inst->hwnd,SB_VERT,&SCinfo);
                            SCinfo.nPage=a.bottom;
                            SetScrollInfo(inst->hwnd,SB_VERT,&SCinfo, TRUE);
                            GetScrollInfo(inst->hwnd,SB_HORZ,&SCinfo);
                            SCinfo.nPage=a.right;
                            SetScrollInfo(inst->hwnd,SB_HORZ,&SCinfo, TRUE);
                        }
                        RECT a;
                        GetWindowRect(inst->hwnd,&a);
                        ScreenToClient(GetParent(inst->hwnd),&a);
                        InvalidateRect(inst->hwnd, &a,true);
                        inst->Resize();
                        return 0;
                    }
                    break;
    these simple code give me 1 idea :P
    - when i add\resize a child control i send a message(SendMessage()) to parent(include the control handle) and just test it's client rectangle for change the vertical or horizontal nMax on scrollbar, instead see the client rectangle of all controls.

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