Ahmed
Ahmed

Reputation: 1

Opening a Program with openwith dialog or arguments in Cpp,CLI WindowsForms

I made an image viewer app for learning purposes. I wanted to add a functional code for using the app with open with command in folders ,thus I added a argument code for it but the code seems to not work.Whenever I try to open it with the open with dialog the program does not even start I tried a new form method too, but now changed to pictureBox method. It is not working plus Iam using AdvancedInstaller I want to add a method of Registering the program on target computer. Here is the code


#include "MyForm.h"
using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;
using namespace System::IO;
[STAThread]
int main(array<String^>^ args)
{
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    ImageViewer::MyForm^ form = gcnew ImageViewer::MyForm();
    if (args->Length >0)
    {
        String^ filePath = args[0];
        if (System::IO::File::Exists(filePath))
        {
            Stream^ st = File::OpenRead(filePath);

            Image^ ig = Image::FromStream(st);
            st->Close();

                PictureBox ^ pB = dynamic_cast<PictureBox^>(Application::OpenForms[0]->Controls["pictureBox1"]);
            pB->Image = ig;
        }
    }
    else {
        Application::Run(form);
    } 
    return 0;
    
}

I added the code in form.cpp file.

I tried to change the code piece from new form to picture box. I did not try the registry method as it had some risk potentials

Upvotes: 0

Views: 70

Answers (0)

Related Questions