Solved

Create a TopMost Process

Posted on 1998-07-19
9
982 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
 

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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

16 Experts available now in Live!

Get 1:1 Help Now