给命令行做一个GUI,Qt能实现这个功能吗?
最近在CSDN上看到一个小软件,给命令行(cmd)做一个GUI
地址:http://topic.csdn.net/u/20120630/19/C3D46E45-72AB-4278-9C87-EB6B88038B95.html
现在我想问一下,这个功能Qt能实现吗?如果可以,就介绍一下思路吧,大家共同学习学习。
[解决办法]
他那个是C#做的,Qt也能,和那个一样的很好做,用QProcess调用系统命令
但是要做一个和windows命令行一模一样的可费劲了,我记得dbzhang800好像做过一个。
[解决办法]
cd 是 cmd 的内置命令,自然是传给 cmd.exe 处理
因为是子进程执行命令,原始进程的当前工作目录没有改变
[解决办法]
哎,这个其实就是输入输出流重定向嘛,你可以搜一下io重定向,把cmd上的输出重定向到gui上,或者文件里,或者重定向到别的地方,其实流程大概就是这样
输入命令 -> 传给cmd.exe -> 把cmd.exe的输出重定向到gui窗口上。这就使得cmd上的东西能显示在某个窗口上了
[解决办法]
那个cd xxx就是用户输入的一个字符串,直接做为参数传给CMD处理,所谓界面,不过是获取CMD输出以显示
楼主钻了牛角尖了。 并不是真的自己编写了个cd命令(当然你也可以一个个命令写,但不是需要讨论的)
[解决办法]
对于 .net, java 等人,他们觉得很神秘?
其实,就是个 win32 c/c++的基础知识, createprocess 的基本参数
win 32 api
CreateProcess
参数 lpStartupInfo
typedef struct _STARTUPINFO {
DWORD cb;
LPTSTR lpReserved;
LPTSTR lpDesktop;
LPTSTR lpTitle;
DWORD dwX;
DWORD dwY;
DWORD dwXSize;
DWORD dwYSize;
DWORD dwXCountChars;
DWORD dwYCountChars;
DWORD dwFillAttribute;
DWORD dwFlags;
WORD wShowWindow;
WORD cbReserved2;
LPBYTE lpReserved2;
HANDLE hStdInput;
HANDLE hStdOutput;
HANDLE hStdError;
} STARTUPINFO, *LPSTARTUPINFO;
hStdInput
If dwFlags specifies STARTF_USESTDHANDLES, this member is the standard input handle for the process. If STARTF_USESTDHANDLES is not specified, the default for standard input is the keyboard buffer.
If dwFlags specifies STARTF_USEHOTKEY, this member specifies a hotkey value that is sent as the wParam parameter of a WM_SETHOTKEY message to the first eligible top-level window created by the application that owns the process. If the window is created with the WS_POPUP window style, it is not eligible unless the WS_EX_APPWINDOW extended window style is also set. For more information, see CreateWindowEx.
Otherwise, this member is ignored.
hStdOutput
If dwFlags specifies STARTF_USESTDHANDLES, this member is the standard output handle for the process. Otherwise, this member is ignored and the default for standard output is the console window's buffer.
If a process is launched from the taskbar or jump list, the system sets hStdOutput to a handle to the monitor that contains the taskbar or jump list used to launch the process. For more information, see Remarks.
Windows 7, Windows Server 2008 R2, Windows Vista, Windows Server 2008, Windows XP, and Windows Server 2003: This behavior was introduced in Windows 8 and Windows Server 2012.
hStdError
If dwFlags specifies STARTF_USESTDHANDLES, this member is the standard error handle for the process. Otherwise, this member is ignored and the default for standard error is the console window's buffer.
[解决办法]