need some help for a dialog box. im a beginner at this.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: need some help for a dialog box. im a beginner at this.

Hybrid View

  1. #1
    Join Date
    Mar 2013
    Posts
    7

    need some help for a dialog box. im a beginner at this.

    i've took some codes from VS 2010 to make a dialog box in VS 2005 but there are errors to it. can someone help me with this problem. the codes are stated below.

    OpenFileDialog ^ openFileDialog1= gcnew OpenFileDialog();
    OpenFileDialog1->Filter = "Image Files|*.tif";
    OpenFileDialog1->Title = "Select a Image File";



    // Show the Dialog.

    // If the user clicked OK in the dialog and

    // a .CUR file was selected, open it.

    if (OpenFileDialog1->Sho() == System::Windows::Forms:ialogResult::OK)

    {

    // Assign the cursor in the Stream to

    // the Form's Cursor property.

    marshal_context ^ context = gcnew marshal_context();

    const char* str4 = context->marshal_as<const char*>(openFileDialog1->FileName);

    IplImage* img = cvLoadImage(str4);

    cvNamedWindow("MyWindow");

    cvShowImage("MyWindow", img);

    cvWaitKey(0);

    cvDestroyWindow("MyWindow");

    cvReleaseImage(&img);

    // return 0;





    // this->Cursor = gcnew

    // System::Windows::Forms::Cursor(

    // openFileDialog1->OpenFile());

    }

    }

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,585

    Re: need some help for a dialog box. im a beginner at this.

    First, and perhaps most important question: What is it what you want that code to do? Loading a cursor file and setting that up as the current form's cursor could simply be done by the commented-out three lines near the end of your snippet, and you probably know that.

    Displaying the cursor loaded without making it the current cursor is not so simple, yet not really complicated either. Here's how to display it in a picture box, for instance:

    Code:
    System::Void Form1::button2_Click(System::Object^  sender, System::EventArgs^  e)
    {
      if (openFileDialog1->ShowDialog(this) == Windows::Forms::DialogResult::OK) {
        Windows::Forms::Cursor ^csr = gcnew Windows::Forms::Cursor(openFileDialog1->OpenFile());
        Bitmap ^bmp = gcnew Bitmap(csr->Size.Width, csr->Size.Height);
        Graphics ^gr = Graphics::FromImage(bmp);
        csr->Draw(gr, Rectangle(Point::Empty, bmp->Size));
        delete gr;
        pictureBox1->Image = bmp;
      }
    }
    (This button click handler definition is from a separate implementation .cpp file. How and why that is done is discussed in many threads around here. If you want it in an event handler defined in a form class' header file, as the IDE sets it up, simply copy-paste the function body, i.e. the part inside the outermost braces pair, into an empty handler.)

    I recommend you forget completely about external native libraries (OpenCV here, apparently) and all that marshaling/interop stuff for now. Why that is recommended is discussed in various threads around here as well. The .NET framework offers a wealth of functionality for quite a lot of purposes, and only when that doesn't suffice and you don't find a suitible .NET-based external library, you should consider employing native code.

    Please use code tags when posting code.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Mar 2013
    Posts
    7

    Re: need some help for a dialog box. im a beginner at this.

    thanks for replying! i want the code to do something like for example, the dialog box can obtain a button where i can search for any image file i want.

  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,585

    Re: need some help for a dialog box. im a beginner at this.

    And in what aspect would that differ from any usual file search by name and or file type (extension)?
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  5. #5
    Join Date
    Mar 2013
    Posts
    7

    Re: need some help for a dialog box. im a beginner at this.

    the program is working! thanks for the codes but how do i specify to open a specific folder or file?

  6. #6
    Join Date
    Mar 2013
    Posts
    7

    Re: need some help for a dialog box. im a beginner at this.

    WHAT DO THEY MEAN BY "Additional information: Argument 'picture' must be a picture that can be used as a Cursor."

  7. #7
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,585

    Re: need some help for a dialog box. im a beginner at this.

    Quote Originally Posted by mayweather View Post
    the program is working! thanks for the codes but how do i specify to open a specific folder or file?
    For picking a file to open there's the OpenFileDialog you alrrady know. This dialog also optionally allows you to select multiple files in one turn when you set its MultiSelect property to true. Handling the resulting bundle of selected files is relatively easy if they're all of the same type, but if they're not, it's up to you to sort that out. There's also the FolderBrowserDialog that allows to specificalky select a folder, but only one per dialog invocation and no individual files within. More flexibility in file/folder selection would require considerably more effort on your side.

    Quote Originally Posted by mayweather View Post
    WHAT DO THEY MEAN BY "Additional information: Argument 'picture' must be a picture that can be used as a Cursor."
    This looks like being from the descriptive text transported by a .NET exception. What was the exact type of that exception? And where in your code that exception was thrown? Please don't post the offending code line only; some more context around that line could considrably reduce the effort to get to a qualified idea what has caused the exception.

    Also, the message suggests tha you tried to construct a Cursor using a constructor that takes some sort of image as a parameter, but Cursor doesn't have such a constructor (see http://msdn.microsoft.com/en-us/libr...v=vs.100).aspx).

    If you got that message in a different context, please explain.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center