本文介绍了初始化CListbox时我应该在“GetDlgItem()”中添加什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我希望你能帮助我。



我有一个表单,mainForm.h,带有一个列表框(以及其他内容)。我想从另一个文件中将项目添加到列表框中。我声明了CListbox,但不知道在GetDlgItem(/ In Here /)中使用什么,因为我不知道我的列表框的ID。以下是我在其他CPP文件中将列表框初始化为actionLogBox的方式:



Hi all I was hoping you'd help me.

I have a form, mainForm.h, with a listbox(among other things). I'd like to add an item to the listbox from another file. I declared the CListbox but don't know what to use inside the GetDlgItem(/In Here/) because I don't know my listbox's ID. Here's how I initialized it the listbox in the other CPP file to call "actionLogBox":

clistBox* actionLogBox = dynamic_cast<CListBox*>(GetDlgItem(/*No IDea what to put here*/));



这是我的mainForm.h,其列表框名为actionLogBox:




Here is my mainForm.h with the listbox called "actionLogBox":

#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*/

}
};
}

推荐答案


这篇关于初始化CListbox时我应该在“GetDlgItem()”中添加什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 05:50