3个回答
展开全部
如果已经知道那个窗体的句柄了那就用sendmessage给那个窗口发送WM_CLOSE消息就可以了.
SendMessage(你的句柄, WM_CLOSE, 0, 0);
如果不知道那个窗口的句柄那就要用FindWindow先获得句柄再发送消息.
SendMessage(FindWindow(nil, '你的窗口标题'), WM_CLOSE, 0, 0);
SendMessage(你的句柄, WM_CLOSE, 0, 0);
如果不知道那个窗口的句柄那就要用FindWindow先获得句柄再发送消息.
SendMessage(FindWindow(nil, '你的窗口标题'), WM_CLOSE, 0, 0);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
if IsIconic(self.Handle) then
begin
GetCursorPos(Pt);
Pt:=ScreenToClient(Pt);
end
else
begin
GetWindowRect(Self.Handle,Prect);
Pt.X:=Mouse.CursorPos.X-Prect.Left;
Pt.Y:=Mouse.CursorPos.Y-Prect.Top;
end;
TitleX:=GetSystemMetrics(SM_CXFRAME);
if IsIconic(self.Handle) then
begin
Nrect:=Rect(86,3,106,21);
if PtInRect(Nrect,Pt) then
SendMessage(self.Handle,WM_SYSCOMMAND,SC_RESTORE,MakeLParam(Pt.X,Pt.Y))
else
begin
Nrect:=Rect(108,3,128,21);
if PtInRect(Nrect,Pt) then
SendMessage(Self.Handle,WM_SYSCOMMAND,SC_MAXIMIZE,MakeLParam(Pt.X,Pt.Y))
else
begin
Nrect:=Rect(130,3,150,21);
if PtInRect(Nrect,Pt) then
SendMessage(self.Handle,WM_CLOSE,0,0)
else
DefaultHandler(msg);
end
end;
end
else
begin
Nrect:=Rect(self.Width-105,TitleX,self.Width-85,TitleX+20);
if PtInRect(Nrect,Pt) then
begin
SendMessage(Self.Handle,WM_SYSCOMMAND,SC_MINIMIZE,MakeLParam(Pt.X,Pt.Y));
if IsIconic(Self.Handle) then
DrawTitleMin;
end
else
begin
Nrect:=Rect(self.Width-80,TitleX,self.Width-60,TitleX+20);
if PtInRect(Nrect,Pt) then
begin
if IsZoomed(self.Handle) then
SendMessage(Self.Handle,WM_SYSCOMMAND,SC_RESTORE,MakeLParam(Pt.X,Pt.Y))
else
begin
SendMessage(Self.Handle,WM_SYSCOMMAND,SC_MAXIMIZE,MakeLParam(Pt.X,Pt.Y));
Invalidate;
end;
end
else
begin
Nrect:=Rect(self.Width-55,TitleX,self.Width-35,TitleX+20);
if PtInRect(Nrect,Pt) then
SendMessage(Self.Handle,WM_CLOSE,0,0)
else
begin
if not IsZoomed(self.Handle) then
DefaultHandler(msg);
end;
end;
end;
end;
begin
GetCursorPos(Pt);
Pt:=ScreenToClient(Pt);
end
else
begin
GetWindowRect(Self.Handle,Prect);
Pt.X:=Mouse.CursorPos.X-Prect.Left;
Pt.Y:=Mouse.CursorPos.Y-Prect.Top;
end;
TitleX:=GetSystemMetrics(SM_CXFRAME);
if IsIconic(self.Handle) then
begin
Nrect:=Rect(86,3,106,21);
if PtInRect(Nrect,Pt) then
SendMessage(self.Handle,WM_SYSCOMMAND,SC_RESTORE,MakeLParam(Pt.X,Pt.Y))
else
begin
Nrect:=Rect(108,3,128,21);
if PtInRect(Nrect,Pt) then
SendMessage(Self.Handle,WM_SYSCOMMAND,SC_MAXIMIZE,MakeLParam(Pt.X,Pt.Y))
else
begin
Nrect:=Rect(130,3,150,21);
if PtInRect(Nrect,Pt) then
SendMessage(self.Handle,WM_CLOSE,0,0)
else
DefaultHandler(msg);
end
end;
end
else
begin
Nrect:=Rect(self.Width-105,TitleX,self.Width-85,TitleX+20);
if PtInRect(Nrect,Pt) then
begin
SendMessage(Self.Handle,WM_SYSCOMMAND,SC_MINIMIZE,MakeLParam(Pt.X,Pt.Y));
if IsIconic(Self.Handle) then
DrawTitleMin;
end
else
begin
Nrect:=Rect(self.Width-80,TitleX,self.Width-60,TitleX+20);
if PtInRect(Nrect,Pt) then
begin
if IsZoomed(self.Handle) then
SendMessage(Self.Handle,WM_SYSCOMMAND,SC_RESTORE,MakeLParam(Pt.X,Pt.Y))
else
begin
SendMessage(Self.Handle,WM_SYSCOMMAND,SC_MAXIMIZE,MakeLParam(Pt.X,Pt.Y));
Invalidate;
end;
end
else
begin
Nrect:=Rect(self.Width-55,TitleX,self.Width-35,TitleX+20);
if PtInRect(Nrect,Pt) then
SendMessage(Self.Handle,WM_CLOSE,0,0)
else
begin
if not IsZoomed(self.Handle) then
DefaultHandler(msg);
end;
end;
end;
end;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
procedure TForm1.Button1Click(Sender: TObject);
var
h: HWND;
begin
h:=FindWindow(nil,'百度一下 你就知道 - Microsoft Internet Explorer');
if h<>0 then
SendMessage(h,WM_SYSCOMMAND,SC_CLOSE,0);
end;
var
h: HWND;
begin
h:=FindWindow(nil,'百度一下 你就知道 - Microsoft Internet Explorer');
if h<>0 then
SendMessage(h,WM_SYSCOMMAND,SC_CLOSE,0);
end;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询