Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2006

Tip: Looking for answers? Try searching our database.

Flash Player Launching Process With CreateProcess

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jay - 09 Jun 2006 15:48 GMT
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)
Jay - 09 Jun 2006 16:10 GMT
> Hey There,
>     I have been writing some code in C++ that gets a message from a
[quoted text clipped - 32 lines]
>   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)
Alex Blekhman - 09 Jun 2006 17:18 GMT
>   For some reason, the EnumWindows Function:
>
[quoted text clipped - 6 lines]
>
> fp = fopen(THREAD_LOG_FILE,APPEND_MODE);

fprintf(fp,"*******************<EnumOpenWindows>************
*******\n");
> fclose(fp);
>
[quoted text clipped - 13 lines]
> fp = fopen(THREAD_LOG_FILE,APPEND_MODE);
> fprintf(fp,"FALSE\n");

fprintf(fp,"*******************</EnumOpenWindows>***********
********\n");
> fclose(fp);
>
[quoted text clipped - 4 lines]
> fp = fopen(THREAD_LOG_FILE,APPEND_MODE);
> fprintf(fp,"TRUE\n");

fprintf(fp,"*******************</EnumOpenWindows>***********
********\n");
> fclose(fp);
>
[quoted text clipped - 5 lines]
> 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.
Alex Blekhman - 09 Jun 2006 17:11 GMT
> Hey There,
>     I have been writing some code in C++ that gets a
[quoted text clipped - 5 lines]
>
> retVal =

CreateProcess(NULL,modName,NULL,NULL,FALSE,NULL,NULL,NULL,&s
i,&pi);
> hProc = pi.hProcess;
> procID = pi.dwProcessId;
[quoted text clipped - 4 lines]
> fclose(fp);
> WaitForInputIdle(hProc,INFINITE);

EnumWindows((WNDENUMPROC)EnumOpenWindows,(LPARAM)&HPStruct);
> fp = fopen(THREAD_LOG_FILE,"a+");
> fprintf(fp,"After EnumWindows \n");
[quoted text clipped - 10 lines]
> 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
Jay - 12 Jun 2006 16:48 GMT
> > Hey There,
> >     I have been writing some code in C++ that gets a
[quoted text clipped - 42 lines]
> 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)
Alex Blekhman - 12 Jun 2006 17:30 GMT
>    I tried to implement the suggestion you made, by
> inserting the code for the foreground window, as shown
[quoted text clipped - 4 lines]
> 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.
Jay - 12 Jun 2006 21:51 GMT
> >    I tried to implement the suggestion you made, by
> > inserting the code for the foreground window, as shown
[quoted text clipped - 7 lines]
> 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)
Alex Blekhman - 13 Jun 2006 11:17 GMT
>>>    I tried to implement the suggestion you made, by
>>> inserting the code for the foreground window, as shown
[quoted text clipped - 13 lines]
> 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.
Tamas Demjen - 09 Jun 2006 19:06 GMT
> 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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.