Ir al contenido


Foto

Hints modificados


  • Por favor identifícate para responder
1 respuesta en este tema

#1 Desart

Desart

    Advanced Member

  • Miembro Platino
  • PipPipPip
  • 715 mensajes
  • LocationEspaña

Escrito 19 mayo 2011 - 12:53

Os Dejo compañeros, el siguiente código, que debéis grabar en un archivo pas con el nombre UHINTPRO.
 
 
  La verdad es que es bastante simple de usar y creo que queda muy curioso.
 
  El código Original es de los Tips De Torry, lo he adaptado apenas y lo he metido en una unidad independeiente.



delphi
  1. [pre]unit UHINTPRO;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs;
  8.  
  9. type
  10.   TGraphicHintWindow = class(THintWindow)
  11.     constructor Create(AOwner: TComponent); override;
  12.   private
  13.     FActivating: Boolean;
  14.   public
  15.     procedure ActivateHint(Rect: TRect; const AHint: string); override;
  16.   protected
  17.     procedure Paint; override;
  18.   published
  19.     property Caption;
  20.   end;
  21.  
  22. var ConstColorFONT,ConstCOLOR1,ConstCOLOR2:TColor;
  23.     ConstTextLeft,ConstHintSpacePlus:Integer;
  24.     ConstImagenBoolean:Boolean;
  25.     ConstFicheroBMP:string;
  26.  
  27. implementation
  28.  
  29.  
  30.  
  31. constructor TGraphicHintWindow.Create(AOwner: TComponent);
  32. begin
  33.   inherited Create(AOwner);
  34.  
  35.   {
  36.   Hier können beliebige Schrift Eigenschaften gesetzt
  37.   werden.
  38.  
  39.   Here you can set custom Font Properties:
  40.   }
  41.     ConstColorFont:=clYellow;
  42.     ConstColor1:=ClBlue;
  43.     ConstColor2:=clYellow;
  44.     ConstTextLeft:=30;
  45.     ConstHintSpacePlus:=200;
  46.     ConstImagenBoolean:=False;
  47.     ConstFicheroBMP:='';
  48.  
  49.   with Canvas.Font do
  50.   begin
  51.     Name := 'Arial';
  52.     Style := Style + [fsBold];
  53.     Size:=10;
  54.     Color :=ConstColorFONT;
  55.   end;
  56. end;
  57.  
  58. procedure TGraphicHintWindow.Paint;
  59. var
  60.   R: TRect;
  61.   bmp: TBitmap;
  62. begin
  63. //  R:=Rect(0,0,350,50);
  64.   R := ClientRect;
  65.   Inc(R.Left, 2);
  66.   Inc(R.Top, 2);
  67.  
  68.   {*******************************************************
  69.   Der folgende Code ist ein Beispiel wie man die Paint
  70.   Prozedur nutzen kann um einen benutzerdefinierten Hint
  71.   zu erzeugen.
  72.  
  73.   The folowing Code ist an example how to create a custom
  74.   Hint Object. :
  75.   }
  76.  
  77.   bmp := TBitmap.Create;
  78.   if ConstImagenBoolean=True then  bmp.LoadfromFile(ConstFicheroBMP);
  79.   with Canvas.Font do
  80.   begin
  81.     Name := 'Arial';
  82.     Style := Style + [fsBold];
  83.     Size:=10;
  84.     Color :=ConstColorFONT;
  85.   end;
  86.  
  87.   with Canvas do      //Dibuja el Rectangulo
  88.   begin
  89.     Brush.Style := bsSolid;
  90.     Brush.Color :=ConstColor2;
  91.     Pen.Color  := clgray;
  92.     Rectangle(0, 0, 30, R.Bottom + 1);
  93.     Draw(2,(R.Bottom div 2) - (bmp.Height div 2), bmp);
  94.   end;
  95.  
  96.   bmp.Free;
  97.   //Beliebige HintFarbe
  98.   //custom Hint Color
  99.   Color :=ConstColor1;
  100.   Canvas.Brush.Style := bsClear;
  101.   Canvas.TextOut(ConstTextLeft, (R.Bottom div 2) - (Canvas.Textheight(Caption) div 2), Caption);  //Posicion del Texto
  102.  
  103.   {********************************************************}
  104. end;
  105.  
  106. procedure TGraphicHintWindow.ActivateHint(Rect: TRect; const AHint: string);
  107. begin
  108.   FActivating := True;
  109.   try
  110.     Caption := AHint;
  111.     //Höhe des Hints setzen setzen
  112.     //Set the "Height" Property of the Hint
  113.     Inc(Rect.Bottom, 14);
  114.     //Breite des Hints setzen
  115.     //Set the "Width" Property of the Hint
  116.     Rect.Right := Rect.Right +ConstHintSpacePlus;
  117.     UpdateBoundsRect(Rect);
  118.     if Rect.Top + Height > Screen.DesktopHeight then
  119.       Rect.Top := Screen.DesktopHeight - Height;
  120.     if Rect.Left + Width > Screen.DesktopWidth then
  121.       Rect.Left := Screen.DesktopWidth - Width;
  122.     if Rect.Left < Screen.DesktopLeft then Rect.Left := Screen.DesktopLeft;
  123.     if Rect.Bottom < Screen.DesktopTop then Rect.Bottom := Screen.DesktopTop;
  124.     SetWindowPos(Handle, HWND_TOPMOST, Rect.Left, Rect.Top, Width, Height,
  125.       SWP_SHOWWINDOW or SWP_NOACTIVATE);
  126.     Invalidate;
  127.   finally
  128.     FActivating := False;
  129.   end;
  130. end;
  131. end.
  132.  
  133.  
  134. {  Usar en la unidad principal de la aplicación
  135.  
  136. Function CambiarHint(ColorFONT,COLOR1,COLOR2:TColor;TextLeft,HintSpacePlus:Integer;ImagenBoolean:Boolean;Fich  eroBMP:string):boolean;
  137. begin      //HAy que usar la unit  UHINTPRO
  138.     ConstColorFont:=ColorFONT;
  139.     ConstColor1:=COLOR1;
  140.     ConstColor2:=COLOR2;
  141.     ConstTextLeft:=TextLeft;
  142.     ConstHintSpacePlus:=HintSpacePlus;
  143.     ConstImagenBoolean:=ImagenBoolean;
  144.     ConstFicheroBMP:=FicheroBMP;
  145.     Result:=True;
  146. end;
  147.  
  148. procedure TForm1.FormCreate(Sender: TObject);
  149. begin
  150.   HintWindowClass := TGraphicHintWindow;
  151.   Application.HintPause:=800;
  152.   Application.HintHidePause:=2000;
  153.   Application.ShowHint := False;
  154.   Application.ShowHint := True;
  155. end;
  156.  
  157. }[/pre]


  • 0

#2 Desart

Desart

    Advanced Member

  • Miembro Platino
  • PipPipPip
  • 715 mensajes
  • LocationEspaña

Escrito 20 mayo 2011 - 04:32

Hola Compañeros os dejo una nueva versión mejorada y cpmentada, ya comentareis.



delphi
  1. //Idea original bajada de: [url=http://www.swissdelphicenter.ch/torry/showcode.php?id=1390]http://www.swissdelphicenter.ch/torry/showcode.php?id=1390[/url]
  2. unit UHINTPRO2;
  3.  
  4. interface
  5.  
  6. uses
  7.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  8.   Dialogs;
  9.  
  10. type
  11.   TGraphicHintWindow = class(THintWindow)
  12.     constructor Create(AOwner: TComponent); override;
  13.   private
  14.     FActivating: Boolean;
  15.   public
  16.     procedure ActivateHint(Rect: TRect; const AHint: string); override;
  17.   protected
  18.     procedure Paint; override;
  19.   published
  20.     property Caption;
  21.   end;
  22.  
  23. var ConstColorFONT,ConstCOLOR1,ConstCOLOR2,ConstHintRPenColor:TColor;
  24.     ConstTextLeft,ConstHintSpacePlus,ConstHintFontSize,ConstHintRPenWith,ConstHintRAcncho:Integer;
  25.     ConstHintFontStyle,ConstHintRStyle:Integer;
  26.     ConstImagenBoolean:Boolean;
  27.     ConstFicheroBMP,ConstHintFontNAme:string;
  28.  
  29. implementation
  30.  
  31.  
  32.  
  33. constructor TGraphicHintWindow.Create(AOwner: TComponent);
  34. begin
  35.   inherited Create(AOwner);
  36.  
  37.   {
  38.   Hier können beliebige Schrift Eigenschaften gesetzt
  39.   werden.
  40.  
  41.   Here you can set custom Font Properties:
  42.   }
  43.     //--General
  44.     ConstColor1:=ClBlue;                      //Color del fondo del Texto
  45.     ConstTextLeft:=32;                        //Espacio a mover el texto desde la Izquierda
  46.     ConstHintSpacePlus:=200;                  //Espacio a dejar de más a la derecha
  47.     ConstImagenBoolean:=False;                //Usar una imagen a la izq
  48.     ConstFicheroBMP:='';                      //Ruta y nombre del archivo BMP a usar ejp. 'C:\Flecha.bmp'
  49.  
  50.     //--Para El Font
  51.     ConstHintFontNAme:='Arial';              //Fuenta a usar en el Hint
  52.     ConstHintFontSize:=10;                    //Tamaño de la fuente a usar
  53.     ConstHintFontStyle:=1;                    //Estilo a usar en la fuente 1 Negrita, 2 Cursiva,
  54.                                               //3 Negrita y cursiva, 0 sin formato
  55.     ConstColorFont:=clYellow;                //Color de la fuente a usar
  56.  
  57.     //Para el Recuadro  a la izq.
  58.     ConstHintRPenWith:=1;                    //Tamaño del Lapiz a usar para pintar el borde del recuadro izq.
  59.     ConstHintRAcncho:=30;                    //Ancho del recuadro izq.
  60.     ConstHintRPenColor:=clGray;              //Color del Lapiz a usar
  61.     ConstHintRStyle:=0;                      //Estilo para el relleno del Recuadro Izq. 0 BsSolid, 1 Bsclear,
  62.                                               //2 BsHorizontal, 3 BsVertical, 4 BsFDiagonal, 5 BsBDiagonal
  63.                                               //6 BsCross y 7 BsDiagCross
  64.     ConstColor2:=clYellow;                    //Color del Relleno del Recuadro Izq.
  65.  
  66.   with Canvas.Font do
  67.   begin
  68.     Name := ConstHintFontNAme;
  69.     if (ConstHintFontStyle>3) or (ConstHintFontStyle<0) then ConstHintFontStyle:=0;
  70.     case ConstHintFontStyle of
  71.       0:Style:=Style +[];
  72.       1:Style:=Style +[fsBold];
  73.       2:Style:=Style +[fsItalic];
  74.       3:Style:=Style +[fsBold,fsItalic];
  75.     end;
  76.     Size:=ConstHintFontSize;
  77.     Color :=ConstColorFONT;
  78.   end;
  79. end;
  80.  
  81. procedure TGraphicHintWindow.Paint;
  82. var
  83.   R: TRect;
  84.   bmp: TBitmap;
  85. begin
  86.   R := ClientRect;
  87.   Inc(R.Left, 2);
  88.   Inc(R.Top, 2);
  89.  
  90.   {*******************************************************
  91.   Der folgende Code ist ein Beispiel wie man die Paint
  92.   Prozedur nutzen kann um einen benutzerdefinierten Hint
  93.   zu erzeugen.
  94.  
  95.   The folowing Code ist an example how to create a custom
  96.   Hint Object. :    }
  97.  
  98.   bmp := TBitmap.Create;
  99.   if ConstImagenBoolean=True then  bmp.LoadfromFile(ConstFicheroBMP);
  100.  
  101.   with Canvas.Font do
  102.   begin
  103.     Name := ConstHintFontNAme;
  104.     if (ConstHintFontStyle>3) or (ConstHintFontStyle<0) then ConstHintFontStyle:=0;
  105.     case ConstHintFontStyle of
  106.       0:Style:=Style +[];
  107.       1:Style:=Style +[fsBold];
  108.       2:Style:=Style +[fsItalic];
  109.       3:Style:=Style +[fsBold,fsItalic];
  110.     end;
  111.     Size  :=ConstHintFontSize;
  112.     Color :=ConstColorFONT;
  113.   end;
  114.  
  115.   with Canvas do      //Dibuja el Rectangulo
  116.   begin
  117.     if (ConstHintRStyle>7) or (ConstHintRStyle<0) then ConstHintRStyle:=0;
  118.     case ConstHintRStyle of
  119.       0:Brush.Style := bsSolid;
  120.       1:Brush.Style := bsClear;
  121.       2:Brush.Style := bsHorizontal;
  122.       3:Brush.Style := bsVertical;
  123.       4:Brush.Style := bsFDiagonal;
  124.       5:Brush.Style := bsBDiagonal;
  125.       6:Brush.Style := bsCross;
  126.       7:Brush.Style := bsDiagCross;
  127.     end;
  128.     Brush.Color :=ConstColor2;
  129.     Pen.Color  :=ConstHintRPenColor;
  130.     Pen.Width  :=ConstHintRPenWith;
  131.     Rectangle(0, 0, ConstHintRAcncho, R.Bottom + 1);
  132.     Draw(2,(R.Bottom div 2) - (bmp.Height div 2), bmp);
  133.   end;
  134.  
  135.   bmp.Free;
  136.   //Beliebige HintFarbe
  137.   //custom Hint Color
  138.   Color :=ConstColor1;
  139.   Canvas.Brush.Style := bsClear;
  140.   Canvas.TextOut(ConstTextLeft, (R.Bottom div 2) - (Canvas.Textheight(Caption) div 2), Caption);  //Posicion del Texto
  141.   {********************************************************}
  142. end;
  143.  
  144. procedure TGraphicHintWindow.ActivateHint(Rect: TRect; const AHint: string);
  145. begin
  146.   FActivating := True;
  147.   try
  148.     Caption := AHint;
  149.     //Höhe des Hints setzen setzen
  150.     //Set the "Height" Property of the Hint
  151.     Inc(Rect.Bottom, 14);
  152.     //Breite des Hints setzen
  153.     //Set the "Width" Property of the Hint
  154.     Rect.Right := Rect.Right +ConstHintSpacePlus;
  155.     UpdateBoundsRect(Rect);
  156.     if Rect.Top + Height > Screen.DesktopHeight then
  157.       Rect.Top := Screen.DesktopHeight - Height;
  158.     if Rect.Left + Width > Screen.DesktopWidth then
  159.       Rect.Left := Screen.DesktopWidth - Width;
  160.     if Rect.Left < Screen.DesktopLeft then Rect.Left := Screen.DesktopLeft;
  161.     if Rect.Bottom < Screen.DesktopTop then Rect.Bottom := Screen.DesktopTop;
  162.     SetWindowPos(Handle, HWND_TOPMOST, Rect.Left, Rect.Top, Width, Height,
  163.       SWP_SHOWWINDOW or SWP_NOACTIVATE);
  164.     Invalidate;
  165.   finally
  166.     FActivating := False;
  167.   end;
  168. end;
  169. end.
  170.  
  171.  
  172. { // Usar en la unidad principal
  173.  
  174. Function CambiarFontHint(FontName:string;FontStyle,FontSize:integer;FontColor:Tcolor):Boolean;
  175. begin    //HAy que usar la unit  UHINTPRO2
  176.     ConstHintFontNAme:=FontName;              //Fuenta a usar en el Hint
  177.     ConstHintFontSize:=FontSize;              //Tamaño de la fuente a usar
  178.     ConstHintFontStyle:=FontStyle;            //Estilo a usar en la fuente 1 Negrita, 2 Cursiva,
  179.                                               //3 Negrita y cursiva, 0 sin formato
  180.     ConstColorFont:=FontColor;                //Color de la fuente a usar
  181.     Result:=True;
  182. end;  //EJEMPLOS CambiarFontHint('magneto',0,12,clWhite); o  CambiarFontHint('Courier',2,10,clYellow);
  183.       //EJEMPLOS 2  CambiarFontHint('Times New Roman',1,12,clWhite); o  CambiarFontHint('Arial',3,11,clNavy);
  184.  
  185.  
  186. Function CambiarCuadHint(CuadStyle,CuadPenWidt,CuadWidth:integer;CuadPenColor,CuadColor:Tcolor):Boolean;
  187. begin    //HAy que usar la unit  UHINTPRO2
  188.     ConstHintRPenWith:=CuadPenWidt;          //Tamaño del Lapiz a usar para pintar el borde del recuadro izq.
  189.     ConstHintRAcncho:=CuadWidth;              //Ancho del recuadro izq.
  190.     ConstHintRPenColor:=CuadPenColor;        //Color del Lapiz a usar
  191.     ConstHintRStyle:=CuadStyle;              //Estilo para el relleno del Recuadro Izq. 0 BsSolid, 1 Bsclear,
  192.                                               //2 BsHorizontal, 3 BsVertical, 4 BsFDiagonal, 5 BsBDiagonal
  193.                                               //6 BsCross y 7 BsDiagCross
  194.     ConstColor2:=CuadColor;                  //Color del Relleno del Recuadro Izq.
  195.     Result:=True;
  196. end;  //EJEMPLOS  CambiarCuadHint(7,2,35,clBlue,clWhite);  o  CambiarCuadHint(7,1,35,clnavy,$000066FF);
  197.  
  198.  
  199. Function CambiarHint(ColorFONT,COLOR1,COLOR2:TColor;TextLeft,HintSpacePlus:Integer;ImagenBoolean:Boolean;FicheroBMP:string):boolean;
  200. //Es comveniente usar esta función antes de usar CambiarFontHint o CambiarCuadHint ya que tine opciones de ambas incluidas
  201. begin      //HAy que usar la unit  UHINTPRO2
  202.     ConstColorFont:=ColorFONT;            //Color de la fuente a usar
  203.                                           //Tambien se encuentra en  CambiarFontHint
  204.     ConstColor1:=COLOR1;                  //Color del Fondo para el texto
  205.     ConstColor2:=COLOR2;                  //Color del Relleno del Recuadro Izq.
  206.                                           //Tambien se encuentra en  CambiarCuadHint
  207.     ConstTextLeft:=TextLeft;              //Espacio a mover el texto desde la Izquierda
  208.     ConstHintSpacePlus:=HintSpacePlus;    //Espacio a dejar de más a la derecha
  209.     ConstImagenBoolean:=ImagenBoolean;    //Usar una imagen a la izq
  210.     ConstFicheroBMP:=FicheroBMP;          //Ruta y nombre del archivo BMP a usar ejp. 'C:\Flecha.bmp'
  211.     Result:=True;
  212. end;  //  EJEMPLO:  CambiarHint(clNavy,clCream,clSilver,35,50,False,'');
  213.  
  214.  
  215. procedure TForm1.FormCreate(Sender: TObject);
  216. begin
  217.   HintWindowClass := TGraphicHintWindow;
  218.   Application.HintPause:=800;
  219.   Application.HintHidePause:=2000;
  220.   Application.ShowHint := False;
  221.   Application.ShowHint := True;
  222. end;
  223.  
  224. }


  • 0




IP.Board spam blocked by CleanTalk.