我有一个简单的控制台应用程序,可以创建3个子进程:
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
STARTUPINFO si[5];
PROCESS_INFORMATION pi[5];
int procIndex = 0;
void monitor_new_process();
void monitor_shutdown();
/**
*
* @see: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682512(v=vs.85).aspx
*/
void _tmain(int argc, TCHAR *argv[]) {
monitor_new_process();
monitor_new_process();
monitor_new_process();
monitor_shutdown();
}
void monitor_new_process() {
ZeroMemory(&si[procIndex], sizeof(si[procIndex]));
si[procIndex].cb = sizeof(si[procIndex]);
ZeroMemory(&pi[procIndex], sizeof(pi[procIndex]));
// Start the child process.
if (!CreateProcess(NULL, // No module name (use command line)
"consumer", // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si[procIndex], // Pointer to STARTUPINFO structure
&pi[procIndex]) // Pointer to PROCESS_INFORMATION structure
)
{
printf("CreateProcess failed (%d).\n", GetLastError());
return;
}
procIndex++;
}
void monitor_shutdown() {
while (procIndex >= 0){
// Wait until child process exits.
WaitForSingleObject(pi[procIndex].hProcess, INFINITE);
// Close process and thread handles.
CloseHandle(pi[procIndex].hProcess);
CloseHandle(pi[procIndex].hThread);
procIndex--;
}
}
我也一直在玩GTK +。我做了一个简单的应用程序,从ui文件生成一个窗口:
#include <gtk/gtk.h>
GtkBuilder *builder;
GObject *window;
GObject *button;
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
/* Construct a GtkBuilder instance and load our UI description */
builder = gtk_builder_new();
gtk_builder_add_from_file(builder, "builder.ui", NULL);
/* Connect signal handlers to the constructed widgets. */
window = gtk_builder_get_object(builder, "window");
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_main();
return 0;
}
我想知道是否有一个GTK +元素可以放入builder.ui文件中,该文件可以充当&#34;容器&#34;对于子进程。
例如,我可以在构建器中使用这样的东西:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="window1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="title" translatable="yes">Test</property>
<property name="window_position">center</property>
<property name="default_width">440</property>
<property name="default_height">250</property>
<property name="destroy_with_parent">True</property>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuBar" id="menubar1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkMenuItem" id="menuitem1">
<!- ... ->
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<!-- SOME KIND OF CHILD PROCESS CONTAINER -->
</child>
</object>
</child>
</object>
</interface>
<!-- SOME KIND OF CHILD PROCESS CONTAINER -->
将是一个具有ID的对象,我可以在其中嵌套来自子进程的GTK +窗口。
类似的概念就像HTML中的iFrame - 您可以使用HTML来指定外部Web应用程序嵌套到父容器中的框架。
另一个类似的概念是Google Chrome。 Chrome的shell是一个进程,每个标签都是一个子进程。这基本上就是我试图模仿的东西。
在GTK +和我的子进程脚本中我需要做什么才能做到这一点?这对GTK来说是否可能?