新手求教,Delphi实现网络蚂蚁和FlashGet的悬浮窗口
delphi吧
全部回复
仅看楼主
level 3
0oI0IOIl0l 楼主
代码在下面了,通过读代码学习delphi,在网上找到一段代码想运行一下,问题来了,这代码怎么用,要建一个什么文件等等之类的。如果要看相关内容到http://www.360doc.com/content/12/0312/16/7389824_193775471.shtml
求指教
unit DropBin;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ExtCtrls, ActiveX, ComObj;
type
TfrmDropBin = class(TForm, IDropTarget)
private
procedure WMNCHitTest(var Msg:TWMNCHitTest); message WM_NCHITTEST;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
procedure DestroyWnd; override;
procedure DoClose(var Action: TCloseAction); override;
// DragDrop 支持
function DragEnter(const dataObj: IDataObject; grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult; stdcall;
function IDropTarget_DragOver(grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult; stdcall;
function IDropTarget.DragOver = IDropTarget_DragOver; // 解决 IDropTarget.DragOver 与 TForm.DragOver 冲突问题
function DragLeave: HResult; stdcall;
function Drop(const dataObj: IDataObject; grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult; stdcall;
public
constructor Create(AOwner: TComponent); override;
end;
var
frmDropBin: TfrmDropBin;
procedure ShowDropBin(Sender: TMenuItem);
implementation
{$R *.dfm}
type
// 虽然 Delphi 的 Windows 单元定义了 SetLayeredWindowAttributes(); ( external ‘User32.dll‘ )
// 但为了兼容 Win9x, 不能直接调用。
TSetLayeredWindowAttributes = function (Hwnd: THandle; crKey: COLORREF; bAlpha: Byte; dwFlags: DWORD): Boolean; stdcall;
var
User32ModH: HMODULE;
SetLayeredWindowAttributes: TSetLayeredWindowAttributes = nil;
procedure ShowDropBin(Sender: TMenuItem);
begin
if Assigned(frmDropBin) then frmDropBin.Close
else begin
frmDropBin := TfrmDropBin.CreateParented(GetDesktopWindow);
end;
end;
constructor TfrmDropBin.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Width := 32;
Height := 32;
end;
procedure TfrmDropBin.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do begin
Style := WS_POPUP or WS_CLIPSIBLINGS {or WS_BORDER};
ExStyle := WS_EX_TOOLWINDOW or WS_EX_TOPMOST;
end;
end;
procedure TfrmDropBin.CreateWnd;
begin
inherited CreateWnd;
Visible := True;
// 为 2000/XP 创建半透明、穿透效果
if Assigned(SetLayeredWindowAttributes) then begin
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
SetLayeredWindowAttributes(Handle, clWhite, 128, LWA_ALPHA or LWA_COLORKEY);
end;
// 设置为接受拖拽
OleCheck(RegisterDragDrop(Handle, Self));
end;
procedure TfrmDropBin.DestroyWnd;
begin
if HandleAllocated then RevokeDragDrop(Handle);
inherited DestroyWnd;
end;
function TfrmDropBin.DragEnter(const dataObj: IDataObject; grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult; stdcall;
begin
//
// 也可以在此判断是否接受拖拽,修改 dwEffect 可以得到不同的效果 ...
//
dwEffect := DROPEFFECT_COPY;
Result := S_OK;
end;
function TfrmDropBin.IDropTarget_DragOver(grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult; stdcall;
begin
dwEffect := DROPEFFECT_COPY;
Result := S_OK;
end;
function TfrmDropBin.DragLeave: HResult; stdcall;
begin
Result := S_OK;
end;
function TfrmDropBin.Drop(const dataObj: IDataObject; grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult; stdcall;
begin
//
// 处理 dataObj 中包含的拖拽内容 ...
//
dwEffect := DROPEFFECT_NONE;
Result := S_OK;
end;
procedure TfrmDropBin.DoClose(var Action: TCloseAction);
begin
Action := caFree;
frmDropBin := nil;
end;
procedure TfrmDropBin.WMNCHitTest(var Msg:TWMNCHitTest);
begin
// 通过 Client 区拖动窗口
DefaultHandler(Msg);
if Msg.Result = HTCLIENT then
Msg.Result:= HTCAPTION;
end;
initialization
OleInitialize(nil);
// 为兼容 Win9x
User32ModH := GetModuleHandle(‘User32.dll‘);
if User32ModH <> 0 then @SetLayeredWindowAttributes := GetProcAddress(User32ModH, ‘SetLayeredWindowAttributes‘);
finalization
OleUninitialize;
end.
2016年01月22日 03点01分 1
level 3
0oI0IOIl0l 楼主
[泪]没人理
2016年01月22日 09点01分 2
level 3
0oI0IOIl0l 楼主

2016年01月23日 12点01分 3
level 13
代码不怎么样,还在考虑兼容win9x,太陈旧了。
2016年01月26日 02点01分 6
level 13
以楼主的水平,先去看看入门资料更有实际意义
2016年01月26日 02点01分 7
level 5
我记得有专门的插件 可以实现
2016年01月29日 10点01分 8
level 8
[吐舌][吐舌][吐舌]
2016年02月05日 15点02分 9
level 3
0oI0IOIl0l 楼主
经过努力,问题解决了[哈哈]
2016年02月08日 06点02分 10
level 3
0oI0IOIl0l 楼主
2016年02月08日 06点02分 11
level 3
0oI0IOIl0l 楼主
虽然是别人的代码,但自己解决了困难还是很高兴。基础是很重要,但兴趣同样重要。我是初学者,我为自己带盐。
2016年02月08日 06点02分 12
level 3
0oI0IOIl0l 楼主
悬浮窗显示什么就自己设计了,注意是半透明的偶。
2016年02月08日 06点02分 13
1