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
Solved

Create a TopMost Process

Posted on 1998-07-19
9
1,002 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 163
deburging in oracle form 12 104
substring method in java 1 129
how to use laptop or pad camera in vb.net windows application 2 85
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…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.

809 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