使用C ++最小化过程 [英] Minimize process with C++

查看:96
本文介绍了使用C ++最小化过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨.我正在尝试创建一个程序,以最小化某些特定过程,例如记事本".我正在使用GetProcessesByName函数,但出现错误.
它说该函数未声明,但我遵循了msdn上的所有内容.

您能帮助我解决该错误,还是说如何创建该程序,我应该使用什么功能?

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?

推荐答案

我认为您想最小化一个窗口,而不是一个过程.每个窗口都属于一个进程,并且属于指定进程内的线程和模块.普通的gui程序使用相同的线程和模块(HINSTANCE)创建所有gui元素.一个进程可以有多个窗口,在您的情况下,我们只有一个.我认为GetProcessByName()仅适用于.net应用程序.在纯Win32中,我将使用FindWindow()或FindWindowEx()来完成这项工作.使用这些功能,您可以按名称或窗口类别(或两者)搜索窗口.由于窗口名称(标题)是变量,因此我仅按窗口类进行搜索.要查找记事本的窗口类,请启动它,然后启动作为Visual Studio工具提供的Spy ++,然后在工具栏中单击其双目图标.在弹出的对话框中,用鼠标左键将十字准线移至记事本的标题栏,然后按OK.确保首先启动记事本,否则必须按F5引用spy ++的捕获数据.这样,您可以从桌面上的任何窗口中找到很多信息.在我的机器上(可能也在您的机器上),记事本窗口的类名是记事本".因此,首先调用FindWindow("Notepad",NULL),如果成功,您可以在窗口上使用SW_MINIMIZE参数调用ShowWindow().如果要处理多个记事本窗口,请使用可用于迭代的FindWindowEx().

注意:如果要查找创建窗口的进程的ID,以及进程内部的线程的ID,请调用GetWindowThreadProcessId().如果您需要处理的句柄,则使用进程ID调用OpenProcess().
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.


谢谢,实际上,我花了很长时间才找到解决方法.
我成功了.
Thank you, I actually found solution by my self after some quite long time.
I succeeded with this.
#include <iostream>
#include <windows.h>

int main()
{
    ShowWindow(FindWindow(NULL, "Untitled - Notepad"), SW_MINIMIZE);
    return 0;
}


这篇关于使用C ++最小化过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆