从另一个CPP文件向表单添加列表项[C ++ / CLI]

时间:2015-07-14 12:54:19

标签: winforms visual-studio-2010 c++-cli

我已经获得了一个项目,并且我已经被困了2天试图搞清楚。

我有一个读取和写入端口的CPP文件(base_station.cpp)。我想在创建的表单列表框(actionLogBox)上显示信息。我想要将项添加到的行(base_station.cpp):

actionLogBox->AddString("Attempting Pin");

base_staion.cpp

/*********************
*   base_station.cpp
*   base_station.cpp holds the implementation for each individual
*   function that applies to the base station.  For a better understanding
*   of each function, please, see reference the desired function.
*********************/
#pragma once
#include "mainForm.h"
#include "stdafx.h"

/*  base station functionality  */
#include "base_station.h"

/*  used for serial (comm) port functionality   */
#include "serial.h"


/***********************
*   bs_ping
*   bs_ping attempts to ping the base station attached to the given
*   port handle, hPort.
*   Command Format
*       Length:     1 byte
*       Byte 1:     0x01
*   Good Response:
*       Length:     1 byte
*       Byte 1:     0x01
*   PRE:    hPort is a legitimate, open, port handle of type HANDLE
*   POST:   if successful, 0 is returned
*           otherwise, some error code
***********************/

int bs_ping(/* in */ HANDLE hPort)
{


    TRACE("bs_ping()\n");
    unsigned char   ucCmd = 0x01,   //  command to send
        ucResponse;     //  holds the response
    DWORD   dwBytes_written = 0,    //  number of bytes written to the port
        dwBytes_read = 0;       //  number of bytes read from the port
    int iResult,                    //  return value of port read/write functions
        iPos;                       //  position in the console that the command was written to
    CString strFormat;              //  formatted string for output to command information window
    /*  send the 0x01 command to the serial port    */
    if ((iResult = port_write(hPort, &ucCmd, 1, dwBytes_written, iPos)) != 0)
        return iResult;


    /*  append to the command description   */
    //strFormat.Format("Attempt to ping base station on port handle %i.\r\nCommand Byte: %#04x",
    //  hPort, ucCmd);
    //strCmd_info[iPos] = strFormat;
    actionLogBox->AddString("Attempting Pin"); /*Here is the line that adds the string to the listbox*/



    /*  attempt to read the correct response, 0x01, from the serial port    */
    if ((iResult = port_read(hPort, &ucResponse, 1, dwBytes_read, iPos)) != 0)
        return iResult;

    if (ucResponse != 0x01) {
        /*  append to the command description   */
        //strFormat.Format("Attempt to ping base station on port handle %i.", hPort);
        //strCmd_info[iPos] = strFormat;
        //return ERROR_INVALID_RESPONSE;
    }

    //strFormat.Format("Attempt to ping base station on port handle %i.", hPort);
    //strCmd_info[iPos] = strFormat;

    return 0;
}

mainForm.h

#pragma once
# include "stdafx.h"
# include "addBase.h"
# include "serial.h"
#include "base_station.h"

namespace WCM {

    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 mainForm
    /// </summary>
    public ref class mainForm : public System::Windows::Forms::Form
    {
    public:
        mainForm(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~mainForm()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::MenuStrip^  menuStrip1;
    private: System::Windows::Forms::ToolStripMenuItem^  fileMenuItem;
    private: System::Windows::Forms::ToolStripMenuItem^  expDataDirMenuItem;
    private: System::Windows::Forms::ToolStripMenuItem^  uploadDataMenuItem;
    private: System::Windows::Forms::ToolStripMenuItem^  exitMenuItem;
    private: System::Windows::Forms::ToolStripMenuItem^  editMenuItem;
    private: System::Windows::Forms::ToolStripMenuItem^  prefMenuItem;
    private: System::Windows::Forms::ToolStripMenuItem^  helpMenuItem;
    private: System::Windows::Forms::ToolStripMenuItem^  aboutMenuItem;
    private: System::Windows::Forms::ToolStrip^  toolStrip1;
    private: System::Windows::Forms::ToolStripDropDownButton^  addBaseButton;
    private: System::Windows::Forms::ToolStripMenuItem^  scanPortsMenuItem;
    private: System::Windows::Forms::ToolStripMenuItem^  addBaseMenuItem;
    private: System::Windows::Forms::ToolStripDropDownButton^  addNodesButton;
    private: System::Windows::Forms::ToolStripMenuItem^  nodeDiscMenuItem;
    private: System::Windows::Forms::ToolStripMenuItem^  addNodeMenuItem;
    private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator1;
    private: System::Windows::Forms::ToolStripButton^  nodesInfoButton;
    private: System::Windows::Forms::ToolStripButton^  nodesConfigButton;
    private: System::Windows::Forms::GroupBox^  bottomBox;
    private: System::Windows::Forms::ListBox^  actionLogBox;
    private: System::Windows::Forms::ListBox^  baseStationBox;
    private: System::Windows::Forms::GroupBox^  sideBox;
    protected:

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container ^components;





#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)
        {
            System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(mainForm::typeid));
            this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
            this->fileMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->expDataDirMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->uploadDataMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->exitMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->editMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->prefMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->helpMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->aboutMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->toolStrip1 = (gcnew System::Windows::Forms::ToolStrip());
            this->addBaseButton = (gcnew System::Windows::Forms::ToolStripDropDownButton());
            this->scanPortsMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->addBaseMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->addNodesButton = (gcnew System::Windows::Forms::ToolStripDropDownButton());
            this->nodeDiscMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->addNodeMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
            this->toolStripSeparator1 = (gcnew System::Windows::Forms::ToolStripSeparator());
            this->nodesInfoButton = (gcnew System::Windows::Forms::ToolStripButton());
            this->nodesConfigButton = (gcnew System::Windows::Forms::ToolStripButton());
            this->bottomBox = (gcnew System::Windows::Forms::GroupBox());
            this->actionLogBox = (gcnew System::Windows::Forms::ListBox());
            this->baseStationBox = (gcnew System::Windows::Forms::ListBox());
            this->sideBox = (gcnew System::Windows::Forms::GroupBox());
            this->menuStrip1->SuspendLayout();
            this->toolStrip1->SuspendLayout();
            this->bottomBox->SuspendLayout();
            this->sideBox->SuspendLayout();
            this->SuspendLayout();
            // 
            // menuStrip1
            // 
            this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(3) {
                this->fileMenuItem, this->editMenuItem,
                    this->helpMenuItem
            });
            this->menuStrip1->Location = System::Drawing::Point(0, 0);
            this->menuStrip1->Name = L"menuStrip1";
            this->menuStrip1->Size = System::Drawing::Size(638, 24);
            this->menuStrip1->TabIndex = 0;
            this->menuStrip1->Text = L"menuStrip1";
            // 
            // fileMenuItem
            // 
            this->fileMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(3) {
                this->expDataDirMenuItem,
                    this->uploadDataMenuItem, this->exitMenuItem
            });
            this->fileMenuItem->Name = L"fileMenuItem";
            this->fileMenuItem->Size = System::Drawing::Size(37, 20);
            this->fileMenuItem->Text = L"File";
            // 
            // expDataDirMenuItem
            // 
            this->expDataDirMenuItem->Name = L"expDataDirMenuItem";
            this->expDataDirMenuItem->Size = System::Drawing::Size(190, 22);
            this->expDataDirMenuItem->Text = L"Explore Data Directory";
            // 
            // uploadDataMenuItem
            // 
            this->uploadDataMenuItem->Name = L"uploadDataMenuItem";
            this->uploadDataMenuItem->Size = System::Drawing::Size(190, 22);
            this->uploadDataMenuItem->Text = L"Upload Data";
            // 
            // exitMenuItem
            // 
            this->exitMenuItem->Name = L"exitMenuItem";
            this->exitMenuItem->Size = System::Drawing::Size(190, 22);
            this->exitMenuItem->Text = L"Exit";
            // 
            // editMenuItem
            // 
            this->editMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) { this->prefMenuItem });
            this->editMenuItem->Name = L"editMenuItem";
            this->editMenuItem->Size = System::Drawing::Size(39, 20);
            this->editMenuItem->Text = L"Edit";
            // 
            // prefMenuItem
            // 
            this->prefMenuItem->Name = L"prefMenuItem";
            this->prefMenuItem->Size = System::Drawing::Size(135, 22);
            this->prefMenuItem->Text = L"Preferences";
            // 
            // helpMenuItem
            // 
            this->helpMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) { this->aboutMenuItem });
            this->helpMenuItem->Name = L"helpMenuItem";
            this->helpMenuItem->Size = System::Drawing::Size(44, 20);
            this->helpMenuItem->Text = L"Help";
            // 
            // aboutMenuItem
            // 
            this->aboutMenuItem->Name = L"aboutMenuItem";
            this->aboutMenuItem->Size = System::Drawing::Size(107, 22);
            this->aboutMenuItem->Text = L"About";
            // 
            // toolStrip1
            // 
            this->toolStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(5) {
                this->addBaseButton, this->addNodesButton,
                    this->toolStripSeparator1, this->nodesInfoButton, this->nodesConfigButton
            });
            this->toolStrip1->Location = System::Drawing::Point(0, 24);
            this->toolStrip1->Name = L"toolStrip1";
            this->toolStrip1->Size = System::Drawing::Size(638, 25);
            this->toolStrip1->TabIndex = 1;
            this->toolStrip1->Text = L"toolStrip1";
            // 
            // addBaseButton
            // 
            this->addBaseButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
            this->addBaseButton->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {
                this->scanPortsMenuItem,
                    this->addBaseMenuItem
            });
            this->addBaseButton->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"addBaseButton.Image")));
            this->addBaseButton->ImageTransparentColor = System::Drawing::Color::Magenta;
            this->addBaseButton->Name = L"addBaseButton";
            this->addBaseButton->Size = System::Drawing::Size(29, 22);
            this->addBaseButton->Text = L"Add Base";
            // 
            // scanPortsMenuItem
            // 
            this->scanPortsMenuItem->Name = L"scanPortsMenuItem";
            this->scanPortsMenuItem->Size = System::Drawing::Size(129, 22);
            this->scanPortsMenuItem->Text = L"Scan Ports";
            // 
            // addBaseMenuItem
            // 
            this->addBaseMenuItem->Name = L"addBaseMenuItem";
            this->addBaseMenuItem->Size = System::Drawing::Size(129, 22);
            this->addBaseMenuItem->Text = L"Add Base";
            this->addBaseMenuItem->Click += gcnew System::EventHandler(this, &mainForm::addBaseMenuItem_Click);
            // 
            // addNodesButton
            // 
            this->addNodesButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
            this->addNodesButton->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {
                this->nodeDiscMenuItem,
                    this->addNodeMenuItem
            });
            this->addNodesButton->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"addNodesButton.Image")));
            this->addNodesButton->ImageTransparentColor = System::Drawing::Color::Magenta;
            this->addNodesButton->Name = L"addNodesButton";
            this->addNodesButton->Size = System::Drawing::Size(29, 22);
            this->addNodesButton->Text = L"Add Nodes";
            // 
            // nodeDiscMenuItem
            // 
            this->nodeDiscMenuItem->Name = L"nodeDiscMenuItem";
            this->nodeDiscMenuItem->Size = System::Drawing::Size(157, 22);
            this->nodeDiscMenuItem->Text = L"Node Discovery";
            // 
            // addNodeMenuItem
            // 
            this->addNodeMenuItem->Name = L"addNodeMenuItem";
            this->addNodeMenuItem->Size = System::Drawing::Size(157, 22);
            this->addNodeMenuItem->Text = L"Add Node";
            // 
            // toolStripSeparator1
            // 
            this->toolStripSeparator1->Name = L"toolStripSeparator1";
            this->toolStripSeparator1->Size = System::Drawing::Size(6, 25);
            // 
            // nodesInfoButton
            // 
            this->nodesInfoButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
            this->nodesInfoButton->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"nodesInfoButton.Image")));
            this->nodesInfoButton->ImageTransparentColor = System::Drawing::Color::Magenta;
            this->nodesInfoButton->Name = L"nodesInfoButton";
            this->nodesInfoButton->Size = System::Drawing::Size(23, 22);
            this->nodesInfoButton->Text = L"Load Node Information";
            this->nodesInfoButton->ToolTipText = L"Load Nodes Information";
            // 
            // nodesConfigButton
            // 
            this->nodesConfigButton->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image;
            this->nodesConfigButton->Image = (cli::safe_cast<System::Drawing::Image^>(resources->GetObject(L"nodesConfigButton.Image")));
            this->nodesConfigButton->ImageTransparentColor = System::Drawing::Color::Magenta;
            this->nodesConfigButton->Name = L"nodesConfigButton";
            this->nodesConfigButton->Size = System::Drawing::Size(23, 22);
            this->nodesConfigButton->Text = L"Configure Nodes";
            // 
            // bottomBox
            // 
            this->bottomBox->Controls->Add(this->actionLogBox);
            this->bottomBox->Location = System::Drawing::Point(0, 281);
            this->bottomBox->Name = L"bottomBox";
            this->bottomBox->Size = System::Drawing::Size(638, 119);
            this->bottomBox->TabIndex = 3;
            this->bottomBox->TabStop = false;
            this->bottomBox->Text = L"Action Log";
            this->bottomBox->Enter += gcnew System::EventHandler(this, &mainForm::groupBox1_Enter);
            // 
            // actionLogBox
            // 
            this->actionLogBox->Anchor = static_cast<System::Windows::Forms::AnchorStyles>(((System::Windows::Forms::AnchorStyles::Bottom | System::Windows::Forms::AnchorStyles::Left)
                | System::Windows::Forms::AnchorStyles::Right));
            this->actionLogBox->BackColor = System::Drawing::SystemColors::Window;
            this->actionLogBox->ForeColor = System::Drawing::SystemColors::InactiveCaptionText;
            this->actionLogBox->FormattingEnabled = true;
            this->actionLogBox->Items->AddRange(gcnew cli::array< System::Object^  >(1) { L"--- Ready ---" });
            this->actionLogBox->Location = System::Drawing::Point(6, 17);
            this->actionLogBox->Name = L"actionLogBox";
            this->actionLogBox->Size = System::Drawing::Size(626, 95);
            this->actionLogBox->TabIndex = 0;
            this->actionLogBox->SelectedIndexChanged += gcnew System::EventHandler(this, &mainForm::actionLogBox_SelectedIndexChanged);
            // 
            // baseStationBox
            // 
            this->baseStationBox->BackColor = System::Drawing::SystemColors::Window;
            this->baseStationBox->ForeColor = System::Drawing::SystemColors::InactiveCaptionText;
            this->baseStationBox->FormattingEnabled = true;
            this->baseStationBox->Items->AddRange(gcnew cli::array< System::Object^  >(1) { L"(Add a Base Station)" });
            this->baseStationBox->Location = System::Drawing::Point(6, 19);
            this->baseStationBox->Name = L"baseStationBox";
            this->baseStationBox->Size = System::Drawing::Size(128, 199);
            this->baseStationBox->TabIndex = 5;
            this->baseStationBox->SelectedIndexChanged += gcnew System::EventHandler(this, &mainForm::baseStationBox_SelectedIndexChanged);
            // 
            // sideBox
            // 
            this->sideBox->Controls->Add(this->baseStationBox);
            this->sideBox->Location = System::Drawing::Point(6, 52);
            this->sideBox->Name = L"sideBox";
            this->sideBox->Size = System::Drawing::Size(134, 225);
            this->sideBox->TabIndex = 6;
            this->sideBox->TabStop = false;
            this->sideBox->Text = L"Base Station Controller";
            // 
            // mainForm
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(638, 400);
            this->Controls->Add(this->sideBox);
            this->Controls->Add(this->bottomBox);
            this->Controls->Add(this->toolStrip1);
            this->Controls->Add(this->menuStrip1);
            this->MainMenuStrip = this->menuStrip1;
            this->Name = L"mainForm";
            this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
            this->Text = L"Wireless Controll Manager";
            this->Load += gcnew System::EventHandler(this, &mainForm::mainForm_Load);
            this->menuStrip1->ResumeLayout(false);
            this->menuStrip1->PerformLayout();
            this->toolStrip1->ResumeLayout(false);
            this->toolStrip1->PerformLayout();
            this->bottomBox->ResumeLayout(false);
            this->sideBox->ResumeLayout(false);
            this->ResumeLayout(false);
            this->PerformLayout();

        }
#pragma endregion
    private: System::Void addBaseMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
        addBase^ add_base = gcnew addBase();
        add_base->ShowDialog();
    }
private: System::Void groupBox1_Enter(System::Object^  sender, System::EventArgs^  e) {
}
private: System::Void mainForm_Load(System::Object^  sender, System::EventArgs^  e) {
}
private: System::Void baseStationBox_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
}
private: System::Void actionLogBox_SelectedIndexChanged(System::Object^  sender, System::EventArgs^  e) {
    actionLogBox->Items->Add("Blue") /*Test*/

}
};
}

0 个答案:

没有答案