SCROLLBAR_GetValue()/SCROLLBAR_SetValue() Not the same value?

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • SCROLLBAR_GetValue()/SCROLLBAR_SetValue() Not the same value?

    Hi folks,
    I'm using a scrollbar on a dialog box and I need to initialize it on initialization of the dialog. Code calls SCROLLBAR_SetValue() to do so. Before that call returns, emWin sends a WM_NOTIFICATION_VALUE_CHANGED message to the scrollbar. In that message handler there is code that calls SCROLLBAR_GetValue() and gets a different value than what was just set set.

    I have tried working around this problem by resetting the value on the first entry to the WM_NOTIFICATION_VALUE_CHANGED handler by calling SCROLLBAR_SetValue() but a subsequent call (as in next line of code) to SCROLLBAR_GetValue() returns the previous undesired value. I have checked the manual on this andI cound not spot any clue to what I am doing wrong.


    The code file was created using the GUI builder. The widget is created using:


    static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
    ...
    { SCROLLBAR_CreateIndirect, "Scrollbar", ID_SCROLLBAR_0, 234, 10, 30, 145, 8, 0x0, 0 },

    // USER START (Optionally insert additional widgets)
    // USER END
    };

    During initialization I have added

    sliderHandle = WM_GetDialogItem(pMsg->hWin, ID_SCROLLBAR_0);
    SCROLLBAR_SetNumItems(sliderHandle, 12); // 9 steps from 0-9, 100%-10%
    // (Yes, with PageSize = 3, numItems =12 gives the desired number of slider steps.)
    sliderPos = 10-backlightPCT/10;
    initJustFinished = true;
    SCROLLBAR_SetValue(sliderHandle, sliderPos);
    SCROLLBAR_SetPageSize(sliderHandle, 3);
    SCROLLBAR_SetWidth(sliderHandle, 40);
    // USER END

    In the WM_NOTIFICATION_VALUE_CHANGED message handler I have


    if(initJustFinished) {
    initJustFinished = false;
    SCROLLBAR_SetValue(sliderHandle, sliderPos);
    backlightPCT= SCROLLBAR_GetValue(sliderHandle);
    }
    backlightPCT= SCROLLBAR_GetValue(sliderHandle);
    backlightPCT = 100-(SCROLLBAR_GetValue(sliderHandle))*10;
    setBacklightPercent(backlightPCT);
    sprintf(logBuf, "%d", backlightPCT);
    EDIT_SetText(editHandle, logBuf);


    Other than the initialization issue the scrollbar works well and does what I need. Any help getting the scrollbar initialized to the correct value would be most welcome!

    thanks,
    hank
  • Hello hank,

    Please note that the notification WM_NOTIFICATION_VALUE_CHANGED is sent by the function SCROLLBAR_SetValue() every time the new value is different from the current value. Therefor calling the function SCROLLBAR_SetValue() as a reaction to WM_NOTIFICATION_VALUE_CHANGED is superfluous.

    Unfortunately I am not able to reproduce the problem, since the new value is stored in the widget, before WM_NOTIFICATION_VALUE_CHANGED was sent. The function SCROLLBAR_GetValue() should read exactly the same value which was previously stored.

    Could you please send me small compilable example application showing the problem? I would like to step through it. Thank you.

    Best regards,
    Adrian
  • Hi Adrian,
    Thank you for looking into this. There will be no need to submit code as I have resolved it. While cleaning up all of the code I had tried as a work around, I found that if I call SCROLLBAR_SetValue() after calling SCROLLBAR_SetPageSize() the problem does not happen. It seems that the SCROLLBAR_SetPageSize() API has the side effect of changing the value. I'm not sure if that is intended but that seems to be the way it works.

    If you still want code that demonstrates the issue I can provide the entire code file.

    thanks,
    hank