javac++jarcreateprocessshowwindow

CreateProcess for Running JAR File Starts with Window Minimized


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.


Solution

  • 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