Click here to Skip to main content
15,892,005 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionpdf995.ini in Program Files (x86) Pin
Erich Ruth19-Sep-19 9:24
Erich Ruth19-Sep-19 9:24 
AnswerRe: pdf995.ini in Program Files (x86) Pin
Victor Nijegorodov19-Sep-19 10:06
Victor Nijegorodov19-Sep-19 10:06 
AnswerRe: pdf995.ini in Program Files (x86) Pin
Gerry Schmitz19-Sep-19 12:21
mveGerry Schmitz19-Sep-19 12:21 
SuggestionRe: pdf995.ini in Program Files (x86) Pin
David Crow20-Sep-19 9:13
David Crow20-Sep-19 9:13 
AnswerRe: pdf995.ini in Program Files (x86) Pin
Richard MacCutchan20-Sep-19 21:04
mveRichard MacCutchan20-Sep-19 21:04 
QuestionMFC VC++ Repopulating the ClistCtrl after database is updated through dialog Pin
Member 1457555618-Sep-19 20:22
Member 1457555618-Sep-19 20:22 
SuggestionRe: MFC VC++ Repopulating the ClistCtrl after database is updated through dialog Pin
Richard MacCutchan18-Sep-19 20:57
mveRichard MacCutchan18-Sep-19 20:57 
GeneralRe: MFC VC++ Repopulating the ClistCtrl after database is updated through dialog Pin
Member 1457555619-Sep-19 3:00
Member 1457555619-Sep-19 3:00 
Below are my codes. I'm new to MFC VC++ and in learning process, pls excuse my coding standard.

This is the Error I got:
Exception thrown at 0x00007FFCFBE90CC3 (mfc140ud.dll) in Medication_Administration.exe: 0xC0000005: Access violation reading location 0x0000000000000040.

If there is a handler for this exception, the program may be safely continued.


1st Dialog :

C++
// Medication_AdministrationDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Medication_Administration.h"
#include "Medication_AdministrationDlg.h"
#include "afxdialogex.h"
#include "odbcinst.h"
#include "afxdb.h"
#include "MedicineDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CPatientDlg dialog



CPatientDlg::CPatientDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_MEDICATION_ADMINISTRATION_DIALOG, pParent)
	, m_strSearch(_T(""))
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CPatientDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_PATIENT_LIST, m_ListControl);
	DDX_Text(pDX, IDC_SEARCH_BOX, m_strSearch);
}

BEGIN_MESSAGE_MAP(CPatientDlg, CDialogEx)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_SEARCH_BUTTON, &CPatientDlg::OnBnClickedSearchButton)
	ON_BN_CLICKED(IDC_SELECT_BUTTON, &CPatientDlg::OnBnClickedSelectButton)
END_MESSAGE_MAP()


// CPatientDlg message handlers

BOOL CPatientDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	
	// 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

	ShowWindow(SW_MINIMIZE);

	// TODO: Add extra initialization here
	m_strSearch = "Enter name or MRN to search";
	UpdateData(FALSE);

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

void CPatientDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	
		CDialogEx::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 CPatientDlg::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
	{
		CDialogEx::OnPaint();
	}
}

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


void CPatientDlg::ResetListControl() {
	m_ListControl.DeleteAllItems();
	int nColumnCount = m_ListControl.GetHeaderCtrl()->GetItemCount();

	// Delete all of the columns.
	for (int i = 0; i < nColumnCount; i++)
	{
		m_ListControl.DeleteColumn(0);
	}
}


void CPatientDlg::OnBnClickedSearchButton()
{
	// TODO: Add your control notification handler code here
	CString SqlQuery, m_LastName, m_FirstName, m_MRN, m_DOB, m_Location;
	int Ctrl_index = 0;
	CDatabase DBobj;
	DBobj.OpenEx(_T("DSN=Demo;UID=root;PWD=root"));
	CRecordset recset(&DBobj);
	UpdateData(TRUE);
	CString dbsearch = m_strSearch;
	if (atoi((char*)(LPCTSTR)dbsearch) == 0){
	//User Input will be string
	//Create a query based on string
		ResetListControl();
		SqlQuery.Format(_T("SELECT * FROM dbdemo.patient WHERE FirstName ='%s'"), dbsearch);
		recset.Open(CRecordset::snapshot, SqlQuery, CRecordset::none);
		//enable selection full row and display grid line
		m_ListControl.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
		//ListView_SetExtendedListViewStyle(m_ListControl, LVS_EX_GRIDLINES);
		m_ListControl.InsertColumn(0, _T("LastName"), LVCFMT_LEFT, 150);
		m_ListControl.InsertColumn(1, _T("FirstName"), LVCFMT_CENTER, 150);
		m_ListControl.InsertColumn(2, _T("MRN"), LVCFMT_CENTER, 150);
		m_ListControl.InsertColumn(3, _T("DOB"), LVCFMT_CENTER, 150);
		m_ListControl.InsertColumn(4, _T("Location"), LVCFMT_CENTER, 150);
		
		while (!recset.IsEOF()) {
			recset.GetFieldValue(_T("LastName"), m_LastName);
			recset.GetFieldValue(_T("FirstName"), m_FirstName);
			recset.GetFieldValue(_T("MRN"), m_MRN);
			recset.GetFieldValue(_T("DOB"), m_DOB);
			recset.GetFieldValue(_T("Location"), m_Location);

			Ctrl_index = m_ListControl.InsertItem(0, m_LastName);
			m_ListControl.SetItemText(Ctrl_index, 1, m_FirstName);
			m_ListControl.SetItemText(Ctrl_index, 2, m_MRN);
			m_ListControl.SetItemText(Ctrl_index, 3, m_DOB);
			m_ListControl.SetItemText(Ctrl_index, 4, m_Location);

			recset.MoveNext();
		}
		recset.Close();
	}
	else {
	//Create a query base on integer number
		ResetListControl();
		SqlQuery.Format(_T("SELECT * FROM dbdemo.patient WHERE MRN ='%s'"), dbsearch);
		recset.Open(CRecordset::snapshot, SqlQuery, CRecordset::none);
		ListView_SetExtendedListViewStyle(m_ListControl, LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
		m_ListControl.InsertColumn(0, _T("LastName"), LVCFMT_LEFT, 150);
		m_ListControl.InsertColumn(1, _T("FirstName"), LVCFMT_CENTER, 150);
		m_ListControl.InsertColumn(2, _T("MRN"), LVCFMT_CENTER, 150);
		m_ListControl.InsertColumn(3, _T("DOB"), LVCFMT_CENTER, 150);
		m_ListControl.InsertColumn(4, _T("Location"), LVCFMT_CENTER, 150);
	
		while (!recset.IsEOF()) {
			recset.GetFieldValue(_T("LastName"), m_LastName);
			recset.GetFieldValue(_T("FirstName"), m_FirstName);
			recset.GetFieldValue(_T("MRN"), m_MRN);
			recset.GetFieldValue(_T("DOB"), m_DOB);
			recset.GetFieldValue(_T("Location"), m_Location);

			Ctrl_index = m_ListControl.InsertItem(0, m_LastName);
			m_ListControl.SetItemText(Ctrl_index, 1, m_FirstName);
			m_ListControl.SetItemText(Ctrl_index, 2, m_MRN);
			m_ListControl.SetItemText(Ctrl_index, 3, m_DOB);
			m_ListControl.SetItemText(Ctrl_index, 4, m_Location);

			recset.MoveNext();
		}
		recset.Close();
	}
	DBobj.Close();	
}




void CPatientDlg::OnBnClickedSelectButton()
{
	CString SqlQuery,p_Name,p_NDC,p_Dose,p_MRN;
	int row = m_ListControl.GetSelectionMark();
	if (row < 0)
	{
		//return;
		MessageBox(_T("Select Something"),_T("Message"));
	}
	else {
		CString s_LastName = m_ListControl.GetItemText(row, 0);
		CString s_FirstName = m_ListControl.GetItemText(row, 1);
		CString s_MRN = m_ListControl.GetItemText(row, 2);
		CString s_DOB = m_ListControl.GetItemText(row, 3);
		CString s_Location = m_ListControl.GetItemText(row, 4);
		MedicineDlg MedDlgObj;
		MedDlgObj.m_PatientName = s_LastName + _T(", ") + s_FirstName;
		MedDlgObj.m_PatientDOB = s_DOB;
		MedDlgObj.m_PatientMRN = s_MRN;
		MedDlgObj.m_PatientLocation = s_Location;
		MedDlgObj.DoModal();
	}

}



2nd Dialog:

C++
// MedicineDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Medication_Administration.h"
#include "MedicineDlg.h"
#include "afxdialogex.h"
#include "odbcinst.h"
#include "afxdb.h"
#include "MedicineListDlg.h"
#include "MedicationDlg.h"


// MedicineDlg dialog

IMPLEMENT_DYNAMIC(MedicineDlg, CDialogEx)

MedicineDlg::MedicineDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_MEDICINE_DLG, pParent)
	, m_PatientName(_T(""))
	, m_PatientDOB(_T(""))
	, m_PatientMRN(_T(""))
	, m_PatientLocation(_T(""))
{

}

MedicineDlg::~MedicineDlg()
{
}

void MedicineDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_MEDICINE_LIST, m_MedListControl);
	DDX_Text(pDX, IDC_PATIENT_NAME, m_PatientName);
	DDX_Text(pDX, IDC_PATIENT_DOB, m_PatientDOB);
	DDX_Text(pDX, IDC_PATIENT_MRN, m_PatientMRN);
	DDX_Text(pDX, IDC_PATIENT_LOCATION, m_PatientLocation);
}


BEGIN_MESSAGE_MAP(MedicineDlg, CDialogEx)
	ON_BN_CLICKED(IDC_SELECT_BUTTON_MED, &MedicineDlg::OnBnClickedSelectButtonMed)
	ON_BN_CLICKED(IDC_ADD_MED_BUTTON, &MedicineDlg::OnBnClickedAddMedButton)
END_MESSAGE_MAP()


// MedicineDlg message handlers

BOOL MedicineDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	GetDlgItem(IDC_PATIENT_NAME)->EnableWindow(FALSE);
	GetDlgItem(IDC_PATIENT_MRN)->EnableWindow(FALSE);
	GetDlgItem(IDC_PATIENT_DOB)->EnableWindow(FALSE);
	GetDlgItem(IDC_PATIENT_LOCATION)->EnableWindow(FALSE);

	DatabaseReload();
	
	//UpdateData(FALSE);

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


void MedicineDlg::OnBnClickedSelectButtonMed()
{
	// TODO: Add your control notification handler code here
	int row = m_MedListControl.GetSelectionMark();
	if (row < 0)
	{
		//return;
		MessageBox(_T("Select Something"), _T("Message"));
	}
	else {
		CString s_MedicineName = m_MedListControl.GetItemText(row, 0);
		CString s_MedicineNDC = m_MedListControl.GetItemText(row, 1);
		CString s_MedicineDose = m_MedListControl.GetItemText(row, 2);
		//CString s_Medicine = m_MedListControl.GetItemText(row, 3);
		CString s_MedicineRoute = m_MedListControl.GetItemText(row, 4);
		CString s_MedicineStatus = m_MedListControl.GetItemText(row, 5);
		CString s_MedicineComment = m_MedListControl.GetItemText(row, 6);
		
		MedicationDlg MedicationObj;
		MedicationObj.m_MedName_MedicationDlg = s_MedicineName;
		MedicationObj.m_MedDSNInput = s_MedicineNDC;
		MedicationObj.DoModal();
	}
	
}


void MedicineDlg::ResetListControl() {
	m_MedListControl.DeleteAllItems();
	int nColumnCount = m_MedListControl.GetHeaderCtrl()->GetItemCount();

	// Delete all of the columns.
	for (int i = 0; i < nColumnCount; i++)
	{
		m_MedListControl.DeleteColumn(0);
	}
}


void MedicineDlg::OnBnClickedAddMedButton()
{
	// TODO: Add your control notification handler code here
	MedicineListDlg MedListObj;
	MedListObj.DoModal();
}

void MedicineDlg::DatabaseReload() {
	CString SqlQuery, p_Name, p_NDC, p_Dose, p_MRN, p_Route, p_Status, p_Comment;
	int Ctrl_index = 0;
	CDatabase DBobj;
	DBobj.OpenEx(_T("DSN=Demo;UID=root;PWD=root"));
	CRecordset recset(&DBobj);
	SqlQuery.Format(_T("SELECT * FROM dbdemo.medicine where MRN = '%s'"), m_PatientMRN);
	recset.Open(CRecordset::snapshot, SqlQuery, CRecordset::none);
	m_MedListControl.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
	
	m_MedListControl.InsertColumn(0, _T("Name"), LVCFMT_LEFT, 150);
	m_MedListControl.InsertColumn(1, _T("NDC"), LVCFMT_CENTER, 150);
	m_MedListControl.InsertColumn(2, _T("Dose"), LVCFMT_CENTER, 150);
	m_MedListControl.InsertColumn(3, _T("MRN"), LVCFMT_CENTER, 150);
	m_MedListControl.InsertColumn(4, _T("Route"), LVCFMT_CENTER, 150);
	m_MedListControl.InsertColumn(5, _T("Status"), LVCFMT_CENTER, 150);
	m_MedListControl.InsertColumn(6, _T("Comment"), LVCFMT_CENTER, 200);
	//enable selection full row

	while (!recset.IsEOF()) {
		recset.GetFieldValue(_T("Name"), p_Name);
		recset.GetFieldValue(_T("NDC"), p_NDC);
		recset.GetFieldValue(_T("Dose"), p_Dose);
		recset.GetFieldValue(_T("MRN"), p_MRN);
		recset.GetFieldValue(_T("Route"), p_Route);
		recset.GetFieldValue(_T("Status"), p_Status);
		recset.GetFieldValue(_T("Comment"), p_Comment);

		Ctrl_index = m_MedListControl.InsertItem(0, p_Name); //Returns the index of the new item if successful or -1 otherwise.
		m_MedListControl.SetItemText(Ctrl_index, 1, p_NDC);
		m_MedListControl.SetItemText(Ctrl_index, 2, p_Dose);
		m_MedListControl.SetItemText(Ctrl_index, 3, p_MRN);
		m_MedListControl.SetItemText(Ctrl_index, 4, p_Route);
		m_MedListControl.SetItemText(Ctrl_index, 5, p_Status);
		m_MedListControl.SetItemText(Ctrl_index, 6, p_Comment);

		recset.MoveNext();
	}
	recset.Close();

}



3rd Dialog Code

C++
// MedicationDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Medication_Administration.h"
#include "MedicationDlg.h"
#include "afxdialogex.h"
#include "odbcinst.h"
#include "afxdb.h"
#include "MedicineDlg.h"


// MedicationDlg dialog

IMPLEMENT_DYNAMIC(MedicationDlg, CDialogEx)

MedicationDlg::MedicationDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(IDD_MED_ADMINISTRATION_DLG, pParent)
	, m_MedName_MedicationDlg(_T(""))
	, m_MedStatus_MedicationDlg(_T(""))
	, m_MedComments_MedicationDlg(_T(""))
{

}

MedicationDlg::~MedicationDlg()
{
}

void MedicationDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, m_MedName_MedicationDlg);
	DDX_Text(pDX, IDC_EDIT2, m_MedStatus_MedicationDlg);
	DDX_Text(pDX, IDC_EDIT3, m_MedComments_MedicationDlg);
	DDX_Control(pDX, IDC_DOSE_COMBO, m_MedDose_MedicationDlg);
	DDX_Control(pDX, IDC_ROUTE_COMBO, m_MedRoute_MedicationDlg);
}


BEGIN_MESSAGE_MAP(MedicationDlg, CDialogEx)
	ON_BN_CLICKED(IDC_SAVE_BUTTON_MEDICATION_DLG, &MedicationDlg::OnBnClickedSaveButtonMedicationDlg)
	ON_CBN_SELCHANGE(IDC_DOSE_COMBO, &MedicationDlg::OnCbnSelchangeDoseCombo)
END_MESSAGE_MAP()


// MedicationDlg message handlers
BOOL MedicationDlg::OnInitDialog() {
	CDialogEx::OnInitDialog();
	GetDlgItem(IDC_EDIT1)->EnableWindow(FALSE);


	UpdateData(FALSE);
	return TRUE;
}


void MedicationDlg::OnBnClickedSaveButtonMedicationDlg()
{
	// TODO: Add your control notification handler code here
	CString m_MedStatusInput, m_MedCommentInput, m_MedDoseInput, m_MedRouteInput, SqlQuery;
	m_MedDose_MedicationDlg.GetLBText(m_MedDose_MedicationDlg.GetCurSel(), m_MedDoseInput);
	m_MedRoute_MedicationDlg.GetLBText(m_MedRoute_MedicationDlg.GetCurSel(), m_MedRouteInput);
	UpdateData(TRUE);
	m_MedStatusInput = m_MedStatus_MedicationDlg;
	m_MedCommentInput = m_MedComments_MedicationDlg;
	
	CDatabase dbobj;
	dbobj.OpenEx(_T("DSN=Demo;UID=root;PWD=root"));
	CRecordset recset(&dbobj);
	SqlQuery.Format(_T("UPDATE dbdemo.medicine SET Route = '%s', Dose = '%s',Status = '%s',Comment = '%s' WHERE NDC ='%s'"), m_MedRouteInput, m_MedDoseInput, m_MedStatusInput, m_MedCommentInput, m_MedDSNInput);
	dbobj.ExecuteSQL(SqlQuery);//till here its working
	MedicineDlg MedicineObj;
	MedicineObj.ResetListControl();// Here the code breaks
	MedicineObj.DatabaseReload();
	
	OnOK();
	
}


void MedicationDlg::OnCbnSelchangeDoseCombo()
{
	// TODO: Add your control notification handler code here
	
}

GeneralRe: MFC VC++ Repopulating the ClistCtrl after database is updated through dialog Pin
Richard MacCutchan19-Sep-19 5:24
mveRichard MacCutchan19-Sep-19 5:24 
GeneralRe: MFC VC++ Repopulating the ClistCtrl after database is updated through dialog Pin
Member 1457555619-Sep-19 5:36
Member 1457555619-Sep-19 5:36 
QuestionRe: MFC VC++ Repopulating the ClistCtrl after database is updated through dialog Pin
David Crow19-Sep-19 5:39
David Crow19-Sep-19 5:39 
AnswerRe: MFC VC++ Repopulating the ClistCtrl after database is updated through dialog Pin
Member 1457555619-Sep-19 5:53
Member 1457555619-Sep-19 5:53 
GeneralRe: MFC VC++ Repopulating the ClistCtrl after database is updated through dialog Pin
Richard MacCutchan19-Sep-19 6:09
mveRichard MacCutchan19-Sep-19 6:09 
GeneralRe: MFC VC++ Repopulating the ClistCtrl after database is updated through dialog Pin
Member 1457555619-Sep-19 6:23
Member 1457555619-Sep-19 6:23 
GeneralRe: MFC VC++ Repopulating the ClistCtrl after database is updated through dialog Pin
Victor Nijegorodov19-Sep-19 6:11
Victor Nijegorodov19-Sep-19 6:11 
GeneralRe: MFC VC++ Repopulating the ClistCtrl after database is updated through dialog Pin
Member 1457555619-Sep-19 6:21
Member 1457555619-Sep-19 6:21 
GeneralRe: MFC VC++ Repopulating the ClistCtrl after database is updated through dialog Pin
Victor Nijegorodov19-Sep-19 6:33
Victor Nijegorodov19-Sep-19 6:33 
GeneralRe: MFC VC++ Repopulating the ClistCtrl after database is updated through dialog Pin
Member 1457555619-Sep-19 6:37
Member 1457555619-Sep-19 6:37 
GeneralRe: MFC VC++ Repopulating the ClistCtrl after database is updated through dialog Pin
Victor Nijegorodov19-Sep-19 8:12
Victor Nijegorodov19-Sep-19 8:12 
AnswerRe: MFC VC++ Repopulating the ClistCtrl after database is updated through dialog Pin
David Crow19-Sep-19 6:47
David Crow19-Sep-19 6:47 
GeneralRe: MFC VC++ Repopulating the ClistCtrl after database is updated through dialog Pin
Member 1457555619-Sep-19 6:50
Member 1457555619-Sep-19 6:50 
GeneralRe: MFC VC++ Repopulating the ClistCtrl after database is updated through dialog Pin
Victor Nijegorodov19-Sep-19 8:09
Victor Nijegorodov19-Sep-19 8:09 
SuggestionRe: MFC VC++ Repopulating the ClistCtrl after database is updated through dialog Pin
David Crow19-Sep-19 9:29
David Crow19-Sep-19 9:29 
QuestionDetermining length of Switch compare Pin
ForNow18-Sep-19 15:45
ForNow18-Sep-19 15:45 
AnswerRe: Determining length of Switch compare Pin
Peter_in_278018-Sep-19 16:49
professionalPeter_in_278018-Sep-19 16:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.