J
jingtao
Unregistered / Unconfirmed
GUEST, unregistred user!
//fileroject1.dpr<br>program Project1;<br><br>uses<br> Windows,<br> Unit_MainForm;<br><br>{$R *.res}<br><br>Var<br>TheMessage:TMsg;<br><br>begin<br> if not MyCreateWinForm('strServerClassName','strServrerCaption') then halt;<br> while GetMessage(TheMessage,0,0,0) do<br> begin<br> TranslateMessage(TheMessage);<br> DispatchMessage(TheMessage);<br> // sleep(20);<br> end;<br>end.<br><br>//file:<br>unit Unit_MainForm;<br><br>interface<br>uses<br> Windows;<br><br>function MyCreateWinForm(strWindowClass,strWindowCaption:string):Bool;stdcall;<br>implementation<br><br>const<br> WM_CREATE = $0001;<br> WM_DESTROY = $0002;<br> Timer1:integer=1;<br><br>procedure OnFormCreate;forward;<br>procedure OnFormDestroy;forward;<br>procedure OnTimer1;forward;<br>var<br>WinClass: TWndClassA; <br>hWindow: HWND; <br><br>procedure Time1pro(hWnd: Longint; uMsg: UINT; idEvent: UINT; Time: DWORD); stdcall;<br>begin<br>OnTimer1;<br>end;<br>function WindowProc(hWindow: HWnd; Message, wParam, lParam: Integer): Integer; stdcall;<br>begin<br>Result:=0;<br>case Message of<br> WM_Create:<br> begin<br> OnFormCreate;<br> end;<br> WM_DESTROY:<br> begin<br> OnFormDestroy;<br> PostQuitMessage(0);<br> Exit;<br> end;<br> else<br> Result := DefWindowProc(hWindow, Message, wParam, lParam);<br> end;<br>end;<br>function MyCreateWinForm(strWindowClass,strWindowCaption:string):Bool;stdcall;<br>var<br>hFont: Integer;<br>Inst: HINST;<br>begin<br>{ Register Custom WndClass }<br> Result:=False;<br> Inst := hInstance;<br> with WinClass do<br> begin<br> style := CS_CLASSDC or CS_PARENTDC;<br> lpfnWndProc := @WindowProc;<br> hInstance := Inst;<br> hbrBackground := color_btnface + 1;<br> lpszClassname := Pchar(strWindowClass);<br> hIcon := LoadIcon(Inst, 'Mainicon');<br> hCursor := LoadCursor(0, IDC_ARROW);<br> end; { with }<br> if RegisterClass(WinClass)=0 then Exit;<br> hWindow := CreateWindowEx(WS_EX_WINDOWEDGE, Pchar(strWindowClass),Pchar(strWindowCaption),<br> WS_MINIMIZEBOX or WS_SYSMENU or WS_VISIBLE,<br> (GetSystemMetrics(SM_CXSCREEN) - 300) div 2,<br> (GetSystemMetrics(SM_CYSCREEN) - 300) div 2, 300, 330, 0, 0, Inst, nil);<br> if hWindow=0 then Exit;<br><br> SetTimer(hWindow, Timer1, 4000, @Time1pro);{注意这里!!!}<br> UpdateWindow(hWindow);<br> Result:=True;<br>end;<br><br><br>{==============================================================================}<br>procedure OnFormCreate;<br>begin<br>MessageBox(0,'OnFormCreate','',MB_OK);<br>end;<br>procedure OnFormDestroy;<br>begin<br>MessageBox(0,'OnFormDestroy','',MB_OK);<br>end;<br>procedure OnTimer1;<br>begin<br>KillTimer(hWindow,Timer1);<br>MessageBox(0,'OnTimer1','',MB_OK);<br>end;<br>{==============================================================================}<br>end.<br><br><br>如果把SetTimer(hWindow, Timer1, 4000, @Time1pro);{注意这里!!!}<br>这句放在<br>procedure OnFormCreate;<br>begin<br>MessageBox(0,'OnFormCreate','',MB_OK);<br>end;<br>里面,发现OnTimer1;里面的KillTimer(hWindow,Timer1);根本不起作用.为什么???放在<br>WM_Create:却是可以的.