-
August 14th, 2015, 06:27 AM
#1
[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)
-
August 14th, 2015, 07:12 AM
#2
Re: how calculate nPos when we resize the window?
But who knows what nPos, X, nPage and the nMax are?
Victor Nijegorodov
-
August 14th, 2015, 08:49 AM
#3
Re: how calculate nPos when we resize the window?
Originally Posted by VictorN
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
-
August 14th, 2015, 08:58 AM
#4
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
-
August 14th, 2015, 09:10 AM
#5
Re: how calculate nPos when we resize the window?
Originally Posted by VictorN
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
-
August 14th, 2015, 09:36 AM
#6
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
-
August 14th, 2015, 10:05 AM
#7
Re: how calculate nPos when we resize the window?
Originally Posted by VictorN
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.
-
August 14th, 2015, 10:10 AM
#8
Re: how calculate nPos when we resize the window?
Victor Nijegorodov
-
August 14th, 2015, 10:26 AM
#9
Re: how calculate nPos when we resize the window?
-
August 14th, 2015, 10:32 AM
#10
Re: how calculate nPos when we resize the window?
Originally Posted by Cambalinho
... 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
-
August 14th, 2015, 11:03 AM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|