Hi,
The above code generates a window and it has a few buttons on it.That is working fine.
But however the part of the code where class "FileDialog" is defined and the function
"myButton5_Click" is used, it does not seem to work.
The output should be such that - When the browse(myButton5) is clicked, a dialog should be opened.
It would be great if anyone can let me know what is wrong with that part of the code as the code was working before I added that class.
Thanks in advance
#include <afxwin.h>
#include <afxdlgs.h>
#include "resource.h"
#using <System.dll>
#using <System.Windows.Forms.dll>
using namespace std;
using namespace System;
using namespace System::IO;
using namespace System::Windows::Forms;
class MFC_Window :public CFrameWnd
{
CMenu menu1;
CButton myButton1;
CButton myButton2;
CButton myButton3;
CButton myButton4;
CButton myButton5;
CScrollBar Scrollbar;
public:
MFC_Window()
{
Create(NULL,"RTBI Billing");
menu1.LoadMenu(IDR_MENU1);
SetMenu(&menu1);
myButton1.Create("BridgeIP",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(0,10,100,60),this,1);
myButton2.Create("PortNumber",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(0,70,100,120),this,2);
myButton3.Create("RTBI Version",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(0,130,100,180),this,3);
myButton4.Create("Transmit",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(0,190,100,240),this,4);
myButton5.Create("Browse",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,CRect(0,250,100,300),this,5);
Scrollbar.Create( SBS_HORZ | SBS_SIZEBOXTOPLEFTALIGN | WS_CHILD | WS_VISIBLE,CRect(0,350,800,350),this,100);
}
void OnFileNew();
void OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI);
void myButton5_Click( Object^ sender , System::EventArgs^ e );
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP( MFC_Window, CFrameWnd)
ON_COMMAND(IDM_FILE_NEW,OnFileNew)
ON_WM_GETMINMAXINFO()
END_MESSAGE_MAP()
void MFC_Window::OnFileNew()
{
//MessageBox("Clicked File->New");
}
void MFC_Window::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
lpMMI->ptMinTrackSize.x = 500; //width of the window
lpMMI->ptMaxTrackSize.x = 800;
lpMMI->ptMinTrackSize.y = 500; //height of the window
lpMMI->ptMaxTrackSize.y = 800;
CFrameWnd::OnGetMinMaxInfo(lpMMI);
}
public ref class FileDialog abstract : public CommonDialog
{
private:
void myButton5_Click( Object^ sender , System::EventArgs^ e )
{
Stream^ myStream;
OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
openFileDialog1->InitialDirectory = "c:\\";
openFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1->FilterIndex = 2;
openFileDialog1->RestoreDirectory = true;
if ( openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
{
if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
{
// Insert code to read the stream here.
myStream->Close();
}
}
}
};
class MyApp :public CWinApp
{
MFC_Window *wnd;
public:
BOOL InitInstance()
{
wnd = new MFC_Window();
m_pMainWnd = wnd;
m_pMainWnd->ShowWindow(1);
return 1;
}
};
MyApp theApp;