By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,385 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

urgemt need......plzzzzzzzzzz help me......

P: 13
hi,
Am trying to create a dialog box in MFC that has two buttons and an edit control.When i click button1,a dialog box that displays all the files in the system is displayed.when i select a file,the file name with the full path should be displayed in the edit control.When button2 is clicked tyhe file should open and i should be able to view the contents of the file.The code is as follows...

// dialDlg.cpp : implementation file
//

#include "stdafx.h"
#include "dial.h"
#include "dialDlg.h"
#include<iostream>
#include<fstream>
using namespace std;

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
CAboutDlg();

// Dialog Data
enum { IDD = IDD_ABOUTBOX };

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

// Implementation
protected:
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()


// CdialDlg dialog




CdialDlg::CdialDlg(CWnd* pParent /*=NULL*/)
: CDialog(CdialDlg::IDD, pParent)
, m_text(_T(""))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CdialDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, m_text);
}

BEGIN_MESSAGE_MAP(CdialDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BUTTON1, &CdialDlg::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, &CdialDlg::OnBnClickedButton2)
END_MESSAGE_MAP()


// CdialDlg message handlers

BOOL CdialDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here

return TRUE; // return TRUE unless you set the focus to a control
}

void CdialDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}

// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.

void CdialDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}

// The system calls this function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CdialDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}


void CdialDlg::OnBnClickedButton1()
{


CFileDialog FileDlg(TRUE, NULL, NULL, 0,NULL,NULL);


if( FileDlg.DoModal() == IDOK )
{
temp = FileDlg.GetPathName();
m_text.SetString(temp);

}
}



void CdialDlg::OnBnClickedButton2()
{
CFile f1;

CString stri;
CString stri1;
stri="success";
stri1="failed";






if(f1.Open(temp,CFile::modeRead,&fileException)==T RUE)
{

::MessageBox(NULL,(LPCWSTR)stri,NULL,0);


}
else
{
::MessageBox(NULL,(LPCWSTR)stri1,NULL,0);
}



//::MessageBox(NULL,(LPCWSTR)temp,NULL,0);



}



My problem is, a dialog is displayed.But when a file is chosen it is not displayed in the edit control.Also on button2 click,i cannot open the file.plz tell me what is the issue here.anybpdy there to help me....?plzzzzzzzzz it is very urgent.

thanks a lot in advance..
shakthi
Nov 8 '06 #1
Share this Question
Share on Google+
2 Replies


P: 73
it seems that u haven't "m_text.UpdateData( false);" in "OnBnClickedButton1()"
Nov 8 '06 #2

P: 13
hi
thanks for the reply.but where should i go and male that change?please tell me...when i right click the button1 i can menu items like,add class,add variable,insert activex control.Since am very new to MFC please guide me what to do.Am running this code in Microsoft Visual Studio2005.plz let me know.

thank you.
Nov 8 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.