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
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