????怎么搞定????我在窗体外单击一下,窗体仍然具有焦点?

Refactoring 2002-11-11 06:29:26
还请指教???
...全文
31 25 打赏 收藏 转发到动态 举报
写回复
用AI写文章
25 条回复
切换为时间正序
请发表友善的回复…
发表回复
langer1 2002-11-13
  • 打赏
  • 举报
回复
//-----------------------------------------------------------
可以的,以下得到文件名与图标
procedure WMDropFiles(var message:TMessage);message WM_DropFiles; //拖放文件

procedure TfrmMain.WMDropFiles(var message:tmessage); //拖放文件

var
p:array[0..254] of char;
i ,ii ,I_FileCount:word;
I_Image : Integer;
ObjIco : TIcon;
NewFName: String;
begin
inherited;
FormState(1);

if SideBar.ActiveGroup.Caption ='系统菜单组' then begin
//如果当前图像列表为菜单列表,则退出警告
Application.MessageBox('不能在系统菜单栏里增加程序链接!','链接出错',Mb_IconInFormation);
Exit;
End;
ii :=SideBar.ActiveGroup.Index ;

{$IFDEF WIN32}
I:=dragqueryfile(message.wparam,$ffffffff,nil,0);
{$ELSE}
I:=dragqueryfile(message.wparam,$ffff,nil,0);
{$ENDIF}

I_FileCount:= i-1;
for i:=0 to I_FileCount do //可能拖动的是一组文件
begin
dragqueryfile(message.wparam,i,p,255); //strpas(p)为路径名
//if UserRegFile.IndexOf(StrPas(p))<0 then begin
UserRegFile.Add(SideBar.Groups.Items[ii].Caption +signStr + StrPas(p));
//如果开始不存在,则新增 图像列表 现不管了,想加就加
SideBar.Groups.Items[ii].Items.Add;
NewFName:= StrPas(p);

NewFName :=DirGetFName(NewFName); //读出文件名

SideBar.Groups.Items[ii].Items[SideBar.Groups.Items[ii].ItemCount-1].Caption := NewFName;
//-----------------------加载图片<<------------------------//
ObjIco := TIcon.Create;
ObjIco.Handle:=GetFileIcon(StrPas(p),False);
if ObjIco =nil then exit;
I_Image := BarIco.AddIcon(ObjIco);
SideBar.Groups.Items[ii].Items[SideBar.Groups.Items[ii].ItemCount-1].LargeImage := I_Image;
ObjIco.Free;
//----------------------->>加载图片------------------------//
SideBar.Groups.Items[ii].Items[SideBar.Groups.Items[ii].ItemCount-1].Tag :=TagBase+UserRegFile.Count-1;

//end;

end;
end;
//-------------------------------//
以下为一API函数,运行程序
WinExec可以运行另一Exe文件
以下函数可以运行另一有路径的东东
ShellExecute(0 ,'Open',Pchar(FileName),nil,nil,Sw_Show);
QQ:5176905

NND,给你留言,说留言太长,累!!
zhangchao_7622 2002-11-13
  • 打赏
  • 举报
回复
高人,如何改为C++呢???
Kingron 2002-11-12
  • 打赏
  • 举报
回复
提问提拔要求说清楚:
>>是要你的程序永远有焦点是吗?

如果是这样,可以做到:
设置Application.OnDeActive事件即可!代码如下:
procedure ForceForegroundWindow(hwnd: THandle);
var
hlp: TForm;
begin
hlp := TForm.Create(nil);
try
hlp.BorderStyle := bsNone;
hlp.SetBounds(0, 0, 1, 1);
hlp.FormStyle := fsStayOnTop;
hlp.Show;
mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
SetForegroundWindow(hwnd);
finally
hlp.Free;
end;
end;

然后在Application.OnDeActive中添加代码:
ForceForegroundWindow(Handle)
Test Ok for WinXP。
理想 2002-11-12
  • 打赏
  • 举报
回复

在“Hook Functions”里有个“MouseProc”,用它来试一下,就像屏蔽键盘一样,可以屏蔽鼠标事件。

LRESULT CALLBACK MouseProc(
int nCode, // hook code
WPARAM wParam, // message identifier
LPARAM lParam // mouse coordinates
);
hnxrm 2002-11-12
  • 打赏
  • 举报
回复
搞不懂,这有什么用?是要你的程序永远有焦点是吗?
langer1 2002-11-12
  • 打赏
  • 举报
回复
procedure TForm1.FormCreate(Sender: TObject);
begin
Dragacceptfiles(form1.handle,true);
end;

这是支持文件拖放的程序设置的东东,效果和你的差不多吧,你试试
dext 2002-11-12
  • 打赏
  • 举报
回复
首先,你要的结果是在窗口丢失焦点后,然后再获得焦点。
其次,OnDeactive事件时发生在丢失焦点以前。
解决的方法有两个:
1.限制鼠标不要出你的窗体
2.修改VCL
Kingron 2002-11-12
  • 打赏
  • 举报
回复
我测试是可以的,不过屏幕总是要闪烁一下,你还是用Mouse Hook吧,虽然复杂,但丝好用。
Kingron 2002-11-12
  • 打赏
  • 举报
回复
>>我用的也是XP,但好像KingRom的代码并不能实现。
看看下面的可不可以?
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, AppEvnts, StdCtrls;

type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
AppEvent: TApplicationEvents;
procedure AppEventDeactivate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure ForceForegroundWindow(hwnd: THandle);
var
hlp: TForm;
begin
hlp := TForm.Create(nil);
try
hlp.BorderStyle := bsNone;
hlp.SetBounds(0, 0, 1, 1);
hlp.FormStyle := fsStayOnTop;
hlp.Show;
mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
SetForegroundWindow(hwnd);
finally
hlp.Free;
end;
end;

procedure TForm1.AppEventDeactivate(Sender: TObject);
begin
ForceForegroundWindow(Screen.Forms[0].Handle);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage('TEST');
end;

end.

object Form1: TForm1
Left = 192
Top = 114
Width = 696
Height = 480
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Memo1: TMemo
Left = 15
Top = 10
Width = 501
Height = 286
Lines.Strings = (
'Memo1')
TabOrder = 0
end
object Button1: TButton
Left = 95
Top = 340
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
object AppEvent: TApplicationEvents
OnDeactivate = AppEventDeactivate
Left = 530
Top = 60
end
end
Refactoring 2002-11-12
  • 打赏
  • 举报
回复
其实用鼠标钩子很容易能实现这个功能,只不过,想找找还有其它方法没有罢了
Refactoring 2002-11-12
  • 打赏
  • 举报
回复
我只是想试试能不能实现这个功能而已。

我用的也是XP,但好像KingRom的代码并不能实现。
naughtyboy 2002-11-12
  • 打赏
  • 举报
回复
showmodal
shuyi 2002-11-12
  • 打赏
  • 举报
回复
高!
linlky 2002-11-11
  • 打赏
  • 举报
回复
我个人觉得这种事情很少发生。因为可能是默认了吧。如果要是设置为默认的。

直接按回车健就可以使用BUTTON健。这个问题不会影响你的程序吧。所以就算是

出现点问题也不要太再意了。。。。我也是用DELPHI6的。所以大家是同道中人。

祝你好运!!!!!!!!
Refactoring 2002-11-11
  • 打赏
  • 举报
回复
要什么代码???这是一个问题,我就是想在外边点完后,窗口仍然具有焦点而已
wangjiki1111 2002-11-11
  • 打赏
  • 举报
回复
你的代码?
Refactoring 2002-11-11
  • 打赏
  • 举报
回复
不行啊,看来,这确实是个问题啊,真得没人知道吗?。。。。。。看业大家应该好好研究研究
侠之大者 f 2002-11-11
  • 打赏
  • 举报
回复
看看用SETFOCUS(HWND)将焦点强行移开如何?
Refactoring 2002-11-11
  • 打赏
  • 举报
回复
呵呵,我要的就是出窗体单击,要不然也没什么意思了
理想 2002-11-11
  • 打赏
  • 举报
回复


可以限制鼠标不要出你的窗体啊。

加载更多回复(5)

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧