c++ - 用 Windows 窗体替换控制台窗口

标签 c++ winforms

我已经在 Visual Studio 2012 C++ 中创建了一个 Win32 控制台应用程序项目。

如何用更吸引人的 GUI(如 Windows 窗体)替代控制台窗口?

int32_t main(int32_t argc, char* argv[])
{
const char *date = "20150428_1\\";
int     mode=0; 
_CallServerPtr      pCallServer;
uint32_t start_address_comp=0;
uint32_t start_address_module=0;
const char*  xmlFile_tx_dbb="tx_dbb.xml";;
char str[100] = "\0";
char localeStr[64];
memset(localeStr, 0, sizeof localeStr);
const char *l_path = "..\\XERCES\\Configs\\";
std::string buf = "";
double Fsym_Hz=(1/1.15)*1e9;
int selection=0;
int user_selection=0;


try
{
    if (strlen(localeStr))
    {
        XMLPlatformUtils::Initialize(localeStr);
    }
    else
    {
        XMLPlatformUtils::Initialize();
    }
}

catch (const XMLException& toCatch)
{
     XERCES_STD_QUALIFIER cerr << "Error during initialization! :\n"
          << StrX(toCatch.getMessage()) << XERCES_STD_QUALIFIER endl;
}


static const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };

DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(gLS);
DOMLSParser       *parser = ((DOMImplementationLS*)impl)->createLSParser(DOMImplementationLS::MODE_SYNCHRONOUS, 0);
DOMConfiguration  *config = parser->getDomConfig();
DOMLSSerializer   *theSerializer = ((DOMImplementationLS*)impl)->createLSSerializer();
DOMLSOutput       *theOutputDesc = ((DOMImplementationLS*)impl)->createLSOutput();



config->setParameter(XMLUni::fgDOMDatatypeNormalization, true);


DOMCountErrorHandler errorHandler;
config->setParameter(XMLUni::fgDOMErrorHandler, &errorHandler);
XERCES_STD_QUALIFIER ifstream fin;

//reset error count first
 errorHandler.resetErrors();*/

 // reset document pool
 parser->resetDocumentPool();


char* pszHostname = NULL;
pSaIn  = 0;
pSaOut = 0;

// Initialize the COM Library
CoInitialize(NULL);


    if (!pszHostname)
    {
        // Create the CallServer server object on the local computer
        pCallServer.CreateInstance(CLSID_CallServer);
    }

    if (pCallServer == NULL)
        throw "Failed to create the CallableVEE CallServer object";


// Load the VEE User Function library
    char strpath[256];
    strcpy (strpath,reposity_path);
    strcat (strpath,l_path_vee);

    _bstr_t bstrLibPath(strpath);
    LibraryPtr pLib = pCallServer->GetLibraries()->Load(bstrLibPath);
    // Print out the names of the UserFunctions in this library.
    UserFunctionsPtr pUserFuncColl = pLib->GetUserFunctions();

    VARIANT_BOOL bDebug = VARIANT_FALSE;

    pCallServer->PutDebug(bDebug);


    // Variables added by ivi
    float *freq =(float *)_aligned_malloc(6,16); // Read frequency vector
    // Previous variables
    int32_t devIdx;
    int32_t modeClock;
    int32_t ifType;
    const char *devType;
    char fpga_device_type[32];
    int32_t rc;
    int32_t ref_clk=0;
    uint32_t carrier=0;
    uint32_t odelay_dac0 = 0;
    uint32_t odelay_dac1 = 0;




    // Parse the application arguments
    if(argc!=5) {
            printf("Usage: FMCxxxApp.exe {interface type} {device type} {device index} {clock mode} \n\n");
            printf(" {interface type} can be either 0 (PCI) or 1 (Ethernet). At CEIT, we use 1 (Ethernet).\n");
            printf(" {device type} is a string defining the target hardware (VP680, ML605, ...). At CEIT, we use VC707.\n");
            printf(" {device index} is a PCI index or an Ethernet interface index. This value depends on the PC.\n");
            printf(" {clock mode} can be either 0 (Int. Clock) or 1 (Ext. Clock)\n");
            printf("\n");
            printf("\n");
            printf("Example: Fmc230APP.exe 1 VC707 0 0\n");
            printf("\n");
            printf("\n");
            printf(" List of NDIS interfaces found in the system {device index}:\n");
            printf(" -----------------------------------------------------------\n");
            if(sipif_getdeviceenumeration(API_ENUM_DISPLAY)!=SIPIF_ERR_OK) {
                    printf("Could not obtain NDIS(Ethernet) device enumeration...\n Check if the 4dspnet driver installed or if the service started?\n");
                    printf("You can discard this error if you do not have any Ethernet based product in use.");
            }

            if( EXIT_IF_ERRORS)
            {
                sipif_free();
                system("pause");
                return -1;
            }
         ...
  }  

最佳答案

您的意思是在 Windows 窗体中具有相同的代码。那行不通的。 printf 和其他命令只能在控制台应用程序中使用。您必须创建一个 Windows 窗体应用程序并为其重写代码。您必须重写所有在 Windows 窗体应用程序中不起作用的命令。可能存在一个转换应用程序,但对于这个简短的代码,我认为重写它会更好。

关于c++ - 用 Windows 窗体替换控制台窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31097820/

相关文章:

c# - 使用 C# .net 检测进程已在 Windows 中运行

c# - 使用 WinForms 绘制宽线时出现 OutOfMemoryException

.net - 如何检查是否安装了 .NET Framework

c++ - 使用从列表中弹出的 pthreads 填充大小的列表

c++ - 关于 C++ 自动完成的 Eclipse CDT 文档

C++ 性能挑战:整数到 std::string 的转换

c++ - 如何让 CMake 在 Mac OS X 上使用 GCC 而不是 Clang?

c++ - 使用 STL 列表获取最高值

c# - 从包含在 using 语句中的另一个类中检索数据的正确方法

.net - 在 TextBox 中 Windows 窗体滚动日志输出的最佳方法