Exferia/Exferia_Formularios/Exferia_Formularios/PE_Esperando_BarraProgreso.cs

215 lines
6.3 KiB
C#

using Exferia_Aplicacion.Visualizacion;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Exferia_Formularios
{
public partial class PE_Esperando_BarraProgreso : Form
{
#region Librerias Externas
[DllImport("dwmapi.dll")]
public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
[DllImport("dwmapi.dll")]
public static extern int DwmIsCompositionEnabled(ref int pfEnabled);
[DllImport("dwmapi.dll")]
public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
#endregion
#region Propiedades publicas
public Color PE_Esperando_BarraProgreso_ColorTituloyBordes
{
set
{
lbl_Titulo.BackColor = value;
pnl_Titulo.BackColor = value;
pnl_BordeDerecho.BackColor = value;
pnl_BordeInferior.BackColor = value;
pnl_BordeIzquierdo.BackColor = value;
lbl_Mensaje.Font = Fuentes.G_FONT_TEXTOS;
}
get
{
return lbl_Titulo.BackColor;
}
}
public int PE_Esperando_BarraProgreso_Total
{
set
{
ex_pgb_Espera.Exferia_BarraProgreso_Total = value;
}
get
{
return ex_pgb_Espera.Exferia_BarraProgreso_Total;
}
}
public int PE_Esperando_BarraProgreso_Actualizar
{
set
{
ex_pgb_Espera.Exferia_BarraProgreso_Actualizar = value;
}
}
public string PE_Esperando_BarraProgreso_Mensaje
{
set
{
lbl_Mensaje.Text = value;
}
get
{
return lbl_Mensaje.Text;
}
}
#endregion
#region Constructores
public PE_Esperando_BarraProgreso()
{
InitializeComponent();
Repintar.Empezar(this);
}
public PE_Esperando_BarraProgreso(string _str_Mensaje)
{
InitializeComponent();
Repintar.Empezar(this);
//Carga Datos ..............................
lbl_Mensaje.Text = _str_Mensaje;
}
public PE_Esperando_BarraProgreso(string _str_Mensaje, string _str_Titulo)
{
InitializeComponent();
Repintar.Empezar(this);
//Carga Datos ..............................
lbl_Mensaje.Text = _str_Mensaje;
if (_str_Titulo.Trim().Length > 0)
{
lbl_Titulo.Text = _str_Titulo;
}
}
#endregion
#region Control Grafico de la Pantalla
protected override void WndProc(ref Message m)
{
//Sombra de la pantalla ..................................................
if (m.Msg == WM_NCPAINT)// box shadow
{
if (g_bol_HabilitarSombra)
{
var v = 2;
DwmSetWindowAttribute(Handle, 2, ref v, 4);
MARGINS margins = new MARGINS()
{
bottomHeight = 1,
leftWidth = 1,
rightWidth = 1,
topHeight = 1
};
DwmExtendFrameIntoClientArea(Handle, ref margins);
}
}
base.WndProc(ref m);
if (m.Msg == WM_NCHITTEST && (int)m.Result == HTCLIENT) // drag the form
m.Result = (IntPtr)HTCAPTION;
}
private void PE_Esperando_BarraProgreso_Resize(object sender, EventArgs e)
{
pnl_BordeIzquierdo.Size = new Size(2, Height - 3);
pnl_BordeDerecho.Location = new Point(Width - 3, pnl_BordeDerecho.Location.Y);
pnl_BordeDerecho.Size = new Size(2, Height - 3);
pnl_BordeInferior.Location = new Point(pnl_BordeInferior.Location.X, Height - 3);
pnl_BordeInferior.Size = new Size(Width - 4, 2);
pnl_Titulo.Size = new Size(Width - 4, pnl_Titulo.Height);
}
#endregion
#region Crear Sombra de la pantalla
[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
int nLeftRect, // x-coordinate of upper-left corner
int nTopRect, // y-coordinate of upper-left corner
int nRightRect, // x-coordinate of lower-right corner
int nBottomRect, // y-coordinate of lower-right corner
int nWidthEllipse, // height of ellipse
int nHeightEllipse // width of ellipse
);
private bool g_bol_HabilitarSombra; // variables for box shadow
private const int CS_DROPSHADOW = 0x00020000;
private const int WM_NCPAINT = 0x0085;
private const int WM_ACTIVATEAPP = 0x001C;
public struct MARGINS // struct for box shadow
{
public int leftWidth;
public int rightWidth;
public int topHeight;
public int bottomHeight;
}
private const int WM_NCHITTEST = 0x84; // variables for dragging the form
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;
protected override CreateParams CreateParams
{
get
{
g_bol_HabilitarSombra = CheckAeroEnabled();
CreateParams cp = base.CreateParams;
if (!g_bol_HabilitarSombra)
cp.ClassStyle |= CS_DROPSHADOW;
return cp;
}
}
private bool CheckAeroEnabled()
{
if (Environment.OSVersion.Version.Major >= 6)
{
int enabled = 0;
DwmIsCompositionEnabled(ref enabled);
return (enabled == 1) ? true : false;
}
return false;
}
#endregion
}
}