سؤال

I'm currently writing a windows application using the U++ IDE. One window that is used for data entry contains more fields to be displayed than can be fit into a single screen, so I wanted to add a scrollbar to my window. So far, so good, I looked up the ScrollBar example on the U++ page and tried to implement it in my application. My problem is - it just doesn't scroll. I suspect that it has to do with my application having multiple windows, but I'm not sure. Here's how my application is structured:

GUI_APP_MAIN {
    MainWindow app;
    ...
    app.Run();
}

struct MainWindow : TopWindow {
    PatientFrame dlg;
    ...
    // Opens window that displays a patient overview
    void new_patient() {
        ...
        dlg.Execute();
}

    ...

struct PatientFrame : TopWindow {
    ProcessFrame proc;
    ...
    // Opens the window that should have a scrollbar
    void new_process() {
        ...
       proc.Execute();
    }
}

struct ProcessFrame : TopWindow {
    ...
    // Nearly 1:1 from the example
    ScrollBar sb;

    virtual void Layout() {
        sb.SetPage(GetSize().cy);
    }

    virtual void MouseWheel(Point, int zdelta, dword) {
        sb.Wheel(zdelta);
    }

    bool Key(dword key, int) {
       return sb.VertKey(key);
    }

    // n is the number of entryfields I have, each entryfield is 21 pixels high
    void SetCount(int n) {
        sb.SetTotal(n * 21);
    }

    void Scroll() {
        Refresh();
    }

    void buildList() {
        // Constructs the contents of the window
        ...
        // Sets the size for the scrollbar
        SetCount(count);
    }

    ...

    typedef ProcessFrame CLASSNAME;

    ProcessFrame() {
        SetRect(0, 0, 720, 435);
        Title("Process Frame").Sizeable().Zoomable();
        ...
        AddFrame(sb);
        sb.WhenScroll = THISBACK(Scroll);
        sb.SetLine(21);
    }
}

Now the scrollbar itself displays just fine. Also its size seems to be set correctly, since when I resize the window to be smaller, the scrollbar adjusts itself, same thing when I resize it bigger. I also tried playing around with the size of one line, again, the scrollbar adjusts just fine. The only problem is, it does not actually scroll the view area.

Any help would be appreciated.

هل كانت مفيدة؟

المحلول

You seemingly skipped the part where you actually read the scrollbar (this happens in Draw at the original example). The scrollbar doesn't adjust anything by itself, the example did shift the digits actually drawn depending on its position. I haven't got much experience with U++, but I guess you need to extend the scrollbar's callback to adjust the widgets' positions before Refresh.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top