Delphi QQ表情的实现

Delphi QQ表情的实现

QQ表情描述
  1. 蓝框
  2. 提示信息
  3. 鼠标在这个表情上面 这个表情才动
  4. 可以增加表情
  5. 表情打包
  6. 单击这个表情插入表情 关闭本窗体
 
主要使用Webbrowsr来实现的
 
--------------------------------------------------------------------------------

//调用过程
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.OleCtrls, SHDocVw, Vcl.StdCtrls,
  Vcl.Menus, Vcl.AppEvnts;

type
  TForm1 = class(TForm)
    Button1: TButton;
    WebBrowser1: TWebBrowser;
     procedure Button1Click(Sender: TObject);
     procedure FormCreate(Sender: TObject);
     procedure WebBrowser1ProgressChange(ASender: TObject; Progress,
      ProgressMax: Integer);
   private
     { Private declarations }
   public
     { Public declarations }
   end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
uses 
    MSHTML,ActiveX, Unit2;


procedure  InsertImage(fileName: string);
var
  s: string;
begin
  s :=Format( '<IMG src="%s">',[fileName]);
( (Form1.WebBrowser1.Document as IHTMLDocument2).selection.createRange as IHtmlTxtRange).pasteHTML(s);

end;


procedure TForm1.Button1Click(Sender: TObject);
var
  frm2:TForm2;
begin
  frm2 :=TForm2.Create( nil); 
  frm2.Left :=Form1.Left +Button1.Left + 2;
  frm2.Top :=Form1.Top -Button1.Top +Button1.Height;
  frm2.ShowModal; //show method
  Caption :=frm2.SelGifPath;

   //插入图片
   if FileExists(frm2.SelGifPath) then
     InsertImage(frm2.SelGifPath);
     (WebBrowser1.Document as IHTMLDocument2).parentWindow.focus; 
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   WebBrowser1.Navigate( 'about:blank');
    if WebBrowser1.Document <> nil then  
      WebBrowser1.OleObject.document.designMode := 'on';

end;

procedure TForm1.WebBrowser1ProgressChange(ASender: TObject; Progress,
  ProgressMax: Integer);
begin
    (WebBrowser1.Document as IHTMLDocument2).parentWindow.focus; 
end;

end.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//实现过程

unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.AppEvnts, Vcl.OleCtrls, SHDocVw,
  Vcl.StdCtrls;

type
  TForm2 = class(TForm)
    ApplicationEvents1: TApplicationEvents;
    WebBrowser1: TWebBrowser;
     procedure FormCreate(Sender: TObject);
     procedure ApplicationEvents1Message( var Msg: tagMSG; var Handled: Boolean);
     procedure WebBrowser1StatusTextChange(ASender: TObject;
       const Text: WideString);
     procedure WebBrowser1DocumentComplete(ASender: TObject;
       const pDisp: IDispatch; const URL: OleVariant);
   private
     { Private declarations }
   public
     { Public declarations }
    SelGifPath:WideString;
    Execute:Boolean;
   end;

var
  Form2: TForm2;
  GifPath:WideString;
implementation
uses ActiveX;
{$R *.dfm}
{
1  WebBrowser1.Navigate一个html网页
2  单击 获得这个GIF的文件路径
       1 获得这个GIF的文件路径
       2 单击这个GIF关闭窗体
其他
  单击这个Gif连接时 禁止新在本Webbrowser中打开

}




procedure TForm2.ApplicationEvents1Message( var Msg: tagMSG;
   var Handled: Boolean);
var
  fileName: string;
begin
  Handled := IsDialogMessage(Webbrowser1.Handle, msg) = True;
   if handled then
   begin               //WM_LBUTTONDOWN
    if (Msg.Message = WM_LBUTTONDOWN)   then
     begin
        fileName :=StringReplace(GifPath, 'file:///', '',[rfReplaceAll]) ;
         if FileExists(fileName) then
         begin
           SelGifPath :=fileName;
           Execute :=True;
         end;
         Close;
     end
    else
   handled := false; //Disable Webbrowser Default PopMenu
   end;
end;

procedure TForm2.FormCreate(Sender: TObject);
var
  path: string;
begin
    BorderStyle :=bsNone;
    Width := 460;
    Height := 240;
//    TransparentColor:=True;
//    TransparentColorValue:=clPurple;
    WebBrowser1.Left := - 2;
    WebBrowser1.Top := 0;

     //WebBrowser1.Align:=alClient;

      //C:\QQ表情框\Win32\Release\Face.html;
     path :=ExtractFilePath(Application.ExeName) + 'face.html';
      if not FileExists(path) then Exit;

     WebBrowser1.Navigate(path);
end;


procedure TForm2.WebBrowser1DocumentComplete(ASender: TObject;
   const pDisp: IDispatch; const URL: OleVariant);
begin
     WebBrowser1.OleObject.Document.Body.style.border := 'none';
     WebBrowser1.OleObject.Document.Body.scroll := 'no';
end;

procedure TForm2.WebBrowser1StatusTextChange(ASender: TObject;
   const Text: WideString);
begin
    GifPath :=Text; //URL 的路径 如 file:///C:/1.gif
    // Caption:=Text; //Test

end;

end.


的属性


1获得单击的GIF路径
2GIF打包
3
的事件


的方法





附件列表

 

转载于:https://www.cnblogs.com/xe2011/p/3149643.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TApplication.OnIdle   当应用程序变为空闲时,OnIdle事件发生。   使用OnIdle事件,可以写一个应用程序空闲时执行特定处理的事件处理程序。当应用程序不处理代码时,称为应用程序空闲。例如,当应用程序等待来自用户的输入时,应用程序为空闲。   TIdleEvent类型是OnIdle事件的类型,它指向一个应用程序空闲时运行的方法。TIdleEvent类型有一个布尔型参数Done,默认时该参数为True。若参数Done为True,当OnIdle事件返回时,调用Windows API WaitMessage函数。只有在应用程序消息队列中出现一个新消息时,WaitMessage函数才放弃对其他应用程序的控制。参数Done为False时,即使应用程序不忙,也不放弃对其他应用程序的控制。   当应用程序转移到空闲状态时,只调用一次OnIdle事件。除非参数Done设置为False,否则不连续调用OnIdle事件。将参数Done设置为False的应用程序,将消耗过多的CPU时间,从而影响整个系统性能。 在delphi中, 当在一个窗口上放置一个ApplicationEvents控件时,Application将会把所有的事件都转寄到ApplicationEvents; 也就是说,ApplicationEvents可以拦截到应用程序的全部事件,包括OnActivate\OnHelp\OnIdle\OnRestore\OnShortCut等等, 甚至可能通过OnMessage事件,在其中截取所有post到应用程序中所有窗口的消息,如WM_PAINT,WM_KEYDOWN, WM_KEYUP等常见的windows消息; 所以当有消息到来的时候就会触发它的OnMessage事件,在OnMessage中监视消息就可以了。 Action的事件有OnExecute和OnUpdate,OnExecute事件在控制被触发时响应,比如说按钮被按下,菜单被按下,而OnUpdate事件是在应用程序空闲时被调用, APPLICATIONEVENTS是用来捕获程序级事件的 ApplicationEvents1Message(var Msg: tagMSG;var Handled: Boolean); {通过 Perform 向窗体发送 消息; OnMessage 收不到} {通过 SendMessage 向窗体发送 消息; OnMessage 收不到} {通过 PostMessage 向窗体发送  消息; OnMessage 可以收到}

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值