在运行时创建的Tabstop Win32控件和不同应用程序的现有控件

时间:2015-02-20 08:53:33

标签: delphi tabstop

我正在创建一个应用程序,它将在另一个应用程序上添加/创建win32控件。使用CreateWindow和多线程,我已经成功创建了控件,并且创建的控件的Tabstop运行良好。问题是当tabstop现在专注于现有控件时,它不会返回到创建的控件。有没有办法来解决这个问题?这是我的代码:

var
  Msg        : TMSG;
procedure CreateEdit(pHWND: HWND; stxt: string; pnt: Tpoint);
var
  hFontText  : HWND;
  hEdit: HWND;
  hOldEdit: HWND;
  hIns: Integer;
  style : DWORD;

  function EnumChildren( hHandle : HWND; lParamMeter : LPARAM) : BOOL; stdcall;
  var
    style : DWORD;
  begin
    Result := True;
    style := GetWindowLong( hHandle, GWL_STYLE );
    if ((style or WS_TABSTOP) <> WS_TABSTOP) then
    begin
      SetWindowLongPtr( hHandle, GWL_STYLE, style or WS_TABSTOP);
    end;
  end;

begin
  hIns := GetWindowLong(pHWND, GWL_HINSTANCE);
  style := GetWindowLong( pHWND, GWL_STYLE );
  if ((style or WS_EX_CONTROLPARENT) <> WS_EX_CONTROLPARENT) then
  begin
    SetWindowLongPtr( pHWND, GWL_STYLE, style or WS_EX_CONTROLPARENT);
  end;
  hFontText := CreateFont(-14,0,0,0,0,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,VARIABLE_PITCH or FF_SWISS,'Tahoma');
  hOldEdit := pHWND;
  hEdit := CreateWindow('Edit', PWideChar(Trim(stxt)),
              WS_TABSTOP OR
              WS_VISIBLE OR
              ES_READONLY OR
              WS_CHILD,
            (pnt.X),(pnt.Y), 100, 23, pHWND, 0, hIns,nil);
  SendMessage(hEdit,WM_SETFONT,hFontText,0);
  SetWindowPos(hEdit, hOldEdit, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
  hOldEdit := hEdit;
  hEdit := CreateWindow('Edit', PWideChar(Trim(stxt)),
              WS_TABSTOP OR
              WS_VISIBLE OR
              WS_CHILD,
            (pnt.X),(pnt.Y) + 50, 100, 23, pHWND, 0, hIns,nil);
  SendMessage(hEdit,WM_SETFONT,hFontText,0);
  SetWindowPos(hEdit, hOldEdit, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
  EnumChildWindows(pHWND, @EnumChildren, 0);
  while GetMessage(Msg,pHWND,0,0) do
  begin
    if not(IsDialogMessage(pHWND, Msg)) then
    begin
      TranslateMessage(Msg);
      DispatchMessage(Msg);
    end;
  end;
end;
function CreateEdtThread(data: Pointer): Integer;
var
  tsTxt: TStrCoor;
begin
  tsTxt := TStrCoor(data^);
  Form2.CreateEdit(tsTxt.ParentHWND, tsTxt.str, tsTxt.pnt);
end;
...
procedure TForm2.Button1Click(Sender: TObject);
var
  tsTxt: PStrCoor;
  thID: Cardinal;
begin
  New(tsTxt);
  with tsTxt^ do
  begin
    ParentHWND := StrToInt(edtHWND.Text);
    str := 'Edit1';
    pnt := Point(25, 30);
  end;
  BeginThread(nil, 0, @CreateEdtThread, tsTxt, 0, thID);
end;

0 个答案:

没有答案