Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Change text of other App Edit Control (https://www.delphipraxis.net/141183-change-text-other-app-edit-control.html)

Razor 4. Okt 2009 10:57


Change text of other App Edit Control
 
Hi!

I want to change/insert text to a Tedit control of other application ( Find File Dialog ).
I got this so far but i guess Setwindowtext won't work


Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
var
  wndMain, wndChild: HWND;
begin
  wndMain := FindWindow('CabinetWClass','Search Results');
  if wndMain <> 0 then
  begin
    wndChild := FindWindowEx(wndMain, 0, 'WorkerW', nil);
    wndChild := FindWindowEx(wndChild, 0, 'ReBarWindow32', nil);
    wndChild := FindWindowEx(wndChild, 0, 'UniversalSearchBand', nil);
    wndChild := FindWindowEx(wndChild, 0, 'Search Box', nil);
 wndChild := FindWindowEx(wndChild, 0, 'SearchEditBoxWrapperClass', nil);
  //  WINDOWS.SetWindowTextA(wndchild,'s');
     //WINDOWS.SetWindowTextW(wndchild,'s');
     sendmessage(wndchild,WM_settext,0,0);
    if wndChild <> 0 then
    begin
      ShowMessage('Window Handle: ' + IntToStr(wndChild));

    end;
  end;
end;

toms 4. Okt 2009 11:06

Re: Change text of other App Edit Control
 
Hi,

To set the text of a control in another process, send the WM_SETTEXT message directly instead of calling SetWindowText.
MSDN-Library durchsuchenSetWindowText

Razor 4. Okt 2009 11:12

Re: Change text of other App Edit Control
 
Well clearly its not working toms...I want to specify what i want to search from delphi app to the find file dialog directory is not enough.Thats why this way..

Delphi-Quellcode:
uses ddeman;

procedure TForm1.Button1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);

  var
  wndMain, wndChild: HWND;
    msg : String;

begin
  wndMain := FindWindow('CabinetWClass','Search Results');
  if wndMain <> 0 then
  begin
    wndChild := FindWindowEx(wndMain, 0, 'WorkerW', nil);
    wndChild := FindWindowEx(wndChild, 0, 'ReBarWindow32', nil);
    wndChild := FindWindowEx(wndChild, 0, 'UniversalSearchBand', nil);
    wndChild := FindWindowEx(wndChild, 0, 'Search Box', nil);
    wndChild := FindWindowEx(wndChild, 0, 'SearchEditBoxWrapperClass', nil);

msg := 'search for this';



    if wndChild <> 0 then
    begin
      ShowMessage('Window Handle: ' + IntToStr(wndChild));
       SendMessage(wndchild, WM_SETTEXT, 0, LongInt(PChar(msg)));

  end;

  end;
end;



procedure TForm1.FormCreate(Sender: TObject);
begin
  with TDDEClientConv.Create(Self) do begin
   ConnectMode := ddeManual;
   ServiceApplication := 'explorer.exe';
   SetLink( 'Folders', 'AppProperties') ;
   OpenLink;
   ExecuteMacro
       ('[FindFolder(, C:\DelphiTips)]', False) ;
   CloseLink;
   Free;
  end;


end;

toms 4. Okt 2009 12:00

Re: Change text of other App Edit Control
 
What's your OS? Is the message ShowMessage(..) shown?

Also check out http://www.delphi-forum.de/viewtopic.php?p=217770

Razor 4. Okt 2009 12:01

Re: Change text of other App Edit Control
 
WIN 7 rtm 7600

toms 4. Okt 2009 12:06

Re: Change text of other App Edit Control
 
Zitat:

Zitat von Razor
WIN 7 rtm 7600

I asked 2 questions :wink:

Razor 4. Okt 2009 12:06

Re: Change text of other App Edit Control
 
The snippet dosent seem to work with DElphi 2010.. :)

[DCC Error] Unit1.pas(90): E2010 Incompatible types: 'Char' and 'AnsiChar'
Delphi-Quellcode:
 ExecuteMacro(PChar('[FindFolder(, '+ sVerz +')]'), False);
[DCC Warning] Unit1.pas(89): W1002 Symbol 'IncludeTrailingBackslash' is specific to a platform
Delphi-Quellcode:
sVerz := IncludeTrailingBackslash(Verzeichnis);

sx2008 4. Okt 2009 12:16

Re: Change text of other App Edit Control
 
Zitat:

Zitat von Razor
WIN 7 rtm 7600

http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx
Zitat:

Zitat von MSDN
Microsoft Windows Vista and later. Message sending is subject to User Interface Privilege Isolation (UIPI). The thread of a process can send messages only to message queues of threads in processes of lesser or equal integrity level.


Razor 4. Okt 2009 12:17

Re: Change text of other App Edit Control
 
Great . now i have to worry about security levels just great.

Razor 4. Okt 2009 13:26

Re: Change text of other App Edit Control
 
Nobody...?Dont know or is it that almost everybody is lazy to hit the post button.

Meflin 4. Okt 2009 13:34

Re: Change text of other App Edit Control
 
Zitat:

Zitat von Razor
Nobody...?Dont know or is it that almost everybody is lazy to hit the post button.

Where is your question?

DeddyH 4. Okt 2009 13:36

Re: Change text of other App Edit Control
 
42 :lol:

Razor 4. Okt 2009 13:37

Re: Change text of other App Edit Control
 
Question is: Why dosen't this work under win 7/vista?Please someone test it!
It only opens the dialog i knew how to do that on my own.So nothing new.

Delphi-Quellcode:
uses  
  ShellAPI,ddeman;  

 
procedure WindowsSuchenDialog(Verzeichnis, Suchstring: string);  
var  
  hOtherWin, hFocusWin: HWND;  
  OtherThreadID, iTimeOut: Integer;  
  aDwordVar: DWORD;  
  buf: array [0..40] of Char;  
  sVerz: string;  
begin  
  // ShellExecute(application.handle, 'find', 'c:\', nil, nil, SW_SHOWNORMAL);  
  // oder mit TDDEClientConv  
  with TDDEClientConv.Create(nil) do  
  begin  
    ConnectMode := ddeManual;  
    ServiceApplication := 'explorer.exe';  
    SetLink('Folders', 'AppProperties');  
    OpenLink;  
    sVerz := IncludeTrailingBackslash(Verzeichnis);  
    ExecuteMacro(PChar('[FindFolder(, '+ sVerz +')]'), False);  
    CloseLink;  
    Free;  
  end;  
  iTimeOut := 0;  
  repeat  
    { Warten, bis der Such Dialog erscheint.  
      Unter Win95/98/NT4 hat der Suchdilaog die Klasse #32770.  
      Unter ME/2000/XP ist die Suche in den Explorer integriert,  
      darum auf CabinetWClass warten}   
    Sleep(100);  
    hOtherWin := GetForegroundWindow;  
    buf[0] := #0;  
    GetClassName(hOtherWin, buf, 60);  
    inc(iTimeOut);  
  until (StrComp(buf, '#32770') = 0) or (StrComp(buf, 'CabinetWClass') = 0) or (iTimeOut > 20);  
  if iTimeOut > 20 then Exit;  
  repeat  
    { Wait until it is visible }   
    { Warten, bis das Fenster erscheint }   
    Sleep(100);  
  until IsWindowVisible(hOtherWin);  

 
  { Handle vom Control finden, welches den Fokus besitzt }   
  OtherThreadID := GetWindowThreadProcessID(hOtherWin, @aDwordvar);  
  if AttachThreadInput(GetCurrentThreadID, OtherThreadID, True) then  
  begin  
    hFocusWin := GetFocus;  
    if hFocusWin <> 0 then  
      try  
        SendMessage(hFocusWin, WM_SETTEXT, 0, Longint(PChar(Suchstring)));  
      finally  
        AttachThreadInput(GetCurrentThreadID, OtherThreadID, False);  
      end;  
  end;  
end;  

 
procedure TForm1.Button1Click(Sender: TObject);  
begin  
  WindowsSuchenDialog('c:\temp','test.txt');  
end;

Offtopic comment:@ DeddyH and others > Delphipraxis will be delphipraxis unique in its own weird bizzaree way.

toms 4. Okt 2009 14:50

Re: Change text of other App Edit Control
 
The answer was already given by sx2008.

This link might also be of interest: Windows Integrity Mechanism Design

Razor 4. Okt 2009 14:52

Re: Change text of other App Edit Control
 
Look toms no offense but you should really really update your Winspy 2008 in win 7 its showing completely diffrent handles.
WinID vs WinSpy 2008 = WinID wins by far!

The problem was WRONG HANDLE!

toms 4. Okt 2009 15:00

Re: Change text of other App Edit Control
 
Zitat:

Zitat von Razor
The problem was WRONG HANDLE!

That's why I asked you the question "Is the message ShowMessage(..) shown?"

Zitat:

Zitat von Razor
its showing completely diffrent handles.

Where exactly was the error? How does the FindWindow Code look like now?

Razor 4. Okt 2009 15:06

Re: Change text of other App Edit Control
 
Well its kind of weird but i will explain step by step:

Winspy 2008 gets handle alright but the last wndchild gets diffrent handle as reported in WINID;
if i used this procedure result would be nothing,but if used direct handle "number"
then it would change but WinID is reporting title change but it is not visible.Very cofusing


Delphi-Quellcode:
  wndMain := FindWindow('CabinetWClass','Search Results');
  if wndMain <> 0 then
  begin
    wndChild := FindWindowEx(wndMain, 0, 'WorkerW', nil);
    wndChild := FindWindowEx(wndChild, 0, 'ReBarWindow32', nil);
    wndChild := FindWindowEx(wndChild, 0, 'UniversalSearchBand', nil);
    wndChild := FindWindowEx(wndChild, 0, 'Search Box', nil);
    wndChild := FindWindowEx(wndChild, 0, 'SearchEditBoxWrapperClass', nil);
    wndChild := FindWindowEx(wndChild, 0, 'DirectUIHWND', nil)


As you can see here title is :www.delphipraxis something'' so it did change but not as it changes in IE search box.


IE search box works but only if you use direct HANDLE input no wndchild's and wndmain's


Now toms explain why does this happen

http://img.techpowerup.org/091004/Capture011.jpg
http://img.techpowerup.org/091004/Capture012.jpg

Razor 4. Okt 2009 16:04

Re: Change text of other App Edit Control
 
i believe toms that problem lies in DirectUIHwnd class.I am still searching what it is exactly.

fkerber 4. Okt 2009 16:12

Re: Change text of other App Edit Control
 
Hi!

Please don't push within 24 hours!


Ciao, Frederic

Razor 4. Okt 2009 17:41

Re: Change text of other App Edit Control
 
Fkerber if you do not know the solution to this problem dont post please...

Matze 4. Okt 2009 18:55

Re: Change text of other App Edit Control
 
Razor, we have a code of behaviour in the DP and you have to comply with it! Pushing within 24 hour is unfair towards others.
Frederic is a member of the team and he knows what you may do or not. You have to accept that!

If you don't change your behaviour your threads will be closed immediately.

Razor 4. Okt 2009 18:58

Re: Change text of other App Edit Control
 
Seriously i totaly regret even signing up for this forum 20 yes thats right 20 posts and no SOLUTION.Dohh.I hate when people link me to sites that have no solution either.

Matze 4. Okt 2009 19:18

Re: Change text of other App Edit Control
 
It's your own fault.

C L O S E D


Alle Zeitangaben in WEZ +1. Es ist jetzt 13:48 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz