int* IconSet::getIcon(int index) { if (index < 0 || index > numIcons) throw string("Icon index not in range"); BOOL result; //Clear the DC memset(pixels, 0x0, width * height * sizeof(UINT)); memset(mask, 0x0, width * height * sizeof(UINT)); Icon icon = icons[index]; //Paint the icon onto the DC result = DrawIconEx(iconContext, 0, 0, icon.getIcon(), icon.getWidth(), icon.getHeight(), 0, NULL, DI_NORMAL); checkResult(result, "Failed to draw icon into memory"); //Paint the icon onto the DC result = DrawIconEx(maskContext, 0, 0, icon.getIcon(), icon.getWidth(), icon.getHeight(), 0, NULL, DI_MASK); checkResult(result, "Failed to draw icon alpha mask into memory"); //pixels and mask now contain the data int *dimensions = new int[2]; dimensions[0] = icon.getWidth(); dimensions[1] = icon.getHeight(); return dimensions; }
//Loop through all the icons, and figure out the maximum width and height void IconSet::getIconDimensions() { vector<Icon>::const_iterator start = icons.begin(); vector<Icon>::const_iterator end = icons.end(); width = height = 0; while (start != end) { Icon icon = *start; if (icon.getWidth() > width) width = icon.getWidth(); if (icon.getHeight() > height) height = icon.getHeight(); start++; } }