Q&A

  • FindWindowEx 에서 메시지 전달시
FindWindowEx에서 다른 프로그램으로 메세지 전달시

문자열로 전달이 되는지 알고 싶습니다.

숫자로는 전달이 되는데 문자열로는 전달이 안되더라구요 ;;;;

hwndClient : HWND;  //변수선언
msgstr : string;         //변수선언

procedure TForm1.FormCreate(Sender: TObject);
begin
  hwndClient := FindWindow(0, 'ICN_TCS_Main');
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
procedure TForm1.FormCreate(Sender: TObject);
begin
  hwndClient := FindWindow(0, 'ICN_TCS_Main');
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  msgstr := 'MENU1';
  SendMessage(hwndClient, WM_USER+200, WPARAM(0), LPARAM(msgstr));
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
  msgstr := 'MENU2';
  SendMessage(hwndClient, WM_USER+200, WPARAM(0), LPARAM(PChar(msgstr)));
end;

procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
  msgstr := 'MENU3';
  SendMessage(hwndClient, WM_USER+200, WPARAM(0), LPARAM(PChar(msgstr)));
end;

procedure TForm1.SpeedButton4Click(Sender: TObject);
begin
  msgstr := 'MENU4';
  SendMessage(hwndClient, WM_USER+200, WPARAM(0), LPARAM(PChar(msgstr)));
end;--------------------------- 메지시 보내는 부분


procedure TForm1.newWndProc(var msg : TMessage);
var tstr : string;
//var i : integer;
begin
//  tstr := TStrings.Create();
  i := 0;
  case msg.Msg of
  WM_USER+100 :
  begin
    // To do
    if 6 > bIndex then
    begin
      appendButton(bIndex, msg);
      bIndex := bIndex +1;
    end

    else
      ShowMessage('지정된 업무수를 초과하였습니다.');
    end;
    WM_USER+200 :
    begin
      tstr := PChar(msg.LParam);
      if 'MENU1' = tstr then i := 1;
      if 'MENU2' = tstr then i := 2;
      if 'MENU3' = tstr then i := 3;
      if 'MENU4' = tstr then i := 4;

      ToMenu(i);

    end;
  end;

  with msg do
    Result := CallWindowProc( FOldProc, pan_M_Left.Handle, Msg, WParam, LParam);
//  tstr.Free;
end;

procedure TForm1.InitMessage(Sender: TObject);
begin
  FoldProc := Pointer(GetWindowLong(self.Handle , GWL_WNDPROC));
  FNewProc := MakeObjectInstance(NewWndProc);
  SetWindowLong(self.Handle, GWL_WNDPROC, LongInt(FNewProc));
end;
---------------------------------메세지 받는 부분 (case WM_USER+100 신경안쓰셔도 되욤)
프로그램은 잘 붙거든요
그런데 받는부분에서 메시지를 못받는군요 ;;;




1  COMMENTS
  • Profile
    최용일 2007.10.30 22:35
    안녕하세요. 최용일입니다.

    문자열을 전송하실려면 WM_COPYDATA라는 메세지를 이용하세요.

    문자열(string)은 일종의 포인터입니다. 실제적인 문자열데이터가 있는 곳의 메모리 번지를 가리키는...

    윈도우는 각각의 프로그램마다 독립적인 4G의 메모리주소를 가집니다. 때문에 문자열같이 메모리 번지를 가지는 포인터형의 데이터를 서로 다른 프로그램이 주고 받는 것은 아무런 의미가 없습니다.

    WM_COPYDATA메세지를 이용하는 것외에 메모리맵드파일같은 공유 메모리를 이용하는 방법도 있습니다.
    배보다 배꼽이 더 클지 모르겠지만 네트워크통신하는 방법도 있죠...

    WM_COPYDATA의 사용법은 팁란이나 델파이 도움말을 찾아보시면 자세히 나와 있습니다.

    ^^ 항상 즐코하세요...