H
hermit
Unregistered / Unconfirmed
GUEST, unregistred user!
高手请看下面的程序,不加循环延时可以正常退出,加上了就不行,为什么?<br><br>program Project_2;<br><br>uses<br><br> Sysutils,<br> Windows,<br> Messages,<br> ShellApi;<br><br>{$R theIcon.res}<br><br>Const<br> WM_MyCallback = WM_User+1000;<br> TrayIconTip = 'This is the notifyIcon procedure';<br><br>var<br> MainWindow : HWND;<br> IconData : TNotifyIconData;<br><br>procedure DeleteTrayIcon;<br>begin<br> Shell_NotifyIcon(NIM_DELETE,@IconData);<br>end;<br><br>Function WndProc(Window : hWnd; Msg,WParam,LParam : Integer): Integer; StdCall;<br>var i,j,k : integer;<br> Begin<br> Result := 0;<br> Case Msg of<br> wm_NCCreate : Result := 1;<br> wm_Destroy : PostQuitMessage(0);<br><br> wm_MyCallback :<br> Begin<br> MessageBeep(0);<br> // 不加下面的循环,程序可以正常退出,加了则不行,why?<br> for i:=0 to 10000 do<br> begin<br> for j:=0 to 10000 do<br> k:=i+j;<br> end;<br><br> PostMessage(MainWindow,WM_Destroy,0,0);<br> End;<br><br> Else Result := DefWindowProc(MainWindow,Msg,WParam,LParam);<br><br> End;<br>End;<br><br><br>Procedure CreateWindow;<br>Var<br> WC : TWndClass;<br><br>Begin<br> With WC do Begin<br> Style := 0;<br> lpfnWndProc := @WndProc;<br> cbClsExtra := 0;<br> cbWndExtra := 0;<br> hIcon := 0;<br> hCursor := 0;<br> hbrBackground := 0;<br> lpszMenuName := nil;<br> lpszClassName := 'MyTrayIconClass';<br> hInstance := SysInit.hInstance;<br> end;<br> RegisterClass(WC);<br> MainWindow := Windows.CreateWindow('MyTrayIconClass','MyVeryOwnTrayIconWindow',<br> ws_OverlappedWindow,0,0,0,0,0,0,hInstance,nil);<br> ShowWindow(MainWindow,sw_Hide);<br> UpdateWindow(MainWindow);<br><br>End;<br>Procedure AddTrayIcon;<br>Begin<br> With IconData do Begin<br> cbSize := SizeOf(IconData);<br> Wnd := MainWindow;<br> uID := 0;<br> uFlags := nif_Icon Or nif_Message Or nif_Tip;<br> uCallBackMessage := wm_MyCallBack;<br> hIcon := LoadIcon(hInstance,'MYICON');<br> StrCopy(szTip,PChar(TrayIconTip));<br> End;<br> Shell_NotifyIcon(NIM_Add,@IconData);<br>End;<br><br><br>Procedure WinMain;<br> Var Msg : TMsg;<br>Begin<br> CreateWindow;<br> AddTrayIcon;<br> While GetMessage(Msg,0,0,0) do Begin<br> TranslateMessage(Msg);<br> DispatchMessage(Msg);<br><br> End;<br> DeleteTrayIcon;<br> End; // end of RunTrayApplication<br><br><br>begin<br> WinMain;<br><br><br>end.