Example #1
0
	void UpdateItemList( const TreeItem& item ) {
		ClearOptionList();
		tjs_uint count = item.Select.size();
		for( tjs_uint i = 0; i < count; i++ ) {
			std::wstring itemstr = item.Select[i].second + std::wstring(L" / ") + item.Select[i].first;
			ComboBox_InsertString( OptionList, -1, itemstr.c_str() );
		}
		ComboBox_SetCurSel( OptionList, item.Value );
		count = count > 12 ? 12 : count;
		if( count <= 0 ) count = 1;
		int itemheight = ComboBox_GetItemHeight(OptionList);
		::SetWindowPos( OptionList, 0, 0, 0, OptionListWidth, itemheight * count + OptionListHeight + 2, SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOREDRAW|SWP_HIDEWINDOW);
		::SetWindowPos( OptionList, 0, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW);
	}
/**
   Adjusting height of dropped list of cbHwnd combobox to fit
   itemsCount items, but not more than MAX_VISIBLE_CB_ITEMS
   ComboBox_SetMinVisible not used because it was introduced in XP.
*/
int adjustDropdownHeight(HWND cbHwnd, unsigned int itemsCount)
{
  COMBOBOXINFO  dbcbinfo;
  RECT          ddRect;
  int           newHeight = 0;

  dbcbinfo.cbSize= sizeof(COMBOBOXINFO);
  ComboBox_GetDroppedControlRect(cbHwnd, &ddRect);
  newHeight= ddRect.bottom - ddRect.top;

  if ( GetComboBoxInfo(cbHwnd, &dbcbinfo) )
  {
    itemsCount= itemsCount < 1 ? 1 : (itemsCount > MAX_VISIBLE_CB_ITEMS
                                      ? MAX_VISIBLE_CB_ITEMS
                                      : itemsCount );

    /* + (itemsCount - 1) - 1 pixel spaces between list items */
    newHeight= itemsCount*ComboBox_GetItemHeight(cbHwnd) + (itemsCount - 1);
    MoveWindow(dbcbinfo.hwndList, ddRect.left, ddRect.top, ddRect.right-ddRect.left, newHeight, FALSE);
  }

  return newHeight;
}