?
Solved

Create a TopMost Process

Posted on 1998-07-19
9
Medium Priority
?
1,022 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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 300 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

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!

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

801 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