这是我给人编的,是针对网吧管理软件在上机时要求输入人员的姓名、性别、年龄,证件号等麻烦的问题,对你的问题完全可以解决。<br>如果要修改的窗口名是已知的情况下,可直接用 FindWindow(nil,'窗口名') 获取该窗口的句柄,然后用 EnumChildWindows 列出所有 Edit,和 TRadioButton 的信息,包括该控件的顺序,也就是 EnumChildWindows枚举的次序。保存起来,其中位置是最主要的。我保存在 ini 中。如查要修改 B 程序中的 Edit 时,只要再一次枚举该窗口,通过判断 次序就可发送 WM_GETTEXT 的消息。添加Edit 的文本,具体源码如下:<br>(现在已有了新版本,你的程序可不用 dll,HookAPI,有疑难可加我 QQ:178718468,有全部源码);<br><br><br>unit Main;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, WinSkinStore, WinSkinData, StdCtrls, Buttons, ComCtrls, ExtCtrls,<br> CheckLst, ShellAPI, Menus, IniFiles, HookConst;<br>const UserFile = 'ufd.ini';<br>type<br> TEditIndexs = record<br> NameIndex: integer;<br> SexManIndex: integer;<br> SexWomanIndex: integer;<br> AgeIndex: integer;<br> PaperIndex: integer;<br> end;<br><br>type<br> PFindWindowStruct = ^TFindWindowStruct;<br> TFindWindowStruct = record<br> Caption: string;<br> ClassName: string;<br> WindowHandle: THandle;<br> end;<br><br>type<br> TMainForm = class(TForm)<br> PageControl1: TPageControl;<br> Panel1: TPanel;<br> TabSheet1: TTabSheet;<br> TabSheet2: TTabSheet;<br> btnExit: TBitBtn;<br> btnHide: TBitBtn;<br> GroupBox1: TGroupBox;<br> Label1: TLabel;<br> Label2: TLabel;<br> edtName: TEdit;<br> edtPaper: TEdit;<br> Label3: TLabel;<br> edtAge: TEdit;<br> UpDown1: TUpDown;<br> rbtnMan: TRadioButton;<br> rbtnWoman: TRadioButton;<br> Label4: TLabel;<br> btnSend: TBitBtn;<br> btnSave: TBitBtn;<br> btnDelete: TBitBtn;<br> TabSheet3: TTabSheet;<br> lbxSearch: TListBox;<br> Panel2: TPanel;<br> btnSearchProc: TButton;<br> btnSelected: TButton;<br> Label5: TLabel;<br> lblWinCount: TLabel;<br> TabSheet4: TTabSheet;<br> Panel3: TPanel;<br> btnSearchFlag: TButton;<br> btnClear: TButton;<br> pnlSelectedWin: TPanel;<br> lvSearchFlag: TListView;<br> ppmSetFlag: TPopupMenu;<br> N1: TMenuItem;<br> N2: TMenuItem;<br> N3: TMenuItem;<br> N4: TMenuItem;<br> N5: TMenuItem;<br> lvUserList: TListView;<br> SkinData1: TSkinData;<br> Panel4: TPanel;<br> Panel6: TPanel;<br> Label11: TLabel;<br> edtWindowName: TEdit;<br> Panel7: TPanel;<br> TabSheet5: TTabSheet;<br> Panel5: TPanel;<br> Label13: TLabel;<br> Label12: TLabel;<br> Label14: TLabel;<br> Label15: TLabel;<br> Label16: TLabel;<br> Label17: TLabel;<br> Label6: TLabel;<br> Label7: TLabel;<br> Label8: TLabel;<br> Label9: TLabel;<br> Label10: TLabel;<br> edtNameIndex: TEdit;<br> edtManIndex: TEdit;<br> edtWomanIndex: TEdit;<br> edtAgeIndex: TEdit;<br> edtPaperIndex: TEdit;<br> UpDown2: TUpDown;<br> UpDown3: TUpDown;<br> UpDown4: TUpDown;<br> UpDown5: TUpDown;<br> UpDown6: TUpDown;<br> btnSaveParam: TBitBtn;<br> chbxAutoPopup: TCheckBox;<br> chbxAutoInput: TCheckBox;<br> Label18: TLabel;<br> Edit1: TEdit;<br> Label19: TLabel;<br> Edit2: TEdit;<br> Label20: TLabel;<br> Edit3: TEdit;<br> UpDown7: TUpDown;<br> procedure btnExitClick(Sender: TObject);<br> procedure btnSearchProcClick(Sender: TObject);<br> procedure btnSelectedClick(Sender: TObject);<br> procedure btnSearchFlagClick(Sender: TObject);<br> procedure btnClearClick(Sender: TObject);<br> procedure N1Click(Sender: TObject);<br> procedure btnSendClick(Sender: TObject);<br> procedure FormCreate(Sender: TObject);<br> procedure FormDestroy(Sender: TObject);<br> procedure lvUserListClick(Sender: TObject);<br> procedure btnSaveClick(Sender: TObject);<br> procedure btnDeleteClick(Sender: TObject);<br> procedure btnSaveParamClick(Sender: TObject);<br> procedure lvUserListDblClick(Sender: TObject);<br> procedure btnHideClick(Sender: TObject);<br> procedure chbxAutoPopupClick(Sender: TObject);<br> procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> private<br> FEditIndexs: TEditIndexs;<br> { Private declarations }<br> function GetEditIndexs: TEditIndexs;<br> public<br> procedure WndProc(var Messages: TMessage); override;<br> published<br> procedure ListBoxAddWidth(AListBox: TListBox);<br> procedure ListControls(Awnd: string);<br> procedure AddFlag(AClass, AValue: string);<br> function SendData(WindowName: string): Boolean;<br> procedure SetValues(AListItem: TListItem);<br> property EditIndexs: TEditIndexs read GetEditIndexs;<br> procedure ReadData;<br> procedure GetUserList(var AStringList: TStringList);<br> procedure WriteData;<br> { Public declarations }<br> end;<br><br>var<br> MainForm: TMainForm;<br> FindAll: Boolean;<br> CtrlIndex: integer;<br> UserData: TIniFile;<br> hMappingFile: THandle;<br> pShMem: PShareMem;<br>const MessageID = WM_User + 110;<br><br>function EnumWindowsProc(hWindow: HWnd; lParam: LongInt): Boolean;<br>{$IFDEF Win32}stdcall; {$ELSE}; export; {$ENDIF}<br>function EnumWindowsFast(hWindow: HWnd; lParam: LongInt): Boolean;<br>{$IFDEF Win32}stdcall; {$ELSE}; export; {$ENDIF}<br>function EnumChildProc(HWnd: integer; lParam: LongInt): Boolean;<br>{$IFDEF Win32}stdcall; {$ELSE}; export; {$ENDIF}<br>function EnumChildItems(HWnd: integer; lParam: LongInt): Boolean;<br>{$IFDEF Win32}stdcall; {$ELSE}; export; {$ENDIF}<br>function FindAWindow(Caption: string; ClassName: string; IsThread: Boolean):<br> THandle;<br><br>implementation<br><br>{$R *.dfm}<br>function StartHook(Sender: HWnd; MessageID: WORD; WatchFormName: TChars): BOOL;<br> stdcall; external<br>'AHook.DLL';<br>function StopHook: BOOL; stdcall; external 'AHook.DLL';<br><br>function SetWatch: BOOL; stdcall; external 'AHook.Dll';<br><br>function TMainForm.GetEditIndexs: TEditIndexs;<br>begin<br> FEditIndexs.NameIndex := UpDown2.Position;<br> FEditIndexs.SexManIndex := UpDown3.Position;<br> FEditIndexs.SexWomanIndex := UpDown4.Position;<br> FEditIndexs.AgeIndex := UpDown5.Position;<br> FEditIndexs.PaperIndex := UpDown6.Position;<br> Result := FEditIndexs;<br>end;<br><br>function EnumWindowsProc(hWindow: HWnd; lParam: LongInt): Boolean;<br>{$IFDEF Win32} stdcall; {$ELSE}; export; {$ENDIF}<br>var<br> lpBuffer: PChar;<br> WindowCaptionFound: Boolean;<br> ClassNameFound: Boolean;<br>begin<br> GetMem(lpBuffer, 255);<br> Result := True;<br> WindowCaptionFound := False;<br> ClassNameFound := False;<br> try<br><br> //------------------------------------------------<br> if GetWindowText(hWindow, lpBuffer, 255) &gt; 0 then<br> if FindAll then<br> begin<br> if not (StrPas(lpBuffer) = '网虫外挂v1.0') then<br> begin<br> MainForm.lbxSearch.Items.Add(StrPas(lpBuffer));<br> MainForm.ListBoxAddWidth(MainForm.lbxSearch);<br> MainForm.lblWinCount.Caption :=<br> IntToStr(StrToInt(MainForm.lblWinCount.Caption) + 1);<br> end;<br> end<br> else<br> if Pos(PFindWindowStruct(lParam).Caption, StrPas(lpBuffer)) &gt; 0 then<br> WindowCaptionFound := True;<br><br> if not FindAll then<br> begin //-----------------------<br> if PFindWindowStruct(lParam).ClassName = '' then<br> ClassNameFound := True else<br> if GetClassName(hWindow, lpBuffer, 255) &gt; 0 then<br> if Pos(PFindWindowStruct(lParam).ClassName, StrPas(lpBuffer)) &gt; 0 then<br> ClassNameFound := True;<br><br> if (WindowCaptionFound and ClassNameFound) then<br> begin<br> PFindWindowStruct(lParam).WindowHandle := hWindow;<br> Result := False;<br> end;<br> end; //----------------------------<br> //-------------------------------------------------<br> finally<br> FreeMem(lpBuffer, sizeof(lpBuffer^));<br> end;<br>end;<br>//--------这个函数可不用---------------<br>function EnumWindowsFast(hWindow: HWnd; lParam: LongInt): Boolean;<br>{$IFDEF Win32} stdcall; {$ELSE}; export; {$ENDIF}<br>var<br> lpBuffer: PChar;<br> WindowCaptionFound: Boolean;<br> ClassNameFound: Boolean;<br>begin<br> GetMem(lpBuffer, 255);<br> Result := True;<br> WindowCaptionFound := False;<br> ClassNameFound := False;<br> try<br> //------------------------------------------------<br> if GetWindowText(hWindow, lpBuffer, 255) &gt; 0 then<br> if Pos(PFindWindowStruct(lParam).Caption, StrPas(lpBuffer)) &gt; 0 then<br> WindowCaptionFound := True;<br> if PFindWindowStruct(lParam).ClassName = '' then<br> ClassNameFound := True else<br> if GetClassName(hWindow, lpBuffer, 255) &gt; 0 then<br> if Pos(PFindWindowStruct(lParam).ClassName, StrPas(lpBuffer)) &gt; 0 then<br> ClassNameFound := True;<br> if (WindowCaptionFound and ClassNameFound) then<br> begin<br> PFindWindowStruct(lParam).WindowHandle := hWindow;<br> Result := False;<br> end;<br> finally<br> FreeMem(lpBuffer, sizeof(lpBuffer^));<br> end;<br>end;<br>//-----这是添加子窗口到 ListView记录 控件的信息------------------<br><br>function EnumChildProc(HWnd: integer; lParam: LongInt): Boolean;<br>{$IFDEF Win32} stdcall; {$ELSE}; export; {$ENDIF}<br>var<br> MyText: PChar;<br> ClassName: array[0..31] of Char;<br> SearchText: string;<br>begin<br> Result := True;<br> GetMem(MyText, 255);<br> try<br> SendMessage(HWnd, Wm_GetText, 255, LongInt(MyText));<br> GetClassName(HWnd, ClassName, 31);<br> SearchText := '[' + StrPas(MyText) + ']';<br><br> MainForm.AddFlag(ClassName, SearchText);<br> finally<br> FreeMem(MyText, sizeof(MyText^));<br> end;<br>end;<br>//-------枚举子窗口并通过索引值发送添写消息----------------<br>function EnumChildItems(HWnd: integer; lParam: LongInt): Boolean;<br>{$IFDEF Win32} stdcall; {$ELSE}; export; {$ENDIF}<br>var<br> ClsName, Caption: array[0..31] of Char;<br>begin<br> GetClassName(HWnd, ClsName, 31);<br> GetWindowText(HWnd, Caption, 31);<br> if CtrlIndex = MainForm.EditIndexs.NameIndex then<br> begin<br> SendMessage(HWnd, WM_SETTEXT, Length(Trim(MainForm.edtName.Text)),<br> LongInt(PChar(Trim(MainForm.edtName.Text))));<br> end;<br> if CtrlIndex = MainForm.EditIndexs.SexManIndex then<br> begin<br> if MainForm.rbtnMan.Checked then<br> SendMessage(HWnd, BM_CLICK, 0, 0);<br> end;<br> if CtrlIndex = MainForm.EditIndexs.SexWomanIndex then<br> begin<br> if MainForm.rbtnWoman.Checked then<br> SendMessage(HWnd, BM_CLICK, 0, 0);<br> end;<br> if CtrlIndex = MainForm.EditIndexs.AgeIndex then<br> begin<br> SendMessage(HWnd, WM_SETTEXT, Length(Trim(MainForm.edtAge.Text)),<br> LongInt(PChar(Trim(MainForm.edtAge.Text))));<br> end;<br> if CtrlIndex = MainForm.EditIndexs.PaperIndex then<br> begin<br> SendMessage(HWnd, WM_SETTEXT, Length(Trim(MainForm.edtPaper.Text)),<br> LongInt(PChar(Trim(MainForm.edtPaper.Text))));<br> end;<br> Inc(CtrlIndex);<br> Result := True;<br>end;<br><br>function FindAWindow(Caption: string; ClassName: string; IsThread: Boolean):<br> THandle;<br>var<br> windowInfo: TFindWindowStruct;<br>begin<br> begin<br> windowInfo.Caption := Caption;<br> windowInfo.ClassName := ClassName;<br> windowInfo.WindowHandle := 0;<br> if not IsThread then<br> EnumWindows(@EnumWindowsProc, LongInt(@windowInfo))<br> else<br> EnumWindows(@EnumWindowsFast, LongInt(@windowInfo));<br> FindAWindow := windowInfo.WindowHandle;<br> end;<br>end;<br>//----加宽 ListBox 的宽度,可不用.<br>procedure TMainForm.ListBoxAddWidth(AListBox: TListBox);<br>var<br> i, MaxWidth: integer;<br>begin<br> MaxWidth := 0;<br> for i := 0 to AListBox.Items.Count - 1 do<br> if MaxWidth &lt; AListBox.Canvas.TextWidth(AListBox.Items.Strings) then<br> MaxWidth := AListBox.Canvas.TextWidth(AListBox.Items.Strings);<br> SendMessage(AListBox.Handle, LB_SETHORIZONTALEXTENT, MaxWidth + 2, 0);<br>end;<br><br>procedure TMainForm.btnExitClick(Sender: TObject);<br>begin<br> Close;<br>end;<br>//--枚举所有窗口到 ListBox 中<br>procedure TMainForm.btnSearchProcClick(Sender: TObject);<br>var<br> windowInfo: TFindWindowStruct;<br>begin<br> FindAll := True;<br> lbxSearch.Clear;<br> lblWinCount.Caption := '0';<br> if EnumWindows(@EnumWindowsProc, LongInt(@windowInfo)) then<br> FindAll := False;<br><br>end;<br>//ListBox选中的窗口名,并列出子窗口,保存在 ListView 中,并加入枚举次序.<br>procedure TMainForm.btnSelectedClick(Sender: TObject);<br>begin<br> if lbxSearch.ItemIndex &lt;&gt; -1 then<br> begin<br> pnlSelectedWin.Caption := lbxSearch.Items[lbxSearch.ItemIndex];<br> edtWindowName.Text := lbxSearch.Items[lbxSearch.ItemIndex];<br> ListControls(pnlSelectedWin.Caption);//加子窗口到 ListView 中.<br> end;<br>end;<br>procedure TMainForm.ListControls(Awnd: string);<br>var<br> TheWindowHandle: THandle;<br>begin<br> TheWindowHandle := FindAWindow(Awnd, '', False);<br> if TheWindowHandle &lt;&gt; 0 then<br> begin<br> lvSearchFlag.Items.Clear;<br> FindAll := False;<br> EnumChildWindows(TheWindowHandle, @EnumChildProc, 0);<br> end;<br>end;<br>procedure TMainForm.btnSearchFlagClick(Sender: TObject);<br>begin<br> ListControls(pnlSelectedWin.Caption);<br>end;<br>procedure TMainForm.AddFlag(AClass, AValue: string);<br>var AItem: TListItem;<br>begin<br> AItem := lvSearchFlag.Items.Add;<br> AItem.Caption := IntToStr(lvSearchFlag.Items.Count);<br> AItem.SubItems.Add(AClass);<br> AItem.SubItems.Add(AValue);<br>end;<br><br>procedure TMainForm.btnClearClick(Sender: TObject);<br>begin<br> lvSearchFlag.Items.Clear;<br>end;<br><br>procedure TMainForm.N1Click(Sender: TObject);<br>begin<br> if lvSearchFlag.SelCount &lt;= 0 then Exit;<br> case TMenuItem(Sender).Tag of<br> 1:<br> begin<br> edtNameIndex.Text := lvSearchFlag.Selected.Caption;<br> end;<br> 2:<br> begin<br> edtManIndex.Text := lvSearchFlag.Selected.Caption;<br> end;<br> 3:<br> begin<br> edtWomanIndex.Text := lvSearchFlag.Selected.Caption;<br> end;<br> 4:<br> begin<br> edtAgeIndex.Text := lvSearchFlag.Selected.Caption;<br> end;<br> 5:<br> begin<br> edtPaperIndex.Text := lvSearchFlag.Selected.Caption;<br> end;<br> end;<br>end;<br><br>function TMainForm.SendData(WindowName: string): Boolean;<br>var TheHandle: THandle;<br>begin<br> TheHandle := FindAWindow(WindowName, '', False);<br> if TheHandle &lt;&gt; 0 then<br> begin<br> CtrlIndex := 1;<br> EnumChildWindows(TheHandle, @EnumChildItems, 0);<br> CtrlIndex := 0;<br> end;<br> Result := True;<br>end;<br>procedure TMainForm.btnSendClick(Sender: TObject);<br>begin<br> if edtWindowName.Text = '' then<br> begin<br> Application.MessageBox('请先设置窗口标志! ', '操作提示', MB_OK +<br> MB_IconStop + MB_ApplModal);<br> PageControl1.ActivePageIndex := 1;<br> Exit;<br> end;<br><br> SendData(edtWindowName.Text);<br>end;<br>procedure TMainForm.ReadData;<br>var<br> i: integer;<br> UserSections: TStringList;<br> AListItem: TListItem;<br>begin<br> edtWindowName.Text := UserData.ReadString('Parameters', 'WindowName', '');<br> UpDown2.Position := UserData.ReadInteger('Parameters', 'NameIndex', 0);<br> UpDown3.Position := UserData.ReadInteger('Parameters', 'ManIndex', 0);<br> UpDown4.Position := UserData.ReadInteger('Parameters', 'WomanIndex', 0);<br> UpDown5.Position := UserData.ReadInteger('Parameters', 'AgeIndex', 0);<br> UpDown6.Position := UserData.ReadInteger('Parameters', 'PaperIndex', 0);<br> // chbxAutoPopup.Checked := UserData.ReadBool('Parameters','AutoPopup',True);<br> // chbxAutoInput.Checked := UserData.ReadBool('Parameters','AutoInput',True);<br> UserSections := TStringList.Create;<br> try<br> GetUserList(UserSections);<br> lvUserList.Items.Clear;<br> for i := 0 to UserSections.Count - 1 do<br> begin<br> AListItem := lvUserList.Items.Add;<br> AListItem.Caption := IntToStr(lvUserList.Items.Count);<br> AListItem.SubItems.Add(UserSections.Strings);<br> AListItem.SubItems.Add(UserData.ReadString(UserSections.Strings,<br> '性别',<br> '男'));<br> AListItem.SubItems.Add(IntToStr(UserData.ReadInteger(UserSections.Strings, '年龄', 18)));<br> AListItem.SubItems.Add(UserData.ReadString(UserSections.Strings,<br> '证件号', ''));<br> end;<br> finally<br> UserSections.Free;<br> end;<br>end;<br><br>procedure TMainForm.GetUserList(var AStringList: TStringList);<br>begin<br> UserData.ReadSections(AStringList);<br> if AStringList.IndexOf('Parameters') &lt;&gt; -1 then<br> AStringList.Delete(AStringList.IndexOf('Parameters'));<br>end;<br>procedure TMainForm.FormCreate(Sender: TObject);<br>begin<br> UserData := TIniFile.Create(ExtractFilePath(paramstr(0)) + UserFile);<br> pShMem := nil;<br> ReadData;<br>end;<br><br>procedure TMainForm.FormDestroy(Sender: TObject);<br>begin<br> if UserData &lt;&gt; nil then<br> UserData.Free;<br>end;<br><br>procedure TMainForm.lvUserListClick(Sender: TObject);<br>begin<br> if lvUserList.Selected &lt;&gt; nil then<br> begin<br> SetValues(lvUserList.Selected);<br> end;<br>end;<br>procedure TMainForm.SetValues(AListItem: TListItem);<br>begin<br> edtName.Text := AListItem.SubItems.Strings[0];<br> if AListItem.SubItems.Strings[1] = '男' then<br> rbtnMan.Checked := True<br> else<br> rbtnWoman.Checked := True;<br> edtAge.Text := AListItem.SubItems.Strings[2];<br> edtPaper.Text := AListItem.SubItems.Strings[3];<br>end;<br>procedure TMainForm.WriteData;<br>const SexStr: array[Boolean] of string = ('女', '男');<br>begin<br> UserData.WriteString(edtName.Text, '性别', SexStr[rbtnMan.Checked]);<br> UserData.WriteInteger(edtName.Text, '年龄', UpDown1.Position);<br> UserData.WriteString(edtName.Text, '证件号', edtPaper.Text);<br>end;<br>procedure TMainForm.btnSaveClick(Sender: TObject);<br>begin<br> if Trim(edtName.Text) &lt;&gt; '' then<br> begin<br> WriteData;<br> ReadData;<br> end;<br><br>end;<br><br>procedure TMainForm.btnDeleteClick(Sender: TObject);<br>begin<br> UserData.EraseSection(edtName.Text);<br> ReadData;<br>end;<br><br>procedure TMainForm.btnSaveParamClick(Sender: TObject);<br>begin<br> UserData.WriteString('Parameters', 'WindowName', edtWindowName.Text);<br> UserData.WriteInteger('Parameters', 'NameIndex', UpDown2.Position);<br> UserData.WriteInteger('Parameters', 'ManIndex', UpDown3.Position);<br> UserData.WriteInteger('Parameters', 'WomanIndex', UpDown4.Position);<br> UserData.WriteInteger('Parameters', 'AgeIndex', UpDown5.Position);<br> UserData.WriteInteger('Parameters', 'PaperIndex', UpDown6.Position);<br> UserData.WriteBool('Parameters', 'AutoPopup', chbxAutoPopup.Checked);<br> UserData.WriteBool('Parameters', 'AutoInput', chbxAutoInput.Checked);<br>end;<br><br>procedure TMainForm.lvUserListDblClick(Sender: TObject);<br>begin<br> if lvUserList.Selected &lt;&gt; nil then<br> begin<br> lvUserList.ItemFocused.Checked := not lvUserList.ItemFocused.Checked;<br> if lvUserList.ItemFocused.Checked then<br> btnSend.Click;<br> end;<br>end;<br><br>procedure TMainForm.btnHideClick(Sender: TObject);<br>begin<br> GroupBox1.Visible := not GroupBox1.Visible;<br> if GroupBox1.Visible then<br> btnHide.Caption := '隐藏'<br> else<br> btnHide.Caption := '显示';<br>end;<br><br>procedure TMainForm.chbxAutoPopupClick(Sender: TObject);<br>var WndName: TChars;<br>begin<br> StrPCopy(WndName, Trim(MainForm.edtWindowName.Text));<br> if chbxAutoPopup.Checked then<br> begin<br> StartHook(MainForm.Handle, MessageID, WndName);<br> end<br> else<br> StopHook;<br> end;<br><br>procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);<br>begin<br> // FindThread.Terminate;<br>end;<br><br>procedure TMainForm.WndProc(var Messages: TMessage);<br>begin<br> if pShMem = nil then<br> begin<br> hMappingFile := OpenFileMapping(FILE_MAP_WRITE, False, MappingFileName);<br> if hMappingFile = 0 then Exception.Create('不能建立共享内存!');<br> pShMem := MapViewOfFile(hMappingFile, FILE_MAP_WRITE or FILE_MAP_READ, 0, 0,<br> 0);<br> if pShMem = nil then<br> begin<br> CloseHandle(hMappingFile);<br> Exception.Create('不能映射共享内存!');<br> end;<br><br> end;<br> if pShMem = nil then Exit;<br> if Messages.Msg = MessageID then<br> begin<br> if chbxAutoPopup.Checked then<br> if not IsWindowVisible(MainForm.Handle) then<br> begin<br> MainForm.Show;<br> // SetForegroundWindow(MainForm.Handle);<br> end;<br> SetWindowPos(MainForm.Handle, HWND_TopMost, 0, 0, 0, 0,<br> SWP_NoMove or SWP_NoSize or SWP_ShowWindow);<br> // SetWindowPos(MainForm.Handle, HWND_NOTOPMOST, 0, 0, 0, 0,<br> // SWP_NoMove or SWP_NoSize or SWP_ShowWindow);<br> { SetWindowPos(MainForm.Handle,<br> HWND_TopMost,<br> 0,<br> 0,<br> 0,<br> 0,<br> SWP_NOACTIVATE or SWP_NoMove or SWP_NoSize or SWP_ShowWindow);<br> }<br><br> // BringWindowToTop(MainForm.Handle);<br> // SetActiveWindow(MainForm.Handle);<br> end; // else<br> inherited;<br>end;<br>procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> StopHook;<br>end;<br><br>end.<br><br><br><br>