Question

I'm using a CreateProcess call within a C++ program to execute a JAR file that runs a Java Swing GUI application. All works fine with the exception that the Java app starts off minimized and I want it to start with the window displayed. Here's the relevant code snippet:

// Construct the command string to be used for the CreateProcess call,
//including a parameter string
sprintf(cmdStr, "javaw -jar \"AppDir\\App.jar\" %s", parmStr);

// Create and initialized startup-info structure for use with CreateProcess call
STARTUPINFO startInfo;
ZeroMemory(&startInfo, sizeof(startInfo));

startInfo.wShowWindow = SW_NORMAL;
startInfo.dwFlags = STARTF_USESHOWWINDOW;
startInfo.cb = sizeof(startInfo);
PROCESS_INFORMATION procInfo;
ZeroMemory(&procInfo, sizeof(procInfo));

if (!CreateProcess(NULL, cmdStr, NULL, NULL, FALSE, 0, NULL, NULL, &startInfo,  &procInfo))
{
   MessageBox( dialogOwner, "Create Process Error", "Application not instantiated", MB_OK);
}

According to the MSDN literature, setting the wShowWindow flag to SW_NORMAL and dwFlags to STARTF_USESHOWWINDOW ought to do the trick but some of the comments I've read in this and other forums imply that sometimes those flags are ignored (e.g. for console apps) so I was wondering if that was the case here. For the record, I've had this problem before then it went away on its own and now it's back after I made some code changes. But I wasn't setting any flags in the startupinfo structure before, so I was hoping to achieve some consistency in behaviour by doing so. Any tips or pointers would be appreciated...

Sheldon R.

Était-ce utile?

La solution 2

This is an update to my previous answer: The reason I had to call my java applet two different ways (i.e. "java" or "javaw") depending on the context, had to do with a bug in the C++ application from which I was calling my applet. The reason I know this is because a few months after fixing my issue, a newer version of this application was released, and this version didn't have the underlying bug, which essentially caused a new bug in my applet due to the "java" command doing what you'd expect i.e. instantiating a console window in addition to the applet window, much to the surprise of my business users :). So for the new bug-free version of the C++ application, I call my applet using the "javaw" command regardless of whether or not a dialog box is instantiated first to enable the user to enter login credentials...

Sheldon

Autres conseils

Okay, I've been working on a solution to my problem and I'm finally ready to talk about it, since it appears to be working :) I call my Java app one of two ways: either by popping up a dialog box first to collect login credentials, or by calling the app directly using saved credentials. For the login-dialog case, I call CreateProcess with the parameter "javaw...", whereas the saved-credential case appears to need "java..." to avoid the app starting up minimized. Aside from the difference in the parameter string, everything else about the CreateProcess call is the same. I don't know why I would use "java" in one case and "javaw" in the other, but since it's working, I won't question it :) But, of course, if someone wants to enlighten on the subject, I'd be happy to learn more. Thanks to @Jim Garrison for the suggestion, even if it wasn't ultimately the solution to my issue...

Sheldon R.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top