Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hey peoples,

I'm writing up a media player and I'm stuck at the open dialog box code.

I've made the media player, and it works without errors, only problem I cant go on to find a file that can be played in it. All it does when I click on open is the drop down menu disappears.

Hope someone can help

Thanks!!
MIDL
// openToolStripMenuItem
        //
        this->openToolStripMenuItem->Name = L"openToolStripMenuItem";
        this->openToolStripMenuItem->Size = System::Drawing::Size(152, 22);
        this->openToolStripMenuItem->Text = L"Open";
        this->openToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::openToolStripMenuItem_Click);


Sorry I'm not that great with all this, only just started having to program in C++ again
Posted
Updated 22-Feb-11 5:25am
v5
Comments
Yusuf 22-Feb-11 11:08am    
Show us your code. It will be much better than your description
Nish Nishant 22-Feb-11 11:45am    
Update your question, and add the code for the openToolStripMenuItem_Click method.

1 solution

Code isn't magic. It wont automatically bring up a load dialog just because something is named open.
You need to provide code to show the dialog. There is some way of generating the open and save dialogs from the designer, but I havn't touched managed code in over a year now so I don't remember.
This is the code from my latest C++/CLI assignment with a few changes to fit your solution.

C#
namespace MoviePlayer { //Your namespace name
	public ref class Player : public System::Windows::Forms::Form { //Your class name
		//With all the other variable declarations
		private: System::Windows::Forms::OpenFileDialog^ FileLoadDialog;
		void InitializeComponent(void) {
			//All the other generated component inits
			this->FileLoadDialog = (gcnew System::Windows::Forms::OpenFileDialog());
			this->FileLoadDialog->Title = L"Load File";
		}
		private: System::Void openToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
			FileLoadDialog->DefaultExt = "avi";
			FileLoadDialog->Filter = 
				"All Video Files (*.avi;*.mkv)|*.avi;*.mkv|"
				"AVI Files (*.avi)|*.avi|"
				"Matroska Files (*.mkv)|*.mkv|"
				"All Files (*.*)|*";
			if (FileLoadDialog->ShowDialog() == ::DialogResult::OK) {
				OpenMovie(FileLoadDialog->FileName); //Or whatever
			}
		}
	}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900