Is there an easier way to do this?
void CheckboxsDlg::DoDataExchange(CDataExchange* pDX){
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_CHECK1, m_Checkbox1);
DDX_Control(pDX, IDC_CHECK2, m_Checkbox2);
DDX_Control(pDX, IDC_CHECK3, m_Checkbox3);
DDX_Control(pDX, IDC_CHECK4, m_Checkbox4);
DDX_Control(pDX, IDC_CHECK5, m_Checkbox5);
DDX_Control(pDX, IDC_CHECK6, m_Checkbox6);
DDX_Control(pDX, IDC_CHECK7, m_Checkbox7);
DDX_Control(pDX, IDC_CHECK8, m_Checkbox8);
DDX_Control(pDX, IDC_CHECK9, m_Checkbox9);
}
... (with more checkboxes to be added).
Can this process be looped in some fashion to create 100 more?
I'm using visual studios 2015 as my ide.
Thanks.
Related
I create a static text in a mfc dialog, then I change variable of this static text into CString type and member name is a m_process.
Then, I will use this static text to show the time process, but the identifier not defined.
int64 tm1 = cv::getTickCount();
int64 tm2 = cv::getTickCount();
double sec = (tm2-tm1)/cv::getTickFrequency();
teks.Format(_T("%g"),sec);
m_process.SetWindowTextW(teks);
and this is the error
Error 9 error C2065: 'm_process' : undeclared identifier d:\kuliah\smt 8\bismillah ta\bismillah_dialog\bismillah_dialog\bismillah_dialogdlg.cpp 391 1 Bismillah_Dialog
Error 4 error C2228: left of '.SetWindowTextW' must have class/struct/union d:\kuliah\smt 8\bismillah ta\bismillah_dialog\bismillah_dialog\bismillah_dialogdlg.cpp 268 1 Bismillah_Dialog
this is the declaration of this static text.
in Dlg.cpp
CBismillah_DialogDlg::CBismillah_DialogDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(CBismillah_DialogDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
modeTampil = 0;
openProcess = 0;
modeAuto = 0;
m_area = _T("");
m_process = _T("");
}
void CBismillah_DialogDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
// DDX_Control(pDX, IDC_EDIT1, m_area);
// DDX_Control(pDX, IDC_EDIT2, m_process);
DDX_Control(pDX, IDC_BUTTON2, m_play);
DDX_Control(pDX, IDC_BUTTON1, m_open);
// DDX_Control(pDX, ID_STATIC, m_pic);
DDX_Control(pDX, ID_STATIC, m_pic);
DDX_Control(pDX, IDC_MFCEDITBROWSE1, m_name);
// DDX_Control(pDX, IDC_EDIT3, m_coba);
// DDX_Control(pDX, IDC_EDIT1, m_area);
DDX_Text(pDX, IDC_EDIT1, m_area);
DDX_Text(pDX, IDC_EDIT2, m_process);
}
and in the header file.
public:
CWinThread* thread;
afx_msg void OnEnChangeMfceditbrowse1();
int modeTampil;
int openProcess;
int modeAuto;
static DWORD ThreadPro(LPVOID *x);
afx_msg void threadProcess();
// CStatic m_area;
// CStatic m_process;
CButton m_play;
CButton m_open;
// CStatic m_pic;
CStatic m_pic;
afx_msg void OnBnClickedButton1();
CMFCEditBrowseCtrl m_name;
// CEdit m_coba;
// CStatic m_area;
CString m_area;
CString m_process;
};
The system already declared the static text, but it is not detect when I build this program.
I dont know how to solved it. I'm very confused, and newbie to this MFC. I'm very very need help. thank you :))
Given your code provided, the UI control is mapped to a CString and not to a CEdit.
Therefore, you can't use SetWindowTextW as CString is not a control object.
In your can just use:
m_process.Format(_T("%g"),sec);
UpdateData(FALSE);
I am not saying this is the most efficient way. But it works with your stated code. There are other ways to transfer control content to variables (for example: SetDlgItemText) but this is how I do it. No doubt there are even more methods.
I want to drag file on dialog and get the file's path.
So I searched web and tried that.
MyDlg.cpp
KmCdmMakeMultiProjectDlg::KmCdmMakeMultiProjectDlg(CWnd* pParent)
: CDialog (KmCdmMakeMultiProjectDlg::IDD, pParent)
{
}
void KmCdmMakeMultiProjectDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST_MULTIPART, lst_AddList);
DDX_Control(pDX, IDC_BTN_ADD_PROJECT, btn_AddList);
DDX_Control(pDX, IDC_BTN_ADDLIST_CSV, btn_AddList_CSV);
DDX_Control(pDX, IDC_BTN_DEL_PROJECT, btn_DelList);
DDX_Control(pDX, IDC_BTN_TARGET_SELECT, btn_ReferFolder);
DDX_Control(pDX, IDC_BTN_FILE_SELECT, btn_ReferCSV);
DDX_Control(pDX, IDC_BTN_EXECUTE, btn_Execute);
DDX_Control(pDX, IDC_BTN_EDIT_NAME, btn_EditName);
DDX_Control(pDX, IDC_BTN_EDIT_DESCRIPTION, btn_EditDescription);
DDX_Control(pDX, ID_CLOSE, btn_Close);
}
BEGIN_MESSAGE_MAP(KmCdmMakeMultiProjectDlg, CDialog)
ON_BN_CLICKED(IDC_BTN_ADD_PROJECT, &KmCdmMakeMultiProjectDlg::AddList)
ON_BN_CLICKED(IDC_BTN_ADDLIST_CSV, &KmCdmMakeMultiProjectDlg::AddListCSV)
ON_BN_CLICKED(IDC_BTN_DEL_PROJECT, &KmCdmMakeMultiProjectDlg::DelList)
ON_BN_CLICKED(IDC_BTN_TARGET_SELECT, &KmCdmMakeMultiProjectDlg::SelectPath)
ON_BN_CLICKED(IDC_BTN_FILE_SELECT, &KmCdmMakeMultiProjectDlg::SelectCSV)
ON_BN_CLICKED(IDC_BTN_EXECUTE, &KmCdmMakeMultiProjectDlg::MakeExecute)
ON_BN_CLICKED(IDC_BTN_EDIT_NAME, &KmCdmMakeMultiProjectDlg::EditName)
ON_BN_CLICKED(IDC_BTN_EDIT_DESCRIPTION, &KmCdmMakeMultiProjectDlg::EditDescription)
ON_BN_CLICKED(ID_CLOSE, &KmCdmMakeMultiProjectDlg::CloseDialog)
ON_WM_DROPFILES()
END_MESSAGE_MAP()
BOOL KmCdmMakeMultiProjectDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CDialog::DragAcceptFiles();
}
void KmCdmMakeMultiProjectDlg::OnDropFiles(HDROP hDropInfo)
{
CString csfile = "Why don't come this break point!";
CDialog::OnDropFiles(hDropInfo);
}
I thought it is not difficult.
Just set message ON_WM_DROPFILES() in dialog,
And Set CDialog::DragAcceptFiles(); in dialog's OnInitDialog() method.
I expected that OnDropFiles(HDROP hDropInfo) is run if I drag a file on dialog.
I have tested with debug mode, and checked break point in OnDropFiles method.
But didn't occur anything even though I dropped a file.
Have you any some idea?, waiting your teaching.
Thank you.
If application run as administrator, must include this 2 line before DragAcceptFiles();
For example.
BOOL KmCdmMakeMultiProjectDlg::OnInitDialog()
{
CDialog::OnInitDialog();
ChangeWindowMessageFilter(0x0049, MSGFLT_ADD);
ChangeWindowMessageFilter(WM_DROPFILES, MSGFLT_ADD);
CDialog::DragAcceptFiles();
}
Points are ChangeWindowMessageFilter.
Thank you.
In the name of the C++ an C, do not use ChangeWindowMessageFilter.
This deals with Privilege Isolation (UIPI) message filter and has nothing to do with drag and drop support.
You have to call DragAcceptFiles for any windows object that is going to accept drag and drop by processing the WM_DROPFILES message.
It has to be called when the object is attached to a window (valid m_hWnd)
In my application, I create a modal dialog that contains a mfc List Control. When I don't initialize any columns or items in the List Control, the dialog shows without error. When I try to add a column to the List Control, I get the following Debug Assertion Failed message:
If it helps, the breakpoint is at
_AFXCMN_INLINE int CListCtrl::InsertColumn(int nCol, const LVCOLUMN* pColumn)
{ ASSERT(::IsWindow(m_hWnd)); return (int) ::SendMessage(m_hWnd, LVM_INSERTCOLUMN, nCol, (LPARAM)pColumn); }
I am trying to add the column headers with the following code in OnInitDialog():
BOOL EventL::OnInitDialog()
{
m_ListEventLog.InsertColumn(0, _T("Description"), LVCFMT_LEFT, 250); //Failure happens HERE
//m_ListEventLog.InsertColumn(0, "Description", LVCFMT_LEFT, 200, 0); //I have also tried things such as this.
return FALSE;
}
I add column headers to other CListControls in my application in this way, without problems. The modal dialog is called with the code:
void ListOption::OnBnClickedEventLog()
{
EventL eventLog;
eventLog.DoModal();
}
Maybe you forgot to call the default function:
BOOL EventL::OnInitDialog()
{
BOOL res = CDialog::OnInitDialog();
m_ListEventLog.InsertColumn(0, _T("Description"), LVCFMT_LEFT, 250); //Failure happens HERE
//m_ListEventLog.InsertColumn(0, "Description", LVCFMT_LEFT, 200, 0); //I have also tried things such as this.
return res; // or return FALSE;
}
That's why ASSERT(::IsWindow(m_hWnd)) fails, because m_hWnd of ListView control is not ready. m_hWnd of dialog would not be ready either.
I had the same issue, until i added DDX_Control(pDX, IDC_LIST1, movies); to
void MainDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST1, movies);
}
movies - is name of the Listcontrol
CListCtrl movies;
I am not able to get the DDX_Control working example.
When I create the dialog box, I am not able to create a reference for the control object.
Google doesn't have examples as well.
Thanks.
void CEditDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_COMBO1, m_cmbBox);
DDX_Text(pDX, IDC_EDIT1, m_Edit);
}
void CMFCApplicationDDEView::OnActionEdit2()
{
// TODO: Add your command handler code here
CEditDialog dlg;
CString str;
dlg.m_cmbBox.GetLBText(0, str);
if (dlg.DoModal() == IDOK)
{
MessageBox(dlg.cmbItemStr);
}
}
dlg.m_cmbBox is NULL. Why is it null and how can I reference it in my view
#barmak is correct in saying that you cannot access dialog box controls directly before the InitDialog() has executed.
However, you can set / retrieve the text of the edit portion of a combo box by using DDX_CBString, like:
// in .h file
CString m_cmbItemStr;
// in .cpp
void CEditDialog::DoDataExchange(CDataExchange* pDX)
{ CDialog::DoDataExchange(pDX);
DDX_CBString(pDX, IDC_COMBO1, m_cmbItemStr);
DDX_Text(pDX, IDC_EDIT1, m_Edit);
}
void CMFCApplicationDDEView::OnActionEdit2()
{ CEditDialog dlg;
CString str = TEXT("some value");
dlg.m_cmbItemStr = str;
if (dlg.DoModal() == IDOK)
MessageBox(dlg.m_cmbItemStr);
}
Your code for combo box and dialog box is correct but m_cmbBox.GetLBText() cannot be used before and after DoModal() because there is no window handle. Override like code below, then access combo_str instead of accessing windows
BEGIN_MESSAGE_MAP(CEditDialog, CDialog)
ON_COMMAND(IDOK, OnOK)
//...
END_MESSAGE_MAP()
BOOL CEditDialog::OnInitDialog()
{
BOOL res = CDialog::OnInitDialog();
//Dialog is created, window handles are available, set text here
return res;
}
void CEditDialog::OnOK()
{
//get text before dialog's window handles are destroyed
int sel = m_cmbBox.GetCurSel();
if (sel >= 0) m_cmbBox.GetLBText(sel, cmbItemStr);
CDialog::OnOK();
}
I have MFC dialog form with Text Edit control that allows to enter not more than 5 symbols. But how to make system not accept string less than 5 symbols?
Dialog form:
IMPLEMENT_DYNAMIC(InputDialog, CDialogEx)
InputDialog::InputDialog(CWnd* pParent /*=NULL*/)
: CDialogEx(InputDialog::IDD, pParent)
, m_edit(_T(""))
{
}
InputDialog::~InputDialog()
{
}
void InputDialog::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT_INPUT, m_edit);
DDV_MaxChars(pDX, m_edit, 5);
}
BEGIN_MESSAGE_MAP(InputDialog, CDialogEx)
ON_BN_CLICKED(IDOK, &InputDialog::OnBnClickedOk)
END_MESSAGE_MAP()
Microsoft provides the source to MFC so you can see how they implemented DDV_MaxChars. Simply copy it and change the condition.
void AFXAPI DDV_MinChars(CDataExchange* pDX, CString const& value, int nChars)
{
// ...
if (pDX->m_bSaveAndValidate && value.GetLength() < nChars)
{
// ...
Handle the Kill Focus event for the text field. In the handler for the event get the length of the string that was entered. If it's less than 5, optionally pop up a message, and, set the focus back to the field.