Flash Player Launching Process With CreateProcess

J

Jay

Hey There,
I have been writing some code in C++ that gets a message from a
Macromedia Flash Player to launch an application that is associated
with a flash button. When the button is pressed, it launches the
application, but the app window is never completely in front. The C++
code that I have been using to do this is below:

retVal =
CreateProcess(NULL,modName,NULL,NULL,FALSE,NULL,NULL,NULL,&si,&pi);
hProc = pi.hProcess;
procID = pi.dwProcessId;
HPStruct.procID = procID;
HPStruct.WindHandle = 0;
fp = fopen(THREAD_LOG_FILE,"a+");
fprintf(fp,"ProcID=%d\n",procID);
fclose(fp);
WaitForInputIdle(hProc,INFINITE);

EnumWindows((WNDENUMPROC)EnumOpenWindows,(LPARAM)&HPStruct);
fp = fopen(THREAD_LOG_FILE,"a+");
fprintf(fp,"After EnumWindows \n");
fclose(fp);
if(HPStruct.WindHandle != 0)
{
ShowWindow(HPStruct.WindHandle,SW_SHOWMAXIMIZED);
retVal = BringWindowToTop(HPStruct.WindHandle);
}

Is there something with the flash player that stops the app
from being in front? When I have other windows open and launch the app,
it will always be in front of any other window BUT the flash player
window. Any suggestions?

Thanks,
Jay
(patelj27b at gmail dot com)
 
J

Jay

Jay said:
Hey There,
I have been writing some code in C++ that gets a message from a
Macromedia Flash Player to launch an application that is associated
with a flash button. When the button is pressed, it launches the
application, but the app window is never completely in front. The C++
code that I have been using to do this is below:

retVal =
CreateProcess(NULL,modName,NULL,NULL,FALSE,NULL,NULL,NULL,&si,&pi);
hProc = pi.hProcess;
procID = pi.dwProcessId;
HPStruct.procID = procID;
HPStruct.WindHandle = 0;
fp = fopen(THREAD_LOG_FILE,"a+");
fprintf(fp,"ProcID=%d\n",procID);
fclose(fp);
WaitForInputIdle(hProc,INFINITE);

EnumWindows((WNDENUMPROC)EnumOpenWindows,(LPARAM)&HPStruct);
fp = fopen(THREAD_LOG_FILE,"a+");
fprintf(fp,"After EnumWindows \n");
fclose(fp);
if(HPStruct.WindHandle != 0)
{
ShowWindow(HPStruct.WindHandle,SW_SHOWMAXIMIZED);
retVal = BringWindowToTop(HPStruct.WindHandle);
}

Is there something with the flash player that stops the app
from being in front? When I have other windows open and launch the app,
it will always be in front of any other window BUT the flash player
window. Any suggestions?

Thanks,
Jay
(patelj27b at gmail dot com)

Also,
For some reason, the EnumWindows Function:

BOOL CALLBACK EnumOpenWindows(HWND hwnd, LPARAM lParam)
{
DWORD dwID;
DWORD currProcId;
FILE* fp;
struct _HwndProcStruct* locHPStruct;

fp = fopen(THREAD_LOG_FILE,APPEND_MODE);
fprintf(fp,"*******************<EnumOpenWindows>*******************\n");
fclose(fp);


locHPStruct = (struct _HwndProcStruct*)lParam;
currProcId = locHPStruct->procID;
dwID = 0;

GetWindowThreadProcessId(hwnd, &dwID);

fp = fopen(THREAD_LOG_FILE,APPEND_MODE);
fprintf(fp,"currProcId=%d dwID2=%d\n",currProcId,dwID);
fclose(fp);

if(dwID == currProcId)
{
locHPStruct->WindHandle = hwnd;
fp = fopen(THREAD_LOG_FILE,APPEND_MODE);
fprintf(fp,"FALSE\n");
fprintf(fp,"*******************</EnumOpenWindows>*******************\n");
fclose(fp);

return FALSE;
}
else
{
fp = fopen(THREAD_LOG_FILE,APPEND_MODE);
fprintf(fp,"TRUE\n");
fprintf(fp,"*******************</EnumOpenWindows>*******************\n");
fclose(fp);

return TRUE;
}
}

The above function never returns the hwnd associated with the procID
that is the ID from the created process. Any ideas?

-Jay
(patelj27b at gmail dot com)
 
A

Alex Blekhman

Jay said:
Hey There,
I have been writing some code in C++ that gets a
message from a Macromedia Flash Player to launch an
application that is associated with a flash button. When
the button is pressed, it launches the application, but
the app window is never completely in front. The C++ code
that I have been using to do this is below:

retVal =
CreateProcess(NULL,modName,NULL,NULL,FALSE,NULL,NULL,NULL,&s
i,&pi);
hProc = pi.hProcess;
procID = pi.dwProcessId;
HPStruct.procID = procID;
HPStruct.WindHandle = 0;
fp = fopen(THREAD_LOG_FILE,"a+");
fprintf(fp,"ProcID=%d\n",procID);
fclose(fp);
WaitForInputIdle(hProc,INFINITE);

EnumWindows((WNDENUMPROC)EnumOpenWindows,(LPARAM)&HPStruct);
fp = fopen(THREAD_LOG_FILE,"a+");
fprintf(fp,"After EnumWindows \n");
fclose(fp);
if(HPStruct.WindHandle != 0)
{
ShowWindow(HPStruct.WindHandle,SW_SHOWMAXIMIZED);
retVal = BringWindowToTop(HPStruct.WindHandle);
}

Is there something with the flash player that
stops the app from being in front? When I have other
windows open and launch the app, it will always be in
front of any other window BUT the flash player window.
Any suggestions?

New process is not foreground process. That's why
BringWindowToTop cannot overcome currently foreground
process. First, you need to relinquish your foreground
rights in favor of new process, then bring new window to
front. Read more about it in SetForegroundWindow and
AllowSetForegroundWindow functions description.

HTH
Alex
 
A

Alex Blekhman

Jay said:
For some reason, the EnumWindows Function:

BOOL CALLBACK EnumOpenWindows(HWND hwnd, LPARAM lParam)
{
DWORD dwID;
DWORD currProcId;
FILE* fp;
struct _HwndProcStruct* locHPStruct;

fp = fopen(THREAD_LOG_FILE,APPEND_MODE);
fprintf(fp said:
fclose(fp);


locHPStruct = (struct _HwndProcStruct*)lParam;
currProcId = locHPStruct->procID;
dwID = 0;

GetWindowThreadProcessId(hwnd, &dwID);

fp = fopen(THREAD_LOG_FILE,APPEND_MODE);
fprintf(fp,"currProcId=%d dwID2=%d\n",currProcId,dwID);
fclose(fp);

if(dwID == currProcId)
{
locHPStruct->WindHandle = hwnd;
fp = fopen(THREAD_LOG_FILE,APPEND_MODE);
fprintf(fp,"FALSE\n");
fprintf(fp said:
fclose(fp);

return FALSE;
}
else
{
fp = fopen(THREAD_LOG_FILE,APPEND_MODE);
fprintf(fp,"TRUE\n");
fprintf(fp said:
fclose(fp);

return TRUE;
}
}

The above function never returns the hwnd associated with
the procID that is the ID from the created process. Any
ideas?

Does it find the window? If it finds the window, but doesn't
return it, then _HwndProcStruct is messed up somewhere or
discareded too early. If EnumOpenWindows doesn't find the
window, then the window is not top-level window.

P.S. You can open log file just once and then write to it as
needed. No need to reopen it every time. It is a real pain
to see such code.
 
T

Tamas Demjen

Jay said:
When the button is pressed, it launches the
application, but the app window is never completely in front. The C++
code that I have been using to do this is below:

MSDN says about BringWindowToTop:
"If an application is not in the foreground and wants to be in the
foreground, it should call the SetForegroundWindow function."

Tom
 
J

Jay

Alex said:
New process is not foreground process. That's why
BringWindowToTop cannot overcome currently foreground
process. First, you need to relinquish your foreground
rights in favor of new process, then bring new window to
front. Read more about it in SetForegroundWindow and
AllowSetForegroundWindow functions description.

HTH
Alex

Hey There,
I tried to implement the suggestion you made, by inserting the code
for the foreground window, as shown below:

if(HPStruct.WindHandle != 0)
{
//ShowWindow(HPStruct.WindHandle,SW_SHOWMAXIMIZED);
retVal = AllowSetForegroundWindow(procID);
errNo = GetLastError();
if(retVal == FALSE)
{
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM, NULL, errNo,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&lpvMessageBuffer, 0, NULL);
fprintf(fp,"AllowSetForegroundWindow error=%s\n",lpvMessageBuffer);
}

retVal = SetForegroundWindow(HPStruct.WindHandle);
errNo = GetLastError();
if(retVal == FALSE)
{
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM, NULL, errNo,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&lpvMessageBuffer, 0, NULL);
fprintf(fp,"AllowSetForegroundWindow error=%s\n",lpvMessageBuffer);
}

The AllowSetForegroundWindow though returns with an "Access is denied."
error. Can anyone tell me why this is the case, and what can be done to
allow it to be set to the foreground?

Thanks,
Jay
(patelj27b at gmail dot com)
 
A

Alex Blekhman

Jay said:
I tried to implement the suggestion you made, by
inserting the code for the foreground window, as shown
below:
[...]
The AllowSetForegroundWindow though returns with an
"Access is denied." error. Can anyone tell me why this is
the case, and what can be done to allow it to be set to
the foreground?

Probably the calling process doesn't meet criteria specified
by AllowSetForegroundWindow documentation.
 
J

Jay

Alex said:
Jay said:
I tried to implement the suggestion you made, by
inserting the code for the foreground window, as shown
below:
[...]
The AllowSetForegroundWindow though returns with an
"Access is denied." error. Can anyone tell me why this is
the case, and what can be done to allow it to be set to
the foreground?

Probably the calling process doesn't meet criteria specified
by AllowSetForegroundWindow documentation.

The Application that is going to be spawning the process that needs to
be in the foreground is an application that resides in the system tray,
therefore it never gets foreground control itself. How would it get
control of the foreground in this case?

-Jay
(patelj27b at gmail dot com)
 
A

Alex Blekhman

Jay said:
I tried to implement the suggestion you made, by
inserting the code for the foreground window, as shown
below:
[...]
The AllowSetForegroundWindow though returns with an
"Access is denied." error. Can anyone tell me why this
is the case, and what can be done to allow it to be set
to the foreground?

Probably the calling process doesn't meet criteria
specified by AllowSetForegroundWindow documentation.

The Application that is going to be spawning the process
that needs to be in the foreground is an application that
resides in the system tray, therefore it never gets
foreground control itself. How would it get control of
the foreground in this case?

Then you have little chance to bring it to foreground. Just
make it active and system will flash the window in taskbar
to draw user's attention.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Enumerating Windows 5

Top