Solved

Create a TopMost Process

Posted on 1998-07-19
9
1,008 Views
Last Modified: 2013-11-20
How to creat a process that makes its window a TopMost?

I know that I can search for the window handle from the proces ID then I can make it a TopMost. But I want to know if there is a direct way to set this property (TopMost) during the process creation without windows-searching method?

Thanks
0
Comment
Question by:khaledo
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1319456
If you are using CreateProcess and want the window to maintain its topmost position even when it is deactivated, there is no direct way to do it. Because topmost is a style of a window, not a process.
0
 

Author Comment

by:khaledo
ID: 1319457
Thanks for the answer BUT  my window is activated and I want to _force_ it to the TopMost style (not to maintain its topmost when it is deactivated.

I understand that TopMost is a Window style , not a process one, but in the process STARTUPINFO structure we can set the window's position, size and some style like maximized, minimized, hidden...etc. I was wondering why not the TopMost property. Did I overlooked this somehow? I will accept your answer if you confirm that Window-searching method is the only way to do it after I create process.
 
Thanks
0
 

Expert Comment

by:LuLuc
ID: 1319458
I think you can use the SetWindowPos function in the InitInstance of the Process :


m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->SetWindowPos(&CWnd::wndTopMost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); // You have to add this line...
m_pMainWnd->UpdateWindow();

The second statement specify that the Window becomes TopMost, without changing any of its coordinates...

I actually think you can do that whenever you have the handle of the window you want to make topmost.

Hope it helps...

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:khaledo
ID: 1319459
Thanks for the answer. BUT
I am creating a separate process using CreateProcess from my application. I do not have the new process's Window handle. I want to make the new process's Window TopMost. Is there any way to do that without searching for the new process Window handle??
0
 

Accepted Solution

by:
LuLuc earned 100 total points
ID: 1319460
OK, That was unclear for me that you wanted to do that FROM an other process. Now I understand. Here is a small section of code that you can use to search the windows on your desktop. I compiled it in C++ but it actually uses Win32 calls.


  HWND hwndNext;
  HWND hwndDesktop;
  CHAR szTitle[100];

  hwndDesktop=::GetDesktopWindow();
  hwndNext=::GetWindow(hwndDesktop, GW_CHILD);

  hwndNext=::GetNextWindow(hwndNext, GW_HWNDNEXT);
  while (hwndNext!=NULL)
  {
    hwndNext=::GetNextWindow(hwndNext, GW_HWNDNEXT);
    ::GetWindowText(hwndNext, szTitle, sizeof(szTitle));

    if (strstr(strupr(szTitle), "NETSCAPE")!=NULL)
      ::SetWindowPos(hwndNext, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
  }

I first retrieve the Desktop window Handle and I also get the handle of a child window of this desktop.
I then go through all the windows of the desktop and search for the text "NETSCAPE" (you can have some other criteria if you want). When the text is found, it sets the window as topmost.

Be careful because you can find also hidden windows having a caption. You then have to know exactly which window you want to work on.

LuLuc

0
 
LVL 1

Expert Comment

by:wizard2072098
ID: 1319461
If I read your question correctly, you want the be able to specify a window to DEFAULT as the topmost during the execution of CreateProcess.

You cannot set a window to topmost when there is no window.
The startup position and size of a window in the CreateProcess method are NOT dependent upon having an actual window on the screen since size and placement are arbitrary numbers. setting a window to be topmost requires the window to be moved to the top of the Z-Order and therefore requires, well, a window.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1319462
I am confused. What exactly do you want to do? It seems that you just want the window to be active when it is created. The users  may switch to other applications, in which case the window is not topmost any more. Currently the window seems to be covered by the other windows when it is created. Right? Specify dwFlags = STARTF_USESHOWWINDOW and wShowWindow = SW_SHOWNORMAL for the STARTUPINFO structure.
0
 

Author Comment

by:khaledo
ID: 1319463
Thanks a lot to Chensu and wizard2. In fact I wanted to make the window TopMost not just SW_SHOWNORMAL. Chensu's first answer was the correct one. Also the commment by Wizard2 made it clear that I cannot make the window TopMost before creating it. I accepted LuLuc answer becasue he confirmed that I must search for the new process's Window anyway. That was the solution I was trying to avoid from the begining but it seems to be the only one.
Both  Chensu and wizard2 deserve my thanks and credits for clearing things up. Is there a way to pass credits to Chensu who gave me the correct answer from the begining?
0
 
LVL 23

Expert Comment

by:chensu
ID: 1319464
No need. Save your points for your next question. Thank you.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

756 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