Java Programm mit CreateProcess --> Java Hauptfenster im Vordergrund
-
Hallo,
ich habe folgendes Problem:
Ich rufe mit CreateProcess aus einem C++ Programm ein Java - Programm auf.
Dieses startet auch, nur leider kommt es nicht in den Vordergrund. Ich habe an mehrere Java - Foren geschrieben, deren Tipps leider nicht geholfen haben. Kann es sein, das es an dem C++Programm liegt, das das Java - Programm nicht in den Vordergrund kommt?Ich benutze in C++ zwar die WinMain - Funktion, erzeuge aber kein Fenster. Kann es daran liegen?
Der Source meines C++ Progs sieht so aus:
#include <stdio.h> #include <windows.h> int ProcessCreate(); bool IsWinNT(); int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { return ProcessCreate(); } int ProcessCreate() { const char app[] = "java myJavaProgramm"; bool result = true; SECURITY_ATTRIBUTES sa; SECURITY_DESCRIPTOR sd; //security information for pipes PROCESS_INFORMATION pi; STARTUPINFO si; DWORD flags; if (IsWinNT()) //initialize security descriptor (Windows NT) { InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION); SetSecurityDescriptorDacl(&sd, true, NULL, false); sa.lpSecurityDescriptor = &sd; } else sa.lpSecurityDescriptor = NULL; sa.nLength = sizeof(SECURITY_ATTRIBUTES); sa.bInheritHandle = true; //allow inheritable handles GetStartupInfo(&si); //set startupinfo for the spawned process /* The dwFlags member tells CreateProcess how to make the process. STARTF_USESTDHANDLES validates the hStd* members. STARTF_USESHOWWINDOW validates the wShowWindow member. */ si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW; si.wShowWindow = SW_SHOW; //spawn the child process if (!CreateProcess(NULL, (char*)app, NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) { return 125; } WaitForSingleObject(pi.hProcess, INFINITE); CloseHandle(pi.hThread); CloseHandle(pi.hProcess); return 0; } bool IsWinNT() //check if we're running NT { OSVERSIONINFO osv; osv.dwOSVersionInfoSize = sizeof(osv); GetVersionEx(&osv); return (osv.dwPlatformId == VER_PLATFORM_WIN32_NT); }
-
MSDN schrieb:
CREATE_NO_WINDOW
This flag is valid only when starting a console application. If set, the console application is run without a console window.
This flag cannot be used with MS-DOS-based applications.Windows Me/98/95: This value is not supported.
Lass dieses Flag mal weg (bei CreateProcess).
Ist überhaupt ein Fenster zu sehen, wenn du das Programm ausführst oder ist es nur im Hintergrund/inaktiv(graue Titelleiste)?
-
D@niel $chumann schrieb:
MSDN schrieb:
CREATE_NO_WINDOW
This flag is valid only when starting a console application. If set, the console application is run without a console window.
This flag cannot be used with MS-DOS-based applications.Windows Me/98/95: This value is not supported.
Lass dieses Flag mal weg (bei CreateProcess).
Ist überhaupt ein Fenster zu sehen, wenn du das Programm ausführst oder ist es nur im Hintergrund/inaktiv(graue Titelleiste)?
Hallo,
hat leider auch nicht geklappt.
Wenn ich das Progrmm aus dem Explorer starte, wird das Java-Fenster hinter das Explorer Fenster gelegt. Ich sehe es also nur, wenn das Explorer - Fenster nicht auf Maximiert steht.
-
Ich hab mir mal ein Testprojekt angelegt und eine TestJavaApplication.
Als Grundlage habe ich dein Programmcode verwendet, musste aber das von mir o.g. Flag und STARTF_USESTDHANDLES (entspr. Attribute werden eh nicht gefüllt) weglassen, um überhaupt eine Ausgabe zu sehen.
Beim Start mittels ExplorerDoppelclick war es bei den ersten malen ganz normal im Vordergrund, dann nach ca. dem 5 mal nicht mehr und dann irgendwann doch wieder, also sehr merkwürdig.
Als Lösung könntest du mit FindWindow das Fensterhandle ermitteln und in den Vordergrund setzten. Dazu dem Fenster evtl. einen speziellen Titel mittels dem Attribut lpTitle von STARTUPINFO geben, damit es einzigartig ist.
-
Vielen Dank, so klappt es...