2
votes

Background:

I have an MFC application with per-monitor DPI awareness mode. When I shift the window to another monitor having another screen scaling, I receive and process the WM_DPICHANGED_AFTERPARENT message.

My owner drawn combo box (with style CBS_OWNERDRAWFIXED) is already filled with items which height I need to update according to the new scaling factor. For this I calculate the new height and call:

SetItemHeight(-1, height); // resizes the closed box
SetItemHeight(0, height); // do this on every item's index from 0 to n

Problem: A combo box not yet opened in former scaling, but opened after having changed the items' height appears wrong. The list opens with the second half of all entries and the lower half is empty. Closing and re-opening it fixes the problem.

I tried workarounds I know from other update problems like Invalidate(), show and hide the combo box, but it doesn't help. Complete re-filling all entries works, but this is slow and leads into flickering (I'm having 12 such boxes in that window).

Any idea? Thank you!

EDIT: The problem obviously only occurs when increasing the items' height (so when moving my window from the 100% to the 200% monitor).

1
This may not be related to your issue, but you are not using the index parameter correctly. According to msdn.microsoft.com/en-us/ie/aa278721(v=vs.100), nIndex must be 0 and the height of all list items will be set.Vlad Feinstein
In the past I had a good experience using SetWindowPos() function (docs.microsoft.com/en-us/windows/win32/api/winuser/…) with SWP_FRAMECHANGED when some internal state of the control needs to be updated.Vlad Feinstein
@VladFeinstein: Thank you! Your first hint in fact isn't related to this issue, but anyway it helps to simplify my code. Your second hint was interesting to try, but unfortunately didn't help :-(( But I found another workaround, see answer below.Nick

1 Answers

0
votes

After desparately trying many attempts I found a workaround which seems to help for all situations which leaded into problems by adding a dummy entry and removing it again:

// Workaround to avoid combo box bug after resizing (esp. enlarging) the entries' height:
int idx = AddString(L"");
DeleteString(idx);