Solved

ShellExecute Open Document - How to pop on top?

Posted on 2016-09-04
3
41 Views
Last Modified: 2016-11-29
I am using ShellExecute  with verb "open" to show *.txt files and *.pdf files.   I have been doing this forever, and was simple and worked fine.  Recently I changed some of the architecture of my application ( MFC, C++, VS2015 ) in that certain panels are Modal, others non-Modal, and I have various situations like "a Modal that is a child of a non-Modal" and so forth.   Now when I do a ShellExecute, the document is not on top -- its 'under' one or more of the screens of my app.  So, I've tried a few things to make it pop on top, like:

Instead of:
HINSTANCE h = ShellExecute(NULL, _T("open"), doc, NULL, NULL, SW_SHOWNORMAL);

I tried:
HWND hwnd = this->GetSafeHwnd();
HINSTANCE h = ShellExecute(hwnd, _T("open"), doc, NULL, NULL, SW_SHOWNORMAL);

( and in the above, instead of "this" which is the currently-open Modal panel, I tried passing its non-modal parent panel, and other guesses)

I also tried:
HINSTANCE h = ShellExecute(HWND_TOPMOST, _T("open"), doc, NULL, NULL, SW_SHOWNORMAL);

But in all cases, the document opens behind my full-screen panel or its parent, and can't be seen.

Is there some way to make the thing pop up 'top-most' ?
0
Comment
Question by:tullhead
3 Comments
 
LVL 15

Accepted Solution

by:
Minh Võ Công earned 500 total points
ID: 41864867
You can use ShellExecuteEx to create process and use SetForegroundWindow, SetActiveWindow to bring the window to top z order.

http://stackoverflow.com/questions/17166178/shell-execute-bring-window-to-front
0
 

Author Comment

by:tullhead
ID: 41870676
Didn't try your solution - had already found another way before  you posted -- but thanks!
0
 
LVL 14

Expert Comment

by:frankhelk
ID: 41905418
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: Minh Võ Công (https:#a41864867)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

frankhelk
Experts-Exchange Cleanup Volunteer
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
returning a dereferenced pts in C++ 10 165
C++ BOOL WINAPI ReadFile fails on windows 10 when reading from USB cable 9 511
computer science syllabus 3 100
c++ syntax question 9 57
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question