CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Making a setup

  1. #1
    Join Date
    Apr 2018
    Posts
    1

    Making a setup

    Hi there.
    I was wondering if you could help me with some information. I think it is simple, but I'm still novice.

    The thing is. The program loads 39 pics from 2 folders, the program just shows them and also i have there some buttons but that the button doesn't matter. As i said, the program load the pics from 2 folders, which are located in my computer ( c:\desktop\ etc.. ). In the code in a specific variable is the location -> mPicPath = "C:/Users/sasam/Desktop/POO/geo/photoss/init";. Ok, it works fine, but I want to use this program in another computer, and here is the problem. In the code i have just my address, another computer will not have the same address as my computer does, so it would not know where to load the pics from. And even i have to move the two folders with the exe everywhere. I think my point is clear.
    Can I make an install which would generate the folders with the pics in them and automatically readjust to a given address ( in the code ).

    Any infos would be helpful. Thank you.

    The code - ( i will highlight the address variable )

    Code:
    #pragma once
    
    
    namespace speranta {
    
    
        using namespace System;
        using namespace System::ComponentModel;
        using namespace System::Collections::Generic;
        using namespace System::Windows::Forms;
        using namespace System::Data;
        using namespace System::IO;
        using namespace System::Drawing;
    
    
        /// <summary>
        /// Summary for MyForm
        /// </summary>
        int norep[100]; 
        int l = 1;
        
        public ref class MyForm : public System::Windows::Forms::Form
        {
            String^ mPicPath;
            List<String^> ^mPicNames;
            Random^ mRandom;
            // second folder
            String^ mPicPath2;
                 List<String^> ^mPicNames2;
        public:
            MyForm(void)
            {
                InitializeComponent();
            }
    
    
        protected:
            /// <summary>
            /// </summary>
            ~MyForm()
            {
                if (components)
                {
                    delete components;
                }
            }
        private: System::Windows::Forms::PictureBox^  pictureBox1;
        protected:
        private: System::Windows::Forms::Button^  button1;
        private: System::Windows::Forms::Button^  button2;
        private:
            /// <summary>
            /// </summary>
            System::ComponentModel::Container ^components;
    
    
    #pragma region Windows Form Designer generated code
            /// <summary>
            /// </summary>
            void InitializeComponent(void)
            {
                this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
                this->button1 = (gcnew System::Windows::Forms::Button());
                this->button2 = (gcnew System::Windows::Forms::Button());
                (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit();
                this->SuspendLayout();
                // 
                // pictureBox1
                // 
                this->pictureBox1->Location = System::Drawing::Point(12, 12);
                this->pictureBox1->Name = L"pictureBox1";
                this->pictureBox1->Size = System::Drawing::Size(1057, 617);
                this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
                this->pictureBox1->TabIndex = 0;
                this->pictureBox1->TabStop = false;
                this->pictureBox1->Click += gcnew System::EventHandler(this, &MyForm::pictureBox1_Click);
                // 
                // button1
                // 
                this->button1->Location = System::Drawing::Point(306, 635);
                this->button1->Name = L"button1";
                this->button1->Size = System::Drawing::Size(187, 32);
                this->button1->TabIndex = 1;
                this->button1->Text = L"Genereaza";
                this->button1->UseVisualStyleBackColor = true;
                this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
                // 
                // button2
                // 
                this->button2->Location = System::Drawing::Point(581, 635);
                this->button2->Name = L"button2";
                this->button2->Size = System::Drawing::Size(187, 32);
                this->button2->TabIndex = 2;
                this->button2->Text = L"Rezultat";
                this->button2->UseVisualStyleBackColor = true;
                this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
                // 
                // MyForm
                // 
                this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
                this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
                this->ClientSize = System::Drawing::Size(1081, 672);
                this->Controls->Add(this->button2);
                this->Controls->Add(this->button1);
                this->Controls->Add(this->pictureBox1);
                this->Name = L"MyForm";
                this->Text = L"MyForm";
                this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
                (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
                this->ResumeLayout(false);
    
    
            }
    #pragma endregion
    
    
        private: System::Void pictureBox1_Click(System::Object^  sender, System::EventArgs^  e) {
            //------
        }
                 int f;
        public: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
        {
            int k = 0;
            int idx = mRandom->Next(mPicNames->Count);
            do {
                if ((l == 39) || (l==40)) {
                    for (int i = 0; i <= 40; i++) norep[i] = 0;
                }
                k = 0;
                for (int i = l; i > 0; i--)
                    if (idx != norep[i]) k = k + 1;
                if (k == l)
                {
                    norep[l] = idx;
                    pictureBox1->Image = Image::FromFile(mPicNames[idx]);
                    f = idx;
                    l++;
                    break;
                }
                if (k != l) {
                    idx = mRandom->Next(mPicNames->Count);
                }
            } while (k != l);
        }
    
    
        public: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e)
        {
            pictureBox1->Image = Image::FromFile(mPicNames2[f]);
        }
        private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e) {
            norep[0] = 0;
            for (int q = 0; q <= 100; q++) norep[q] = 0;
            // rezultat
            mPicPath2 = "C:/Users/sasam/Desktop/POO/geo/photoss/rezult";
            mPicNames2 = gcnew List<String^>;
            array<String^> ^tmp2 = Directory::GetFiles(mPicPath2, "*.png");
            mPicNames2->AddRange(tmp2);
            tmp2 = Directory::GetFiles(mPicPath2, "*.jpg");
            mPicNames2->AddRange(tmp2);
            if (mPicNames2->Count == 0)
            {
                MessageBox::Show("Nici o imagine adaugata");
                return;
            }
            pictureBox1->Image = Image::FromFile(mPicNames2[0]);
    
    
            // resurse
    
            mPicPath = "C:/Users/sasam/Desktop/POO/geo/photoss/init";
            mPicNames = gcnew List<String^>;
            array<String^> ^tmp = Directory::GetFiles(mPicPath, "*.png");
            mPicNames->AddRange(tmp);
            tmp = Directory::GetFiles(mPicPath, "*.jpg");
            mPicNames->AddRange(tmp);
            if (mPicNames->Count == 0)
            {
                MessageBox::Show("Nici o imagine adaugata");
                return;
            }
            mRandom = gcnew Random();
            pictureBox1->Image = Image::FromFile(mPicNames[0]);
        }
    };
    }
    https://gyazo.com/7405bd26b07010e337de74a3a1bfa854

    photo, to get a better idea.

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Making a setup

    Sure.
    Let your installer install the images in 2 folders next to your EXE.
    For example:
    - c:\program files\MyProgram\MyProgram.EXE
    - c:\program files\MyProgram\Folder1\<images>
    - c:\program files\MyProgram\Folder2\<images>
    Then, in your code, you can ask your executable assembly what its location is, and then you can use that to construct the path to your image folders at run time.
    There is no need for your installer to modify your EXE file.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured