Scrollbar doesn't work

Well, now I have to add a scroll-bar to a STATIC control that contains other controls with text. I have tried to adapt the code from Microsoft and I broke everything. The scroll-bar is like blocked.
I'll tell you what I want. The content of the STATIC control is re-sized as you re-size the main window. When maximized there is no need to scroll (it should disappear or remain disabled with no thumb-track) but as you stretch the window the scroll-bar should change it range or something and allow you to scroll up and down.

I will put here the messages handling procedure of the STATIC control (it is sub-classed) and bellow the link to my entire project with some screen captures of what do I have now:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
LRESULT CALLBACK hpanel_proc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam){
    SCROLLINFO si;
    int yPos;
    WORD wScrollNotify = 0xFFFF;
    int content_height = 0;
    switch (Message) {
        // Here I am re-sizing my STATIC controls, for more details see the project link
        case WM_SIZE:
            //Resizing control code - it works and I get the total height of the content as
            content_height = 40 + window_props(desc_panel, HEIGHT) + 
                             window_props(title_panel, HEIGHT) + 
                             window_props(desc_panel2, HEIGHT);

            content_height = 40 + window_props(desc_panel, HEIGHT) + 
                                     window_props(title_panel, HEIGHT) + window_props(desc_panel2, HEIGHT);
            si.fMask = SIF_RANGE;
            si.nMin = 0;
            si.nMax = content_height - window_props(head_panel, HEIGHT);
            si.nPage = content_height - (content_height - window_props(head_panel, HEIGHT));
            SetScrollRange(head_panel, SB_CTL, 0, 100, TRUE);
            SetScrollInfo(head_panel, SB_CTL, &si, TRUE);

            UpdateWindow(hWnd);
            return 0;
        break;
        case WM_VSCROLL:
            si.fMask  = SIF_ALL;
            GetScrollInfo(hWnd, SB_VERT, &si);
            yPos = si.nPos;

            switch (LOWORD(wParam)) {
                case SB_TOP:
                    si.nPos = si.nMin;
                break;
                case SB_BOTTOM:
                    si.nPos = si.nMax;
                break;
                case SB_LINEUP:
                    si.nPos -= 1;
                break;
                case SB_LINEDOWN:
                    si.nPos += 1;
                break;
                case SB_PAGEUP:
                    si.nPos -= si.nPage;
                break;
                case SB_PAGEDOWN:
                    si.nPos += si.nPage;
                break;
                case SB_THUMBTRACK:
                    si.nPos = si.nTrackPos;
                break;
                default:
                break;
            }
            si.fMask = SIF_POS;
            SetScrollInfo (hWnd, SB_VERT, &si, TRUE);
            GetScrollInfo (hWnd, SB_VERT, &si);

            if (si.nPos != yPos) {
                ScrollWindow(hWnd, 0, yPos - si.nPos, NULL, NULL);
                UpdateWindow(hWnd);
            }
            return 0;
        break;
        // This doesn't work either but for the moment the problem is not here
        case WM_KEYDOWN:
            switch (wParam) {
                case VK_UP:
                    wScrollNotify = SB_LINEUP;
                break;
                case VK_PRIOR:
                    wScrollNotify = SB_PAGEUP;
                break;
                case VK_NEXT:
                    wScrollNotify = SB_PAGEDOWN;
                break;
                case VK_DOWN:
                    wScrollNotify = SB_LINEDOWN;
                break;
                case VK_HOME:
                    wScrollNotify = SB_TOP;
                break;
                case VK_END:
                    wScrollNotify = SB_BOTTOM;
                break;
            }
            SendMessage(hWnd, WM_VSCROLL, MAKELONG(wScrollNotify, 0), 0L);
            return 0;
        break;
        default:
            return CallWindowProc(orig_hpanel_proc, hWnd, Message, wParam, lParam);
        break;
    }
}


Project code (Mingw + CodeBlocks) : http://www.devimperium.info/ScrollBar.zip
Screenshot: http://www.devimperium.info/screen8.jpg

Thanks in advance for your advice and help!
Last edited on
closed account (DSLq5Di1)
MSDN wrote:
Static controls are child windows used in Microsoft® Windows™-based applications to display text, to draw frames or lines separating other controls, or to display icons. Static controls do not accept user input and do not send notification messages to their parent windows.

Although it is possible to add a scrollbar to a static control, it will not be functional. Look into creating a scrollbar control [1] or for a quick fix, replace your static control with a read-only edit control.

[1] http://msdn.microsoft.com/en-us/library/ms997557
Thanks sloppy9. Can edit controls contain images and other controls, or just text? I am thinking about adding more elements, not only text. If STATIC controls does not support scroll-bars what is WM_VSCROLL for then?
closed account (DSLq5Di1)
I don't see why not, controls are just specialized windows with a set of features tailored to their use. WM_VSCROLL is a window message all windows can handle, though static controls are a special case as they do not accept user input.

That said, I'm not sure what your end goal with this program is, or if it's just a learning excersise, but I think you are going about it the wrong way.

Personally I'd avoid creating many child/nested child windows. Seems like you would be better off with a blank canvas that you can draw text and images on.. this is what the WM_PAINT handler is for. Positional/size changes and scrolling will be trickier to handle, though you could encapsulate drawing elements in a class and pass around a container of them to ease the pain.

Read up on the GDI/GDI+ documentation [1]. A Rich Edit control [2] might be another viable option.

*poke* Andywestken/webJose/<some other windows wizard> may have alternative suggestions too.

[1] http://msdn.microsoft.com/en-us/library/dd145203
[2] http://msdn.microsoft.com/en-us/library/bb787605
Last edited on
Using an EDIT instead of STATIC worked as a piece of cake. The question is: how do I disable the clipping cursor that appears when I activate it?
closed account (DSLq5Di1)
You can handle the WM_SETCUSOR message and set it to an arrow cursor, or perhaps even better, register another window class and use that instead of a control.
Done. I have a little problem now. The control content is not re-drawn correctly when I scroll it. I use UpdateWindow() after ScrollWindow().
Topic archived. No new replies allowed.