Hi,
I did raise the question of adding automatic scrollbars to an edit box some time ago and had a go at doing it, with some success. Anyway...
I've made a window that is supposed to have the same client dimensions as the image it is showing. The image's dimensions are held in the variables sImgWidth and sImgHeight. If the window's client area is resized to below the image's width or height the appropriate scrollbar should be shown. I wrote this code for the window's WindowProc:
Code:
case WM_SIZE:
{
if ((GetWindowLong(hwnd, GWL_STYLE) & WS_HSCROLL) != WS_HSCROLL && LOWORD(lParam) < sImgWidth)
{
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_HSCROLL);
SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
}
else if ((GetWindowLong(hwnd, GWL_STYLE) & WS_HSCROLL) == WS_HSCROLL && LOWORD(lParam) >= sImgWidth)
{
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) ^ WS_HSCROLL);
SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
}
if ((GetWindowLong(hwnd, GWL_STYLE) & WS_VSCROLL) != WS_VSCROLL && HIWORD(lParam) < sImgHeight)
{
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_VSCROLL);
SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
}
else if ((GetWindowLong(hwnd, GWL_STYLE) & WS_VSCROLL) == WS_VSCROLL && HIWORD(lParam) >= sImgHeight)
{
SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) ^ WS_VSCROLL);
SetWindowPos(hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
}
break;
}
I did have this working once, when the code was in the parent window's WindowProc (which is stupid, so I moved it), but it doesn't seem to work now. Anyone know why?