示例#1
0
int _init_combo(
		HWND        hwnd, 
		_init_list *list,
		DWORD       val,
		BOOL        or,
		int         bits
	)
{
	int count = 0;
	int item = 0;

	while ( wcslen(list[count].display) )
	{
		SendMessage( hwnd, (UINT)CB_ADDSTRING, 0, (LPARAM)list[count].display );
		if ( !or )
		{
			if ( list[count].val == val )
			{
				item = count;
			}
		} else {
			if ( (bits != -1 ? _bitcount(list[count].val) == bits : TRUE) && 
				 (val & list[count].val) )
			{
				item = count;
			}
		}		
		count++;
	}
	SendMessage( hwnd, CB_SETCURSEL, item, 0 );
	return item;

}
// closest power of 2 above or equal
int _ceil_power2(int value) {
	if (_power2p(value)) return value;
	
	if (value == 1) return 2;
	int j, i = _bitcount(value);
	int res = 1;
	for (j = 0; j < i; j++) res <<= 1;
	return res;
}