如何写一个既支持命令行又可以有图形界面的程序呢?谢谢
支持命令行的话可以方便的使用脚本调用
有图形界面的话手动使用的时候方便
我以前用vc写的都是只能命令行或者只有图形界面的。
但是看到一些软件,比如beyondcompare,wireshark啥的都是既有命令行又有图形界面。
使用vc搞这样的程序的话,需要怎么创建工程?
btw:命令行的时候可以不显示图形界面,直接根据命令行参数做一些计算即可,当然,显示图形界面也可以。
[解决办法]
链接参数subsystem,决定了你的程序链接后是什么样的程序:是否有控制台。
但你也可以在运行的时候将控制台的黑框子建立出来,用api函数AllocConsole,具体细节可以参看msdn。
[解决办法]
图形界面程序本来就支持命令行。
GetCommandLine
The GetCommandLine function returns a pointer to the command-line string for the current process.
LPTSTR GetCommandLine(VOID)
Parameters
This function has no parameters.
Return Values
The return value is a pointer to the command-line string for the current process.
Remarks
ANSI console processes written in C can use the argc and argv arguments of the main function to access the command-line arguments. ANSI GUI applications can use the lpCmdLine parameter of the WinMain function to access the command-line string, excluding the program name. The reason that main and WinMain cannot return Unicode strings is that argc, argv, and lpCmdLine use the LPSTR data type for parameters, not the LPTSTR data type. The GetCommandLine function can be used to access Unicode strings, because it uses the LPTSTR data type.
QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in winbase.h.
Import Library: Use kernel32.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows and Windows NT.
See Also
Processes and Threads Overview, Process and Thread Functions, CreateProcess,WinMain