怎么从子进程里获取主进程的ThreadID?

背景:
我要从子进程(控制台程序)发送消息给主进程,用该函数
PostThreadMessage(m_hThreadID[i], WM_MESSAGE, NULL, NULL);

怎么才能从子进程获取主进程的threadID呢?

谢谢!

 在Application类中获取主线程Id,全局都可以得到主线程ID
public class BaseApplication extends Application{
    private  static BaseApplication application;
    //主线程的id
    private static  int mainId;
    //对外提供Handler
    private static Handler handler;
    @Override
    public void onCreate() {
        super.onCreate();
        application = this;
        mainId = android.os.Process.myTid();
        handler = new Handler();
    }
    //对外获取Context
    public  static Context getAppliction(){
        return application;
    }
  //获取主线程的id
    public static int getMainId() {
        return mainId;
    }
    //获取Handler
    public static Handler getHandler() {
        return handler;
    }
}

在Application类中获取主线程Id,全局都可以得到主线程ID
public class BaseApplication extends Application{
private static BaseApplication application;
//主线程的id
private static int mainId;
//对外提供Handler
private static Handler handler;
@Override
public void onCreate() {
super.onCreate();
application = this;
mainId = android.os.Process.myTid();
handler = new Handler();
}
//对外获取Context
public static Context getAppliction(){
return application;
}
//获取主线程的id
public static int getMainId() {
return mainId;
}
//获取Handler
public static Handler getHandler() {
return handler;
}
}

你可以在主线程创建子线程的时候,把主线程的ID作为参数传递进线程函数。然后线程函数保存下来使用