16,748
社区成员
发帖
与我相关
我的任务
分享
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
if Msg.message = wm_LBUTTONDOWN then
if (form2 <> nil) and (IsChild(Form2.Handle, msg.hwnd)
or (form2.Handle = msg.hwnd)) then
begin
Caption := 'a';
end;
end;
procedure TCustomForm.WndProc(var Message: TMessage);
var
FocusHandle: HWND;
SaveIndex: Integer;
MenuItem: TMenuItem;
Canvas: TCanvas;
DC: HDC;
begin
with Message do
case Msg of
WM_ACTIVATE, WM_SETFOCUS, WM_KILLFOCUS:
begin
if not FocusMessages then Exit;
if (Msg = WM_SETFOCUS) and not (csDesigning in ComponentState) then
begin
FocusHandle := 0;
if FormStyle = fsMDIForm then
begin
if ActiveMDIChild <> nil then FocusHandle := ActiveMDIChild.Handle;
end
else if (FActiveControl <> nil) and (FActiveControl <> Self) then
FocusHandle := FActiveControl.Handle;
if FocusHandle <> 0 then
begin
Windows.SetFocus(FocusHandle);
Exit;
end;
end;
end;
CM_EXIT:
if HostDockSite <> nil then DeActivate;
CM_ENTER:
if HostDockSite <> nil then Activate;
WM_WINDOWPOSCHANGING:
if ([csLoading, csDesigning] * ComponentState = [csLoading]) then
begin
if (Position in [poDefault, poDefaultPosOnly]) and
(WindowState <> wsMaximized) then
with PWindowPos(Message.lParam)^ do flags := flags or SWP_NOMOVE;
if (Position in [poDefault, poDefaultSizeOnly]) and
(BorderStyle in [bsSizeable, bsSizeToolWin]) then
with PWindowPos(Message.lParam)^ do flags := flags or SWP_NOSIZE;
end;
WM_DRAWITEM:
with PDrawItemStruct(Message.LParam)^ do
if (CtlType = ODT_MENU) and Assigned(Menu) then
begin
MenuItem := Menu.FindItem(itemID, fkCommand);
if MenuItem <> nil then
begin
Canvas := TControlCanvas.Create;
with Canvas do
try
SaveIndex := SaveDC(hDC);
try
Handle := hDC;
Font := Screen.MenuFont;
Menus.DrawMenuItem(MenuItem, Canvas, rcItem,
TOwnerDrawState(LongRec(itemState).Lo));
finally
Handle := 0;
RestoreDC(hDC, SaveIndex)
end;
finally
Free;
end;
Exit;
end;
end;
WM_MEASUREITEM:
with PMeasureItemStruct(Message.LParam)^ do
if (CtlType = ODT_MENU) and Assigned(Menu) then
begin
MenuItem := Menu.FindItem(itemID, fkCommand);
if MenuItem <> nil then
begin
DC := GetWindowDC(Handle);
try
Canvas := TControlCanvas.Create;
with Canvas do
try
SaveIndex := SaveDC(DC);
try
Handle := DC;
Font := Screen.MenuFont;
TMenuItemAccess(MenuItem).MeasureItem(Canvas,
Integer(itemWidth), Integer(itemHeight));
finally
Handle := 0;
RestoreDC(DC, SaveIndex);
end;
finally
Canvas.Free;
end;
finally
ReleaseDC(Handle, DC);
end;
Exit;
end;
end;
else if Message.Msg = RM_TaskbarCreated then
begin
Perform(CM_WININICHANGE, 0, 0);
Perform(CM_SYSCOLORCHANGE, 0, 0);
Perform(CM_SYSFONTCHANGED, 0, 0);
Perform(CM_PARENTCOLORCHANGED, 0, 0);
Perform(CM_PARENTFONTCHANGED, 0, 0);
Perform(CM_PARENTBIDIMODECHANGED, 0, 0);
end;
end;
inherited WndProc(Message);
end;