zoukankan      html  css  js  c++  java
  • SendMessage FindWindow

    主要API:FindWindow(LPCTSTR lpClassName,    LPCTSTR lpWindowName  )

    //通过进程名得到进程handle

    SendMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0

    //The result of the message processing; its value depends on the message sent.

    主程序 Server :其他均为默认.

    MFC 建立一Dialog 应用程序,工程名字:Server

    添加一Button控件command,并与之对应的函数OnCommand

    在ServerDlg.h里添加自己的消息:#define WM_COMM WM_USER+10

    函数 OnCommand 添加代码:

    {

     CString str="Client";
     CWnd *pWnd=CWnd::FindWindow(NULL,str);
     if(pWnd)
      pWnd->SendMessage(WM_COMM,0,0);//通过SendMessage的后两个参数

    //WPARAM wParam, LPARAM lParam传递信息
      else MessageBox("FindWindow NULL");

    }

    MFC另 建立一Dialog 应用程序,工程名字:Client 在 其

    OnInitDialog里最后添加代码SetWindowText("Client");

    在Client.h里添加自己的消息:#define WM_COMM WM_USER+10

    添加消息映射:

    BEGIN_MESSAGE_MAP(CSenderDlg, CDialog)
     //{{AFX_MSG_MAP(CSenderDlg)
     ON_WM_SYSCOMMAND()
     ON_WM_PAINT()
     ON_WM_QUERYDRAGICON()
      ON_MESSAGE(WM_COMM,OnSendMsg)//添加的自己的消息处理
     //}}AFX_MSG_MAP
    END_MESSAGE_MAP()

    给ClientDlg.cpp添加自己的消息处理函数OnSendMsg(WPARAM wParam, LPARAM lParam)

    {

    // wParam  lParam既是要传递的信息

    if(wParam==0 && lParam==0)
    AfxMessageBox("HelloWorld!");

    }

  • 相关阅读:
    linux三剑客
    linux用户权限
    linux文件权限
    linux目录配置
    linux命令(持续更新)
    linux外置命令
    linux日常操作指令
    晨雾

    CAPTCHA--验证码
  • 原文地址:https://www.cnblogs.com/shengshuai/p/sendmessagefindexec.html
Copyright © 2011-2022 走看看