Draw themed combobox on windows

时光总嘲笑我的痴心妄想 提交于 2019-12-11 02:41:09

问题


I try to emulate the look of a themed noneditable combobox (CBS_DROPDOWNLIST) using DrawThemeBackground. I supply the part CP_READONLY, which apparently draws the background of a themed combobox:

DrawThemeBackground(theme, dc, CP_READONLY, CBRO_NORMAL, &rectangle, nullptr);

However, it does not contain the dropdown arrow. So, I tried to paint the arrow myself the following way:

rectangle.left = rectangle.right - 20;
DrawThemeBackground(theme, dc, CP_DROPDOWNBUTTONRIGHT, CBXSR_NORMAL, &rectangle, nullptr);

But the above draws the arrow centered within the rectangle on a combobox background including the border, so I cannot use this without having a border within the combobox (which itself already has a border). I used theme-explorer to verify that the arrow is always on a background with borders.

In essence, my question is: How can I draw the background and the arrow at the appropriate position to emulate the look of a plain windows combobox?

What I have found out so far:

  • I can specify a clipping rectangle to clip away the aforementioned borders. But this poses the question of determining the exact position rectangle and the clipping rectangle: It seems that I can use GetThemeMargins to determine the margins, but that does not tell me how large the arrow is as a whole.

  • GetThemeBitmap might be useful in determining the exact size of the arrow, but as I read here and confirmed on my machine, using it with TMT_GLYPHDIBDATA does not work as advertised, and I would like to go without any workarounds, if possible.

来源:https://stackoverflow.com/questions/47199120/draw-themed-combobox-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!