Win32, scrollwindowex (): how to display back the up area from the "off window" that disappeared after scrolling down?

Many things have appeared in my main application window, so I need a vertical scrollbar to fit all within the client area. I encoded a scrollbar control, WM_VSCROLL messages such as SB_LINEDOWN are processed, and the scrollbar moves perfectly. The last part is to make the contents of the main window move along with the thumb of the scroll bar, and for me this seems a little difficult task. This is my best attempt:

int dy = -( CurrPos - si.nPos ); RECT rctMainWindowArea = { 0, 0, 1000, main_window.bottom }; ScrollWindowEx( hwndMainWindow, 0, dy,( CONST RECT * ) &rctMainWindowArea,( CONST RECT * ) NULL,( HRGN ) NULL,( LPRECT ) NULL, SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE ); UpdateWindow( hwndMainWindow ); 

It works while I scroll down. When I scroll back again, everything becomes spoiled. I have been looking for this problem for a while, and it seems to me that I need to redraw the lost client area of ​​the main window. However, I have no idea how to do this. I found only examples on the Internet where the text scrolls inside the edit control. I need to scroll through the main window, which has several different basic controls, some BMP graphics, some other graphics, such as TextOut (), RoundRect (), etc.

I need code examples on how to solve my problem or at least a simple explanation (I'm an amateur programmer). Many thanks!

+4
source share
1 answer

Windows does not keep track of how much the window scrolls, so when it asks you to repaint a part of the window, you need to change what you draw, depending on how much scroll you made.

The easiest way to do this is to adjust the start of the window according to the amount of scrolling you did. Your WM_PAINT handler might look something like this. offsetX and offsetY are the distances that you scroll in the X and Y directions, respectively.

 // Adjust coordinates to automatically scroll POINT origin; GetWindowOrgEx(hdc, &origin); SetWindowOrgEx(hdc, origin.x + offsetX, origin.y + offsetY, 0); // Move the paint rectangle into the new coordinate system OffsetRect(&ps.rcPaint, offsetX, offsetY); // Do the painting // Change this to call your painting function CWindow::DoPaint(hdc, ps); // Restore coordinates SetWindowOrgEx(hdc, origin.x, origin.y, 0); 
+4
source

Source: https://habr.com/ru/post/1397927/


All Articles