我想重寫我的winform的「wndProc」方法。所以,我可以爲特定的消息實現我自己的wndproc方法。我能夠成功地做到這一點。但是,現在我遇到了另一個我從未見過的問題。在單個線程上啓動第二個消息循環不是有效的操作
成功編譯之後,我運行程序,彈出以下錯誤消息:「在單個線程上啓動第二個消息循環不是有效的操作,請改用Form.ShowDialog。
保護訪問符下我重寫的方法Winproc傳:
method WndProc(var m:Message); override;
我的方法Winproc傳的定義如下:
method MainForm.WndProc(var m: Message);
const WM_NCLBUTTONDOWN = 161;
const WM_SYSCOMMAND = 274;
const HTCAPTION = 2;
const SC_MOVE = 61456;
begin
if ((m.Msg = WM_SYSCOMMAND) and (m.WParam.ToInt32 = SC_MOVE)) then
begin
exit;
end;
if ((m.Msg = WM_NCLBUTTONDOWN) and (m.WParam.ToInt32 = HTCAPTION)) then
begin
exit;
end;
end;
錯誤被提出是在program.pas文件:
[STAThread]
class method Program.Main(args: array of string);
begin
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ThreadException += OnThreadException;
using lMainForm := new MainForm do
Application.Run(lMainForm); < --------Raised here.
end;
我該怎麼去abo解決它?
嗯,這應該會產生另一個異常,「錯誤創建窗口句柄」。您必須在覆蓋中調用基本方法。發佈異常的堆棧跟蹤如果沒有幫助。 – 2012-01-04 17:18:48
@HansPassant你是對的。我還看到了創建窗口句柄的錯誤。 – ThN 2012-01-04 19:38:14