void Dow::Handle::Position (Win::Rect const & rect) { if (!::SetWindowPos (H (), NULL, // insert after (in z-order) rect.Left (), rect.Top (), rect.Width (), rect.Height (), SWP_NOZORDER)) { throw Win::Exception ("Cannot position window"); } }
win::Rect ResizeRect(const win::Rect& rect_dest, int src_width, int src_height, bool stretch, bool center_x, bool center_y) { win::Rect rect = rect_dest; float dest_width = static_cast<float>(rect_dest.Width()); float dest_height = static_cast<float>(rect_dest.Height()); float image_width = static_cast<float>(src_width); float image_Height = static_cast<float>(src_height); // Source < Destination (no need to resize) if ((image_width < dest_width) && (image_Height < dest_height) && !stretch) { rect.right = rect.left + src_width; rect.bottom = rect.top + src_height; if (center_x) rect.Offset(static_cast<int>((image_width - image_width) / 2.0f), 0); if (center_y) rect.Offset(0, static_cast<int>((dest_height - image_Height) / 2.0f)); // Source > Destination (resize) } else { // Calculate aspect ratios float dest_ratio = dest_width / dest_height; float image_ratio = image_width / image_Height; // Width > Height if (image_ratio > dest_ratio) { rect.bottom = rect.top + static_cast<int>(dest_width * (1.0f / image_ratio)); if (center_y) rect.Offset(0, static_cast<int>((dest_height - rect.Height()) / 2.0f)); // Height > Width } else if (image_ratio < dest_ratio) { rect.right = rect.left + static_cast<int>(dest_height * image_ratio); if (center_x) rect.Offset(static_cast<int>((dest_width - rect.Width()) / 2.0f), 0); } } return rect; }
void Dow::Handle::Move (Win::Rect const & rect) { ::MoveWindow (H (), rect.Left (), rect.Top (), rect.Width (), rect.Height (), TRUE); }