//------------------------------------------------------------------------------------------------------------------------------
// 窗口最小化后焦点回到ListView1
private
{ Private declarations }
procedure AppMsg(var Msg: TagMsg; var Handled: Boolean);
procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
procedure TForm1.AppMsg(var Msg: TagMsg; var Handled: Boolean);
var
r:TRect;item:TListItem;
m: TMessage; mc: TWMSysCommand; //最小化事件
begin
if IsChild(WebBrowser1.Handle, Msg.Hwnd) and
(Msg.Message = WM_LBUTTONDOWN ) and (ListView1.Selected<>nil) then
begin
item:=ListView1.Selected;
r:=Item.DisplayRect(drSelectBounds);
with TCustomListView(Form1.ListView1).Canvas do
begin
Brush.Color:=$00F1C684; //此处设置为红色
FillRect(r);
TextOut(r.Left,r.Top,item.SubItems.Strings[0]);
end;
Self.FocusControl(WebBrowser1); //焦点到WebBrowser1 // Handled:=True; 焦点不变
end;
if Msg.message = WM_SYSCOMMAND then begin //最小化事件后 焦点转移到ListView1起
m.Msg := Msg.message;
m.WParam := Msg.wParam; m.LParam := Msg.lParam;
mc := TWMSysCommand(m);
if mc.CmdType = SC_MINIMIZE then begin
Self.FocusControl(ListView1);
end;
end; inherited; //最小化事件后 焦点转移到ListView1止
end;
procedure TForm1.WMSysCommand(var Msg: TWMSysCommand); //最小化事件后 焦点转移到ListView1
begin
if Msg.CmdType = SC_MINIMIZE then Self.FocusControl(ListView1);
inherited;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := AppMsg;
end;
//------------------------------------------------------------------------------------------------------------------------------
// 窗口不最小化// 先声明
{ Private declarations }
procedure OnAppMessage(var Msg: TMsg; var Handled: Boolean);
procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
// 下面是实现
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := OnAppMessage;
end;
procedure TForm1.OnAppMessage(var Msg: TMsg; var Handled: Boolean);
var
m: TMessage;
mc: TWMSysCommand;
begin
if Msg.message = WM_SYSCOMMAND then begin
m.Msg := Msg.message;
m.WParam := Msg.wParam;
m.LParam := Msg.lParam;
mc := TWMSysCommand(m);
if mc.CmdType = SC_MINIMIZE then begin
Handled := true;
exit;
end;
end;
inherited;
end;
procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
begin
if Msg.CmdType = SC_MINIMIZE then begin
Msg.Result := 1;exit;end;
inherited;
end;