I'm creating an application that will add/create a win32 control/s on another application. Using CreateWindow
and also multithreading, I have successfully created the controls, and also the Tabstop of the created control is running well. The problem is when the tabstop is now focused on existing controls, it will not go back to the created controls. Is there a way to fix this? here's my code:
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;