library remotesim; {%File 'mainpanel.dat'} uses Windows, Messages, classes, controls, stdctrls, sysutils, forms, module, internal, Unit1 in 'Unit1.pas' {RemoteSim1}; const cMenuEntryCaption = '&RemoteSIM'; cMenuEntryItem1Caption = '&Start server'; cMenuEntryID1 = 40001; cMenuEntryItem2Caption = ''; cMenuEntryID2 = 40002; cMenuEntryItem3Caption = 'Show &dialog'; cMenuEntryID3 = 40003; cMenuEntryItem4Caption = '&Start server'; cMenuEntryID4 = 40004; var ImportTable: MODULE_IMPORT; Linkage: MODULE_LINKAGE; OldWndProc: TFarProc; procedure ModuleInit; stdcall; begin end; procedure ModuleDeinit; stdcall; begin end; function FSimWindowProc(Wnd: HWND; uMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; procedure AddMenu; var I: Integer; Menu, MyMenu: HMENU; Buffer: array [0..128] of Char; begin Menu := GetMenu(Wnd); if Menu <> 0 then begin // Look for our menu entry in the main menu. I := 0; while I < GetMenuItemCount(Menu) do begin GetMenuString(Menu, I, Buffer, SizeOf(Buffer), MF_BYPOSITION); if Buffer = cMenuEntryCaption then // It is already here, we do not need to add it again Break; Inc(I); end; if I < GetMenuItemCount(Menu) then // It is already here, we do not need to add it again Exit; {* Create new menu. NOTE: It seems that this will be * reached more times, so we cannot save the handle, because * in such case it could be destroyed and we will not have * any access to it in the simulator. *} MyMenu := CreateMenu; AppendMenu(MyMenu, MF_STRING or MF_ENABLED, cMenuEntryID1, cMenuEntryItem1Caption); AppendMenu(MyMenu, MF_SEPARATOR or MF_ENABLED, cMenuEntryID2, cMenuEntryItem2Caption); AppendMenu(MyMenu, MF_STRING or MF_ENABLED, cMenuEntryID3, cMenuEntryItem3Caption); AppendMenu(Menu, MF_STRING or MF_POPUP, UINT(MyMenu), cMenuEntryCaption); end; end; procedure DoMenu1; begin remotesim1.re1.Clear; remotesim1.timer1.enabled:=true; remotesim1.udps.Active:=true; remotesim1.udpfgc.Active:=true; end; procedure DoMenu2; begin remotesim1.timer1.enabled:=false; status:=0; end; procedure DoMenu3; begin remotesim1.Show; end; begin case uMsg of WM_NCPAINT: AddMenu; WM_COMMAND: begin if LOWORD(wParam) = cMenuEntryID1 then begin DoMenu1; Result := 0; Exit; end; if LOWORD(wParam) = cMenuEntryID3 then begin DoMenu3; Result := 0; Exit; end; end; end; Result := CallWindowProc(OldWndProc, Wnd, uMsg, wParam, lParam); end; procedure SubClassFlightSim; var HFSimWindow: HWND; begin HFSimWindow := FindWindow('FS98MAIN', nil); OldWndProc := TFarProc(SetWindowLong(HFSimWindow, GWL_WNDPROC, Longint(@FSimWindowProc))); end; exports Linkage, ImportTable; begin Linkage.ModuleInit := @ModuleInit; Linkage.ModuleDeinit := @ModuleDeinit; Linkage.ModuleVersion := $0900; // FS2004 version (use 0x0800 for FS2002) SubClassFlightSim; remotesim1:=Tremotesim1.Create(nil); remotesim1.Hide; end.