如何使用参数?

发布于 2024-09-24 16:54:32 字数 4120 浏览 2 评论 0 原文

我在 Visual Studio C++ 2010 Express 中生成了两个文件。

test2.cpp

// test2.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"

using namespace test2;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false); 

// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}

和 Form1.h

#pragma once

namespace test2 {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
    Form1(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //
    }

protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~Form1()
    {
        if (components)
        {
            delete components;
        }
    }
private: System::Windows::Forms::WebBrowser^  webBrowser1;
public: System::Windows::Forms::Timer^  timer1;
private: 

private: System::ComponentModel::IContainer^  components;
protected: 

private:
    /// <summary>
    /// Required designer variable.
    /// </summary>


#pragma region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    void InitializeComponent(void)
    {
        this->components = (gcnew System::ComponentModel::Container());
        this->webBrowser1 = (gcnew System::Windows::Forms::WebBrowser());
        this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
        this->SuspendLayout();
        // 
        // webBrowser1
        // 
        this->webBrowser1->Dock = System::Windows::Forms::DockStyle::Fill;
        this->webBrowser1->IsWebBrowserContextMenuEnabled = false;
        this->webBrowser1->Location = System::Drawing::Point(0, 0);
        this->webBrowser1->MinimumSize = System::Drawing::Size(20, 20);
        this->webBrowser1->Name = L"webBrowser1";
        this->webBrowser1->ScrollBarsEnabled = false;
        this->webBrowser1->Size = System::Drawing::Size(284, 262);
        this->webBrowser1->TabIndex = 0;
        this->webBrowser1->Url = (gcnew System::Uri(L"http://wp.pl", System::UriKind::Absolute));
        this->webBrowser1->DocumentCompleted += gcnew System::Windows::Forms::WebBrowserDocumentCompletedEventHandler(this, &Form1::webBrowser1_DocumentCompleted);
        // 
        // timer1
        // 
        this->timer1->Enabled = true;
        this->timer1->Interval = 10000;
        this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
        // 
        // Form1
        // 
        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->ClientSize = System::Drawing::Size(284, 262);
        this->Controls->Add(this->webBrowser1);
        this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
        this->Name = L"Form1";
        this->ResumeLayout(false);

    }
#pragma endregion
private: System::Void webBrowser1_DocumentCompleted(System::Object^  sender, System::Windows::Forms::WebBrowserDocumentCompletedEventArgs^  e) {
         }
public: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
            Application::Exit();
         }
};
}

如何使用命令提示符中的参数?例如如何更改

this->timer1->Interval = 10000;

用户 var?像这样的东西

this->timer1->Interval = time;

I have two file generated in visual studio c++ 2010 express.

test2.cpp

// test2.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"

using namespace test2;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false); 

// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}

and Form1.h

#pragma once

namespace test2 {

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
    Form1(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //
    }

protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~Form1()
    {
        if (components)
        {
            delete components;
        }
    }
private: System::Windows::Forms::WebBrowser^  webBrowser1;
public: System::Windows::Forms::Timer^  timer1;
private: 

private: System::ComponentModel::IContainer^  components;
protected: 

private:
    /// <summary>
    /// Required designer variable.
    /// </summary>


#pragma region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    void InitializeComponent(void)
    {
        this->components = (gcnew System::ComponentModel::Container());
        this->webBrowser1 = (gcnew System::Windows::Forms::WebBrowser());
        this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
        this->SuspendLayout();
        // 
        // webBrowser1
        // 
        this->webBrowser1->Dock = System::Windows::Forms::DockStyle::Fill;
        this->webBrowser1->IsWebBrowserContextMenuEnabled = false;
        this->webBrowser1->Location = System::Drawing::Point(0, 0);
        this->webBrowser1->MinimumSize = System::Drawing::Size(20, 20);
        this->webBrowser1->Name = L"webBrowser1";
        this->webBrowser1->ScrollBarsEnabled = false;
        this->webBrowser1->Size = System::Drawing::Size(284, 262);
        this->webBrowser1->TabIndex = 0;
        this->webBrowser1->Url = (gcnew System::Uri(L"http://wp.pl", System::UriKind::Absolute));
        this->webBrowser1->DocumentCompleted += gcnew System::Windows::Forms::WebBrowserDocumentCompletedEventHandler(this, &Form1::webBrowser1_DocumentCompleted);
        // 
        // timer1
        // 
        this->timer1->Enabled = true;
        this->timer1->Interval = 10000;
        this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
        // 
        // Form1
        // 
        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->ClientSize = System::Drawing::Size(284, 262);
        this->Controls->Add(this->webBrowser1);
        this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
        this->Name = L"Form1";
        this->ResumeLayout(false);

    }
#pragma endregion
private: System::Void webBrowser1_DocumentCompleted(System::Object^  sender, System::Windows::Forms::WebBrowserDocumentCompletedEventArgs^  e) {
         }
public: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
            Application::Exit();
         }
};
}

How to using argument from command prompt? For example how change

this->timer1->Interval = 10000;

on user var? Something like

this->timer1->Interval = time;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧人 2024-10-01 16:54:32

You can get a string array containing the command-line arguments by calling Environment::GetCommandLineArgs.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文