3

当用户通过双击标题栏恢复表单时,我需要处理。我尝试处理 WM_SYSCOMMAND 窗口消息,但这仅在用户通过单击系统菜单中的恢复按钮恢复表单时才有效。

如果这很重要,我正在使用 DevExpress 功能区表单组件。

谢谢。

4

2 回答 2

6

I think you mean double-clicking on the title bar because double clicking on the system menu closes the form.
WM_SYSCOMMAND should work since the sequence of messages when double-clicking on the title bar to restore the form is:

Message posted: hwnd=$004E0820 WM_NCLBUTTONDBLCLK wParam $00000002 lParam $000705D4 Process Project1.exe (2380)
=> Message sent: hwnd=$004E0820 WM_SYSCOMMAND restore cmd requested (-44,-44) Process Project1.exe (2380)
Message sent: hwnd=$004E0820 WM_WINDOWPOSCHANGING wParam $00000000 lParam $0012F4CC Process Project1.exe (2380)
Message sent: hwnd=$004E0820 WM_GETMINMAXINFO wParam $00000000 lParam $0012EF6C Process Project1.exe (2380)
Message sent: hwnd=$004E0820 WM_NCCALCSIZE wParam $00000001 lParam $0012F4A0 Process Project1.exe (2380)
Message sent: hwnd=$004E0820 WM_NCPAINT update region  40040F4B Process Project1.exe (2380)
Message sent: hwnd=$004E0820 WM_ERASEBKGND wParam $31011DCA lParam $00000000 Process Project1.exe (2380)
Message sent: hwnd=$004E0820 WM_WINDOWPOSCHANGED wParam $00000000 lParam $0012F4CC Process Project1.exe (2380)

The problem is that the CmdType const SC_RESTORE2 = 61730 //0xF122 is missing in Windows.pas.

See the working code below:

type
  TForm7 = class(TForm)
  private
    procedure WMSysCommand(var Message: TWMSysCommand); message WM_SYSCOMMAND;
  end;

var
  Form7: TForm7;

implementation

{$R *.dfm}

{ TForm7 }

const
  SC_RESTORE2 = 61730; //0xF122

procedure TForm7.WMSysCommand(var Message: TWMSysCommand);
begin
  case Message.CmdType of
    SC_RESTORE2 : beep;
  end;
  inherited;
end;

Update: reference to SC_RESTORE2 from WM_SYSCOMMAND Notification on MSDN (see the "values in C#" part)

于 2009-09-23T17:59:11.507 回答
2

万一有人在稍后的搜索中发现了这个...

问题不在于 Windows.pas 中缺少任何内容,因为 SC_RESTORE2 不应该存在。正如 Rob Kennedy 所指出的,SC_RESTORE2 值也不在 WinUser.h 中。问题是 François 的示例代码(可能是 James 的代码)无法按位进行,而 wParam (Message.CmdType) 则为 $FFF0。这在 François 的更新链接中进行了描述,并且在“C# 中的值”社区内容中也有说明,其中甚至说不要使用 SC_RESTORE2。请注意 SC_RESTORE2 和 $FFF0 = SC_RESTORE。

于 2010-08-12T21:22:56.493 回答