delphi开发无界面activex的问题(100分)

  • 主题发起人 主题发起人 weilibox
  • 开始时间 开始时间
W

weilibox

Unregistered / Unconfirmed
GUEST, unregistred user!
我这里有一个问题,需要在jsp页面中调用一个activex控件,这个控件不需要界面,直接执行一些任务,比如打开一个本地文件,不知道delphi能不能编写这样的控件,如果能该怎么做?
 
能 啊!
例如 :ie登陆 login.jsp
如果成功,对外发消息给指定的外部程序!表明哪个USERID登陆成功!
如果 写个小文件,简单了无法!
 
unit MiniShellImpl1;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
shellapi, Registry, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ActiveX, AxCtrls, MiniShellProj1_TLB, StdVcl, StdCtrls;
const wm_login = wm_user + 1000;
C_MainKey = 'zzxTECH';
c_FormName = 'FormName';
C_userID = 'userid';
C_pwd = 'pwd';
type
TMiniShell = class(TActiveForm, IMiniShell)
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
FEvents: IMiniShellEvents;
procedure ActivateEvent(Sender: TObject);
procedure ClickEvent(Sender: TObject);
procedure CreateEvent(Sender: TObject);
procedure DblClickEvent(Sender: TObject);
procedure DeactivateEvent(Sender: TObject);
procedure DestroyEvent(Sender: TObject);
procedure KeyPressEvent(Sender: TObject
var Key: Char);
procedure PaintEvent(Sender: TObject);
protected
{ Protected declarations }
procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage)
override;
procedure EventSinkChanged(const EventSink: IUnknown)
override;
function Get_Active: WordBool
safecall;
function Get_AlignDisabled: WordBool
safecall;
function Get_AutoScroll: WordBool
safecall;
function Get_AutoSize: WordBool
safecall;
function Get_AxBorderStyle: TxActiveFormBorderStyle
safecall;
function Get_Caption: WideString
safecall;
function Get_Color: OLE_COLOR
safecall;
function Get_Cursor: Smallint
safecall;
function Get_DoubleBuffered: WordBool
safecall;
function Get_DropTarget: WordBool
safecall;
function Get_Enabled: WordBool
safecall;
function Get_Font: IFontDisp
safecall;
function Get_HelpFile: WideString
safecall;
function Get_HelpKeyword: WideString
safecall;
function Get_HelpType: TxHelpType
safecall;
function Get_KeyPreview: WordBool
safecall;
function Get_PixelsPerInch: Integer
safecall;
function Get_PrintScale: TxPrintScale
safecall;
function Get_Scaled: WordBool
safecall;
function Get_Visible: WordBool
safecall;
function Get_VisibleDockClientCount: Integer
safecall;
procedure _Set_Font(var Value: IFontDisp)
safecall;
procedure Set_AutoScroll(Value: WordBool)
safecall;
procedure Set_AutoSize(Value: WordBool)
safecall;
procedure Set_AxBorderStyle(Value: TxActiveFormBorderStyle)
safecall;
procedure Set_Caption(const Value: WideString)
safecall;
procedure Set_Color(Value: OLE_COLOR)
safecall;
procedure Set_Cursor(Value: Smallint)
safecall;
procedure Set_DoubleBuffered(Value: WordBool)
safecall;
procedure Set_DropTarget(Value: WordBool)
safecall;
procedure Set_Enabled(Value: WordBool)
safecall;
procedure Set_Font(const Value: IFontDisp)
safecall;
procedure Set_HelpFile(const Value: WideString)
safecall;
procedure Set_HelpKeyword(const Value: WideString)
safecall;
procedure Set_HelpType(Value: TxHelpType)
safecall;
procedure Set_KeyPreview(Value: WordBool)
safecall;
procedure Set_PixelsPerInch(Value: Integer)
safecall;
procedure Set_PrintScale(Value: TxPrintScale)
safecall;
procedure Set_Scaled(Value: WordBool)
safecall;
procedure Set_Visible(Value: WordBool)
safecall;
procedure Set_LGuid(const Value: WideString)
safecall;
procedure Set_LUser(const Value: WideString)
safecall;
procedure Set_SendMessage(Value: Integer)
safecall;
public
{ Public declarations }
FGUID: string;
FUSER: string;
procedure Initialize
override;
end;

implementation

uses ComObj, ComServ;

{$R *.DFM}

{ TMiniShell }

procedure DeleteKey(value: string);
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/' + C_MainKey, true) then
begin
reg.DeleteValue(value);
Reg.DeleteKey(value);

end;
finally
Reg.Free;

end;

end;

function bCheckKey(value: string): boolean;
var
Reg: TRegistry;
begin
result := false;
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/' + C_MainKey, True);

if trim(reg.ReadString(value)) <> '' then result := true;
reg.Free;
end;


procedure SetKey(lsubkey:string;value: string);
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
//声明注册表主键

Reg.RootKey := HKEY_LOCAL_MACHINE;
//打开注册表路径。。。。。。。。

if Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/' + C_MainKey, True) then
begin
/// 打开成功, 写入注册表。。。。
Reg.WriteString(lsubkey,value);
// MyApp 项名
// ParamStr(0) 当前的操作项
//关闭
Reg.CloseKey;
end;
finally
// 释放内存
Reg.Free;

end;
end;


function ReadKey(value: string): string;
var
Reg: TRegistry;
begin
result := '';
Reg := TRegistry.Create;
try
//声明注册表主键

Reg.RootKey := HKEY_LOCAL_MACHINE;
//打开注册表路径。。。。。。。。

if Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/' + C_MainKey, True) then
begin
/// 打开成功, 写入注册表。。。。
result := Reg.ReadString(value);
// MyApp 项名
// ParamStr(0) 当前的操作项
//关闭
Reg.CloseKey;
end;
finally
// 释放内存
Reg.Free;

end;
end;

procedure TMiniShell.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
begin
{ Define property pages here. Property pages are defined by calling
DefinePropertyPage with the class id of the page. For example,
DefinePropertyPage(Class_MiniShellPage)
}
end;

procedure TMiniShell.EventSinkChanged(const EventSink: IUnknown);
begin
FEvents := EventSink as IMiniShellEvents;
inherited EventSinkChanged(EventSink);
end;

procedure TMiniShell.Initialize;
begin
inherited Initialize;
OnActivate := ActivateEvent;
OnClick := ClickEvent;
OnCreate := CreateEvent;
OnDblClick := DblClickEvent;
OnDeactivate := DeactivateEvent;
OnDestroy := DestroyEvent;
OnKeyPress := KeyPressEvent;
OnPaint := PaintEvent;
end;

function TMiniShell.Get_Active: WordBool;
begin
Result := Active;
end;

function TMiniShell.Get_AlignDisabled: WordBool;
begin
Result := AlignDisabled;
end;

function TMiniShell.Get_AutoScroll: WordBool;
begin
Result := AutoScroll;
end;

function TMiniShell.Get_AutoSize: WordBool;
begin
Result := AutoSize;
end;

function TMiniShell.Get_AxBorderStyle: TxActiveFormBorderStyle;
begin
Result := Ord(AxBorderStyle);
end;

function TMiniShell.Get_Caption: WideString;
begin
Result := WideString(Caption);
end;

function TMiniShell.Get_Color: OLE_COLOR;
begin
Result := OLE_COLOR(Color);
end;

function TMiniShell.Get_Cursor: Smallint;
begin
Result := Smallint(Cursor);
end;

function TMiniShell.Get_DoubleBuffered: WordBool;
begin
Result := DoubleBuffered;
end;

function TMiniShell.Get_DropTarget: WordBool;
begin
Result := DropTarget;
end;

function TMiniShell.Get_Enabled: WordBool;
begin
Result := Enabled;
end;

function TMiniShell.Get_Font: IFontDisp;
begin
GetOleFont(Font, Result);
end;

function TMiniShell.Get_HelpFile: WideString;
begin
Result := WideString(HelpFile);
end;

function TMiniShell.Get_HelpKeyword: WideString;
begin
Result := WideString(HelpKeyword);
end;

function TMiniShell.Get_HelpType: TxHelpType;
begin
Result := Ord(HelpType);
end;

function TMiniShell.Get_KeyPreview: WordBool;
begin
Result := KeyPreview;
end;

function TMiniShell.Get_PixelsPerInch: Integer;
begin
Result := PixelsPerInch;
end;

function TMiniShell.Get_PrintScale: TxPrintScale;
begin
Result := Ord(PrintScale);
end;

function TMiniShell.Get_Scaled: WordBool;
begin
Result := Scaled;
end;

function TMiniShell.Get_Visible: WordBool;
begin
Result := Visible;
end;

function TMiniShell.Get_VisibleDockClientCount: Integer;
begin
Result := VisibleDockClientCount;
end;

procedure TMiniShell._Set_Font(var Value: IFontDisp);
begin
SetOleFont(Font, Value);
end;

procedure TMiniShell.ActivateEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnActivate;
end;

procedure TMiniShell.ClickEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnClick;
end;

procedure TMiniShell.CreateEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnCreate;
end;

procedure TMiniShell.DblClickEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnDblClick;
end;

procedure TMiniShell.DeactivateEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnDeactivate;
end;

procedure TMiniShell.DestroyEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnDestroy;
end;

procedure TMiniShell.KeyPressEvent(Sender: TObject
var Key: Char);
var
TempKey: Smallint;
begin
TempKey := Smallint(Key);
if FEvents <> nil then FEvents.OnKeyPress(TempKey);
Key := Char(TempKey);
end;

procedure TMiniShell.PaintEvent(Sender: TObject);
begin
if FEvents <> nil then FEvents.OnPaint;
end;

procedure TMiniShell.Set_AutoScroll(Value: WordBool);
begin
AutoScroll := Value;
end;

procedure TMiniShell.Set_AutoSize(Value: WordBool);
begin
AutoSize := Value;
end;

procedure TMiniShell.Set_AxBorderStyle(Value: TxActiveFormBorderStyle);
begin
AxBorderStyle := TActiveFormBorderStyle(Value);
end;

procedure TMiniShell.Set_Caption(const Value: WideString);
begin
Caption := TCaption(Value);
end;

procedure TMiniShell.Set_Color(Value: OLE_COLOR);
begin
Color := TColor(Value);
end;

procedure TMiniShell.Set_Cursor(Value: Smallint);
begin
Cursor := TCursor(Value);
end;

procedure TMiniShell.Set_DoubleBuffered(Value: WordBool);
begin
DoubleBuffered := Value;
end;

procedure TMiniShell.Set_DropTarget(Value: WordBool);
begin
DropTarget := Value;
end;

procedure TMiniShell.Set_Enabled(Value: WordBool);
begin
Enabled := Value;
end;

procedure TMiniShell.Set_Font(const Value: IFontDisp);
begin
SetOleFont(Font, Value);
end;

procedure TMiniShell.Set_HelpFile(const Value: WideString);
begin
HelpFile := string(Value);
end;

procedure TMiniShell.Set_HelpKeyword(const Value: WideString);
begin
HelpKeyword := string(Value);
end;

procedure TMiniShell.Set_HelpType(Value: TxHelpType);
begin
HelpType := THelpType(Value);
end;

procedure TMiniShell.Set_KeyPreview(Value: WordBool);
begin
KeyPreview := Value;
end;

procedure TMiniShell.Set_PixelsPerInch(Value: Integer);
begin
PixelsPerInch := Value;
end;

procedure TMiniShell.Set_PrintScale(Value: TxPrintScale);
begin
PrintScale := TPrintScale(Value);
end;

procedure TMiniShell.Set_Scaled(Value: WordBool);
begin
Scaled := Value;
end;

procedure TMiniShell.Set_Visible(Value: WordBool);
begin
Visible := Value;
end;

procedure TMiniShell.Button1Click(Sender: TObject);
var S: string;
PATH: PCHAR;
begin
s := ReadKey(c_FormName);
PATH := PCHAR(ExtractFilepath(S));
if not fileexists(s) then
begin
showmessage('文件[' + s + ']不存在...');
exit;
end;
edit1.text := s;
ShellExecute(0, nil, PCHAR(S), 'LBC726DDF47A41CD982F13847A9D7562 SuperUser123040', PATH, sw_ShowNormal);
end;

procedure TMiniShell.Set_LGuid(const Value: WideString);
begin
Fguid := value;
end;

procedure TMiniShell.Set_LUser(const Value: WideString);
var S: string;
PATH: PCHAR;
begin
FUSER := VALUE;

s := ReadKey(c_FormName);
PATH := PCHAR(ExtractFilepath(S));
if not fileexists(s) then
begin
showmessage('文件[' + s + ']不存在...');
exit;
end;
edit1.text := s;
ShellExecute(0, nil, PCHAR(S), 'LBC726DDF47A41CD982F13847A9D7562 SuperUser123040', PATH, sw_ShowNormal);

end;

procedure TMiniShell.Set_SendMessage(Value: Integer);

var s: string;
h: hwnd;
begin
s := ReadKey(c_FormName);
if s = '' then exit;
h := findwindow(0, pchar(s));
if h > 0 then
begin
// memo1.Lines.Add('已经向外发送消息');
setkey(C_userID, inttostr(Value));
postMessage(h, wm_login, 1, 0);
end;
end;


initialization
TActiveFormFactory.Create(
ComServer,
TActiveFormControl,
TMiniShell,
Class_MiniShell,
1,
'',
OLEMISC_SIMPLEFRAME or OLEMISC_ACTSLIKELABEL,
tmApartment);
end.
 
后退
顶部