Here is some sample code that you could use (the CalcClientMetrics function is defined below):
case WM_SIZE: /* Avoid processing other WM_SIZE messages while we are processing this one */if (fSizeInUse == TRUE)return (0);fSizeInUse = TRUE;/* Turn off scrolling and exit if the window is minimized, or if there is no bitmap */if ((wParam == SIZE_MINIMIZED) || (!LeadBitmap.Flags.Allocated)){SetScrollRange(hWnd, SB_VERT, 0, 0, FALSE);SetScrollRange(hWnd, SB_HORZ, 0, 0, FALSE);fSizeInUse = FALSE;return (0);}/* Initialize the client height and width using message parameters */ClientHeight = HIWORD(lParam); ClientWidth = LOWORD(lParam);/* Update the values, separating client information from scrollbar information */CalcClientMetrics(hWnd,&ClientWidth,&ClientHeight,&RightBarThickness,&BottomBarThickness);/* Use the offsets of the display to initialize scroll positions */XScrollPosition = -rLeadDest.left;YScrollPosition = -rLeadDest.top;/* Calculate the range and scroll position of the vertical scroll bar */if (ClientHeight >= DisplayHeight){/* We do not need a vertical scroll bar *//* Use the full display height, and turn off the scroll bar */rLeadDest.bottom = DisplayHeight;rLeadDest.top = 0;SetScrollRange(hWnd, SB_VERT, 0, 0, FALSE);}else{/* We need a vertical scrollbar *//* The range and position of the vertical scrollbar depend on whether there is also a horizontal scrollbar */if (ClientWidth >= DisplayWidth){/* There will not be a horizontal scroll bar *//* Calculate the range without the horizontal scrollbar */YScrollRange = DisplayHeight - ClientHeight;/* If the expected scroll position would leave blank space,adjust the scroll position and reposition the display rectangle */if (YScrollPosition > YScrollRange){/* Reposition the display rectangle */OffsetRect(&rLeadDest, 0, YScrollPosition - YScrollRange);/* Adjust the scroll position */YScrollPosition = YScrollRange;}}else{/* There will also be a horizontal scroll bar *//* Calculate the scroll range, including the scrollbar */YScrollRange = DisplayHeight - ClientHeight + BottomBarThickness;}SetScrollRange(hWnd, SB_VERT, 0, YScrollRange, FALSE);SetScrollPos(hWnd, SB_VERT, YScrollPosition, TRUE);}/* Calculate the range and scroll position of the horizontal scroll bar */if (ClientWidth >= DisplayWidth){/* We do not need a horizontal scroll bar *//* Use the full display width, and turn off the scroll bar */rLeadDest.right = DisplayWidth;rLeadDest.left = 0;SetScrollRange(hWnd, SB_HORZ, 0, 0, FALSE);}else{/* We need a horizontal scrollbar *//* The range and position of the horizontal scrollbar depend on whether there is also a vertical scrollbar */if (ClientHeight >= DisplayHeight){/* There will not be a vertical scroll bar *//* Calculate the range without the vertical scrollbar */XScrollRange = DisplayWidth - ClientWidth;/* If the expected scroll position would leave blank space,adjust the scroll position and reposition the display rectangle */if (XScrollPosition > XScrollRange){/* Reposition the display rectangle */OffsetRect(&rLeadDest, XScrollPosition - XScrollRange, 0);/* Adjust the scroll position */XScrollPosition = XScrollRange;}}else{/* There will also be a vertical scroll bar *//* Calculate the scroll range, including the scrollbar */XScrollRange = DisplayWidth - ClientWidth + RightBarThickness;}SetScrollRange(hWnd, SB_HORZ, 0, XScrollRange, FALSE);SetScrollPos(hWnd, SB_HORZ, XScrollPosition, TRUE);}fSizeInUse = FALSE; return (0);/*---[CalcClientMetrics]-------------------------------------------------------Parameters: HWND hWnd Window handleint *nClientWidth Width in and width outint *nClientHeight Height in and height outint *nRightBarThickness Resulting thickness of the Y scrollbarint *nBottomBarThickness Resulting thickness of the X scrollbarProtoType: EZFunc.hNotes: Use this function to interpret the client area width andheight parameters from the WM_SIZE message. The incomingparameters attempt to give us the correct client area, excludingscrollbars. But, because while processing this message weshow or hide the scrollbars, the incoming parameters often arenot correct. Therefore, we must get the true client areadimensions, including scrollbars, and get the thickness ofscrollbars. The caller can then make its own decisions aboutthe size of the client area.--------------------------------------------------------------------------*/void CalcClientMetrics(HWND hWnd,int *nClientWidth,int *nClientHeight,int *nRightBarThickness,int *nBottomBarThickness){DWORD dwStyle, dwVersion;int cxClient, cyClient, cxScroll, cyScroll;/* Initialize local variables */cxClient = *nClientWidth;cyClient = *nClientHeight;cxScroll = GetSystemMetrics(SM_CXVSCROLL);cyScroll = GetSystemMetrics(SM_CYHSCROLL);dwStyle = GetWindowLong(hWnd, GWL_STYLE);/* Adjust for the difference in how newer WIN32 versions report scrollbar thickness when there is a window border */#ifdef WIN32{dwVersion = GetVersion();if (LOBYTE(LOWORD(dwVersion)) >= 4){cxScroll += GetSystemMetrics(SM_CXBORDER);cyScroll += GetSystemMetrics(SM_CYBORDER);}}#endif/* If there is a window border, subtract it from the scrollbar thickness */if (dwStyle & WS_BORDER){cxScroll -= GetSystemMetrics(SM_CXBORDER);cyScroll -= GetSystemMetrics(SM_CYBORDER);}/* Add the scrollbar thickness to the client area */if (dwStyle & WS_VSCROLL)cxClient += cxScroll;if (dwStyle & WS_HSCROLL)cyClient += cyScroll;/* Update the caller's variables */*nClientWidth = cxClient;*nClientHeight = cyClient;*nRightBarThickness = cxScroll;*nBottomBarThickness = cyScroll;}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
