请熟悉shell编程的朋友进来帮帮忙,分不是问题,Up者有分 (200分)

  • 主题发起人 学VC用VB
  • 开始时间

学VC用VB

Unregistered / Unconfirmed
GUEST, unregistred user!
我做了一个IE工具栏,但是目在两个问题

1,在工具栏中有一个按纽,点击后出现一个上下文菜单,如果新打开的IE就没有问题,但是如果是连接中打开的新窗口,那么这时再点击按纽就不会出现上下文菜单,请问如何解决。

2,同上相反,工具栏中另一个按纽,点击后打开一个窗体,并且只能打开一个,如果IE是通过连接打开的窗口,那么没问题,如果是新打开的窗口,那么我点那个按纽就会再打开一个窗体,但我只想无论开多少个IE、按多少下按纽,只要我要打开的那个窗体存在就不要再打开

不知道我有没有说清楚,

 
自已顶一下
 
关于第二个问题,你可先设定好本窗体的句栟名称,

然后再创建时查找一下所有可见窗体的句栟,有的话就显示出来,否则创建它
你试试看???
function aa(s:string):boolean;
var
hCurrentWindow: HWnd;
szText: array[0..254] of char;
begin
result:=false;
hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);
while hCurrentWindow <> 0 do
begin
if iswindowvisible(hCurrentWindow) then
begin
if GetWindowText(hCurrentWindow, @szText, 255)>0 then
if s =StrPas(@szText) then
result:=true;
end;
hCurrentWindow:=GetWindow(hCurrentWindow, GW_HWNDNEXT);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if aa then
// 创建窗体
//显示窗体
end;
 
我用findwindow取窗体名柄,但是没用,窗体没创建就已经存在句柄了
 
我测试了你的代码,结果编译时通过,但运行后报错,内存地址为只读
 
哦,听你这么说我又试了一下
全部代码如下,测试没有问题
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
fcTreeView1: TfcTreeView;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function aa(s: string): boolean;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.aa(s: string): boolean;
var
hCurrentWindow: HWnd;
szText: array[0..254] of char;
begin
result := false;
hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);
while hCurrentWindow <> 0 do
begin
if iswindowvisible(hCurrentWindow) then
begin
if GetWindowText(hCurrentWindow, @szText, 255) > 0 then
if s = StrPas(@szText) then
result := true;
end;
hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if aa('动态生成代码') then
MessageBox(GetActiveWindow(), '找到了!!','警告', MB_OK + MB_ICONWARNING);
// 创建窗体
//显示窗体
end;
 
谢谢你,第二个问题解决,请问第一个怎么做?
 
噢,,还是不行, 在应用程序中,你的办法可行,但到了com组件中就不行了,找是可以找到,但是开另一个窗体又是新的了
 
测试了一下,在ie工具栏中,你的代码只能取到当前IE窗口的windowText跟我的程序的text
 
我想可能是因为Com组件已经不是一个独立的程序了,而是嵌套在IE中的一个控件,所以会出现以上情况,有劳app2001再想想办法
 
怎么没人帮我了啊?
 
急啊!![:(]
 
呵呵,看到UP有分,那我来凑上一份,别忘了给我分哦
 
顶部