Solved

ShellExecute Open Document - How to pop on top?

Posted on 2016-09-04
3
11 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
Comment Utility
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
Comment Utility
Didn't try your solution - had already found another way before  you posted -- but thanks!
0
 
LVL 13

Expert Comment

by:frankhelk
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now