1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Donation with Paypal!!!

    Go to your paypal account and send directly donation to [email protected]

    1 month - 10 $ - Standart VIP

    6 months - 20 $- Standart VIP

    1 year - 30 $- Standart VIP

    2 years - 50 $- Standart VIP

    Gold member for life - 150 $- Standart VIP

    High Vip (Standart VIP include) group please send PM or email to [email protected] for info

    After Donation please send email to [email protected]

  3. Donation Ways 2020


    Paysend
  4. Telegram

  5. Delphifan Magazine
Dismiss Notice

Donation with Paypal!!!

Go to your paypal account and send directly donation to [email protected]

1 month - 10 $ - Standart VIP

6 months - 20 $- Standart VIP

1 year - 30 $- Standart VIP

2 years - 50 $- Standart VIP

Gold member for life - 150 $- Standart VIP

High Vip (Standart VIP include) group please send PM or email to [email protected] for info

After Donation please send email to [email protected]

Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

how to send the required information to the other running applications?

Discussion in 'Delphi Help&Requests' started by mahqni, May 5, 2015.

  1. mahqni
    Offline

    mahqni DF Junior

    I have a Delphi Win32 application which manages basic customer information
    (name, customer number, adress, etc.).
    I would like to be able to click on a button in our Delphi application that
    would send the required information to the other running applications like accounting without us having to
    retype the info into these Applications.
    Is this possible?
    How Would one go about doing this?
    Any help will be greatly appreciated.
    Regards,
     
  2. chris
    Online

    chris DF Junior

    Hello, that is possible via the WM_CopyData Message
    so something like this
    // send it


    Code:
    procedure SendItemsData(AData: string; DataValue: Byte = 25);
    var
      aCopyData: TCopyDataStruct;
      hTargetWnd: HWND;
    begin
      with aCopyData do
      begin
        dwData := DataValue;// Your data Value
        cbData := StrLen(PChar(AData)) * SizeOf(Char);
        lpData := PChar(AData)
      end;
      hTargetWnd := FindWindow('YourWindow', 'YourWindowCaption');
      if hTargetWnd <> 0 then
        SendMessage(hTargetWnd, WM_COPYDATA, NativeUint(WinHandle), NativeUint(@aCopyData))
      else
        // ShowMessage('No recipient found!'); Error
    end;
    recieve the Data


    Code:
    private
     procedure ReceiveItemsData(var Msg: TWMCopyData); message WM_COPYDATA;
    



    Code:
    procedure YourForm.ReceiveItemsData(var Msg: TWMCopyData);
    var
      sText: array [0 .. 500000] of Char;
      i: Integer;
      fText:string;
    begin
      // generate text from parameter
      StrLCopy(sText, Msg.CopyDataStruct.lpData, Msg.CopyDataStruct.cbData);
      // write received text
      ItemsData.Clear;
      case Msg.CopyDataStruct.dwData of
        // 31 dev_combo//32 line_combo//33 control_combo 34 volume 35 mute
        31:
          begin
            //fText := string(sText);
            // do something with the data
          end;
        32:begin
            //fText := string(sText);
            // do something with the data
          end;
      end;
    end;
    
    
     
  3. mahqni
    Offline

    mahqni DF Junior

    RE:

    thanks,but i cant write any code for recieving so i need another Method if possible
     
  4. chris
    Online

    chris DF Junior

    If I right understand there is another Application and you want read Data from there.
    As so far the wanted Data/text/ are inside a Control which will have a handle it is possible.
    To catch the code to read the Data from the other Prog just use Winspy .It will build code so that you can find the right handle via
    FindWindow or FindWindowEx

    http://www.cst-tech.de/downloads/WinSpy.7z
     
  5. mahqni
    Offline

    mahqni DF Junior

    RE:

    thanks Chris but i want to write in the other application Edits.
    i did that with windows Calculator but with other Applications i faild
     
  6. chris
    Online

    chris DF Junior

    Here an little small Example (send "TextString" 2 Notepad)

    Code:
    var Wnd: HWnd;
    
    begin
    
      Wnd := FindWindowEx(FindWindow('notepad',nil),0,'Edit',nil);
    
      if Wnd <> 0 then
    
        SendMessage(Wnd,WM_SETTEXT,0,LongInt(PChar('TextString')));
    
    end;
    
     
  7. mahqni
    Offline

    mahqni DF Junior

    RE:

    [font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]I used the winspy to get the Classname of edit but i still have 0 for the handle of edits[/font]
    [font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]var[/font]
    [font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]FoundWindow: HWND;[/font]
    [font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]WindowText: array[0..255] of char;[/font]
    [font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]MyHandle: THandle;[/font]
    [font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]begin[/font]
    [font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]MyHandle:=FindWindow(nil,pwidechar(Other Application));[/font]

    [font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]FoundWindow := FindWindowEx(MyHandle, 0, 'TMkEdit', nil);[/font]
    [font=Verdana, Arial, Tahoma, Calibri, Geneva, sans-serif]end;[/font]
     
  8. chris
    Online

    chris DF Junior

    The FindWindow call is wrong.var
    MyHandle:hwnd;

    FindWindow(TheFormClassName,The Caption of the Classname)

    So Example
    MyHandle := FindWindow(TForm1,Caption)

    By the way what is the Name of the other Application?
    so its a little bit more easy to send you the right code
     
  9. mahqni
    Offline

    mahqni DF Junior

    RE:

    Thanks Chris,
    My Problem is with the Findwindowex
      MyHandle := findwindow('TFAddSupplier','FAddSupplier');
      // hier i recieve the handle
      FoundWindow := FindWindowEx(MyHandle, 0, 'TMkedit',nil);
      // I got my mistake the Tmkedit are not direct on the form but on A Panel
    my question now how can i get the edit on this Panel
     
  10. chris
    Online

    chris DF Junior

    The Problem is you will need the Handle of the Panel.
    Here an little bit more Complex Code of my own DJ prog

    searching for a Tedit ....Form,Panel,PageControl,Tabsheet ,GroupBox,Tedit

    as you see to became the Handle of the Tedit you will need All Subclass Handles



    Code:
    function FindWindowEx2(hParent: HWND; ChildClassName: string; ChildNr: Word): HWND;
    var
      i: Word;
      hChild: HWND;
    begin
      hChild := 0;
      Result := 0;
      Dec(ChildNr);
      for i := 0 to ChildNr do
      begin
        hChild := FindWindowEx(hParent, hChild, PChar(ChildClassName), nil);
        if hChild = 0 then
          Break;
        Result := hChild;
      end;
    end;
    
    var
      wndMain, wndChild: HWND;
    begin
      wndMain := FindWindow('TSound_Config','Options');
      if wndMain <> 0 then
      begin
        wndChild := FindWindowEx(wndMain, 0, 'TsPanel', nil);
        wndChild := FindWindowEx2(wndChild,'TsPanel', 3);
        wndChild := FindWindowEx(wndChild, 0, 'TsPageControl1', nil);
        wndChild := FindWindowEx(wndChild, 0, 'TsTabSheet', nil);
        wndChild := FindWindowEx2(wndChild,'TsGroupBox', 6);
        wndChild := FindWindowEx2(wndChild,'TsEdit', 2);
        if wndChild <> 0 then
        begin
          ShowMessage('Window Handle: ' + IntToStr(wndChild));
        end;
      end;
    end.
     
  11. mahqni
    Offline

    mahqni DF Junior

    RE:

    Thanks a lot Chris
     
  12. Amro
    Online

    Amro Guest

     
  13. sysnikcy
    Online

    sysnikcy Guest

    RE:

    thanks
     
  14. ogrimdoohamer
    Offline

    ogrimdoohamer DF Member

    RE:

    Hi man, you can connect the 2 applications bt DataSnap or other TCP protocol. This way can be more secure to transfer the comunications.
     
  15. Amro
    Online

    Amro Guest

    and how can i do that?
     

Share This Page