现有两个应用程序A和B,相对应的窗体是FormA和FormB,我想通过FormA窗体向FormB窗体发送窗体隐藏/显示消息,如何实现。分不够可以再加

解决方案 »

  1.   

    1 用FindWindow找到FormB,用SendMessage或PostMessage发; 易
    2 Hook FormB; 较难
      

  2.   

    以下是向别的程序发送自定义消息的函数:const
      WM_MYMSG = WM_USER+1;function SendMsgToOtherProgram( const v_strWindowCaption: String ): Boolean;
    var
      hProgramWnd: HWND;
    begin
      hProgramWnd := FindWindow( nil, PChar(v_strWindowCaption) );
      if 0<>hProgramWnd then
        begin
          SendMessage( hProgramWnd, WM_MYMSG, 0, 0 );
          Result := TRUE;
        end
      else
        Result := FALSE;
    end;
      

  3.   

    程序A
    const WM_HideOrShow=WM_User+3;
    procedure SendToB;
    begin
      SendMessage(hB,WM_HideOrShow,wp,lp); //lp=0 then b hide else show,wp always 0
    end;
    程序B
    const WM_HideOrShow=WM_User+3; //same to A
    procedure HideOrShow(var msg:TMessage);message WM_HideOrShow;//dowith message
    implementation
    procedure HideOrShow(var msg:TMessage)
    begin
      if msg.lp=0 then Hide
      else Show;
    end;
      

  4.   


     WM_COPYDATA
     
     FindWindow(ClassName,Caption) ; // 得到句柄
      

  5.   

    用自定义消息
    如:
    const wm_fromforma = wm_user + 100;然后在forma中发消息给formb
    在formb中拦截此消息进行想要的处理