Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
Hi. I am trying to create a program that will minimize some specific process for example "notepad". I am using GetProcessesByName function but I am getting an error.
It says that that function is undeclared but I followd everything on msdn.

Can you help me with that error, or say how to create that program, what function should I use?
Posted
Comments
Sergey Alexandrovich Kryukov 1-Aug-12 12:21pm    
What does it mean: "minimize process"? Minimize to what?
GetProcessesByName works properly. Your "but I am getting an error" is not informative. Create a complete but minimal code sample, focusing on GetProcessesByName problem only, make sure it reproduces the problem. Post it using "Improve question" above.

Is it System.Diagnostics.Process.GetProcessesByName (then this is .NET, and not exactly C++ but C++/CLI, and not directly related to "Win32", so makes sure to change your tags if so)?
--SA

I think you want to minimize a window, and not a process. each window belongs to a process, and to a thread and a module inside the specified process. An ordinary gui program creates all gui elements using the same thread and module (HINSTANCE). A single process can have multiple windows, in your case we have only one. I think GetProcessByName() works only with .net apps. In pure win32 I would use FindWindow() or FindWindowEx() to do the job. With these functions you can search for windows by name or by window class or by both. Since the window name (title) is variable I would search only by window class. To find out the window class of notepad start it, plus launch Spy++ that comes as a visual studio tool and click its binocular icon in the toolbar. In the dialog that pops up grab the crosshair to with left mouse button to the titlebar of the notepad and then press OK. Make sure that you launch notepad first, otherwise you have to referesh the captured data of spy++ by pressing F5. This way you can find out a lot of info from any window on your desktop. On my machine (and probably on yours too) the classname of the notepad window is "Notepad". So first call FindWindow("Notepad", NULL), and if it succeeds you can call ShowWindow() with SW_MINIMIZE parameter on the window. If you want to handle multiple notepad windows then use FindWindowEx() which can be used to iterate.

Note: If you want to find out of the id of the process that created the window, and the id of the thread inside the process then call GetWindowThreadProcessId(). If you need a handle to the process then call OpenProcess() with the process id.
 
Share this answer
 
Thank you, I actually found solution by my self after some quite long time.
I succeeded with this.
XML
#include <iostream>
#include <windows.h>

int main()
{
    ShowWindow(FindWindow(NULL, "Untitled - Notepad"), SW_MINIMIZE);
    return 0;
}
 
Share this answer
 
Comments
pasztorpisti 1-Aug-12 13:05pm    
This solution won't always work. Use ShowWindow(FindWindow("Notepad", NULL), SW_MINIMIZE) instead. On my machine there is a hungarian XP and the title of a newly opened notepad is "Névtelen - Notepad". And this title changes if you open a text file or save a new one.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900