• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1034
  • Last Modified:

Create a TopMost Process

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
khaledo
Asked:
khaledo
  • 3
  • 3
  • 2
  • +1
1 Solution
 
chensuCommented:
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
 
khaledoAuthor Commented:
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
 
LuLucCommented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
khaledoAuthor Commented:
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
 
LuLucCommented:
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
 
wizard2072098Commented:
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
 
chensuCommented:
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
 
khaledoAuthor Commented:
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
 
chensuCommented:
No need. Save your points for your next question. Thank you.
0

Featured Post

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!

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now