?
Solved

IDC_STATIC Problem?

Posted on 2008-10-11
24
Medium Priority
?
1,211 Views
Last Modified: 2013-11-20
Hallo all,
I have a problem with changing text for IDC_STATIC. I have 1 Combobox, 1 button and 1 idc_static text in my dialog. For initializing, everything worked quite well. Now after clicking the button, I want to update the new text for the idc_static and also for the combobox. It worked for the combobox but for the static text, it didn't work, and I don't know why. Can somebody help me?

Thank you very much

DDX_Text(pDX, IDC_STATIC_RPA_STATUS, m_strRPAStatus);	
DDX_Control(pDX, IDC_COMBO_STATE_REASON, m_StateReasonCtrl);
 
m_pParentWnd->GetRpaProps()->m_strRPAStatus = StringFromVar(pRpaTab->GetFieldValue("Status")); ---> it didn't work
// CString Status = StringFromVar(pRpaTab->GetFieldValue("Status"));
// SetDlgItemText(IDC_STATIC_RPA_STATUS, Status);              ---> this also didn't work
m_pParentWnd->GetRpaProps()->m_StateReasonCtrl.SetCurSel(nID); ---> it worked perfectly

Open in new window

0
Comment
Question by:rambovn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 9
  • 3
24 Comments
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22695184
The following is one possible solution:

1. Declare m_strRPAStatus as a CStatic member variable:

CStatic m_strRPAStatus;

2. Use the following macro:

DDX_Control(pDX, IDC_STATIC_RPA_STATUS, m_strRPAStatus);

3. To update the text call the following line:

m_strRPAStatus.SetWindowText(_T("New text"));
0
 
LVL 8

Author Comment

by:rambovn
ID: 22695244
Hallo LordOfPorts,
Thank you for your quick reply, I will test it again, but I am still wondering, it worked at the 1st time opening the dialog, why didn't it work after clicking the button on this dialog?
Regards
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22695487
Actually it will work if you call UpdateData(FALSE); after changing the value of the CString variable.
m_pParentWnd->GetRpaProps()->m_strRPAStatus = StringFromVar(pRpaTab->GetFieldValue("Status"));
UpdateData(FALSE);

Open in new window

0
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 
LVL 8

Author Comment

by:rambovn
ID: 22696605
Hi LordOfPorts,
I already tried UpdateData(False); and it didn't work :-(
I am still thinking about your 3 ways above, because if I change the type of the variable, I have to change my whole program, and it will take much time :-(
Do you have any other idea?
Thank you very much
Regards,
0
 
LVL 8

Author Comment

by:rambovn
ID: 22696629
Sorry you gave one solution but I thought there were 3 :-(
0
 
LVL 8

Author Comment

by:rambovn
ID: 22696701
I did exactly in the way in your 1st post, but there was Debug Assert Error at the 1st time opening the dialog :-(

ASSERT(::IsWindow(m_hWnd));
m_hWnd == NULL



0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 22697801
IDC_STATIC is a generic ID for static controls.  To do what you want you need to define a unique  ID for each static control you want to manipulate the text of.
0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22698118
rambovn, you mentioned that with CString it had worked during the dialog initialization so you have already correctly set the ID of your CStatic control to IDC_STATIC_RPA_STATUS, correct?

I have tested the first solution with mapping to control to a CStatic member variable as well as using UpdateData(FALSE); when the member variable was of CString data type successfully so let's check the configuration one more time assuming you are using the CStatic member variable approach from the first post, i.e. how does the OnInitDialog() look like? It would be something like:
BOOL CYourDialogDerivedClassDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
 
	// ...
 
	// TODO: Add extra initialization here
	m_strRPAStatus.SetWindowText(_T("Original Text"));
	
	return TRUE;
}

Open in new window

0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22698142
...and just to also confirm, you have replaced the following line:

DDX_Text(pDX, IDC_STATIC_RPA_STATUS, m_strRPAStatus); // when mapping CString

with:

DDX_Control(pDX, IDC_STATIC_RPA_STATUS, m_strRPAStatus); // when mapping CStatic
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 22698147
>> It worked for the combobox but for the static text, it didn't work, and I don't know why

(Was the text set in the resource editor ?)


The question is not very clear about how the dialog controls are (ID, initial caption)
0
 
LVL 8

Author Comment

by:rambovn
ID: 22698320
To Andy: My ID is already unique, it already worked for the initialization. It didn't work only when I clicked the button on the same dialog.
Can you explain your question "Was the text set in the resource editor" more clearly? Thank you very much
To LordOfPorts: I already did like the way you wrote, but it didn't work also for the inialization so I changed it back
I attached my code again





CRPAProperties::CRPAProperties(CWnd* pParent /*=NULL*/)
	: CDialog(CRPAProperties::IDD, pParent),
	m_pParentWnd (pParent)
{
	//{{AFX_DATA_INIT(CRPAProperties)
	m_strRPAStatus = _T("");
	//}}AFX_DATA_INIT
	m_pParentWnd  = pParent;
}
 
void CRPAProperties::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRPAProperties)
	DDX_Text(pDX, IDC_STATIC_RPA_STATUS, m_strRPAStatus);
	DDX_Control(pDX, IDC_COMBO_STATE_REASON, m_StateReasonCtrl);
//	DDX_Control(pDX, IDC_STATIC_RPA_STATUS, m_strRPAStatus);
	//}}AFX_DATA_MAP
}
 
BEGIN_MESSAGE_MAP(CRPAProperties, CDialog)
	ON_BN_CLICKED(IDC_BUTTON_REFUSE_RPA_ON_PROPERTYDLG, OnButtonRefuseRPA)
END_MESSAGE_MAP()
 
BOOL CRPAProperties::OnInitDialog()
{
	CDialog::OnInitDialog();
	PopulateStateReasonCombo();
	return true;
}
 
// Opening the dialog
void GPSView_Fen::OnRPAProperty()
{
	m_pRPAPropsDlg = new CRPAProperties(this);
	
	CVectorBlock* bsel;
	CListElements* sel = m_pGeoWinManager->GetSelectedVectors( &bsel );
CVectorBasis* el = (CVectorBasis*)sel->obj;
	
	// get the dataset
	long linkid = el->ID();
	m_pRPAPropsDlg->m_pRPATab->GetRecordByID(linkid);
	m_pRPAPropsDlg->m_strIdOrder = StringFromVar(m_pRPAPropsDlg->m_pRPATab->GetFieldValue("ID"));
	m_pRPAPropsDlg->m_strRPAStatus = StringFromVar(m_pRPAPropsDlg->m_pRPATab->GetFieldValue("Status"));
// 	CString	Status1 = StringFromVar(m_pRPAPropsDlg->m_pRPATab->GetFieldValue("Status"));
// 	m_pRPAPropsDlg->m_strRPAStatus.SetWindowText(Status1);
	m_pRPAPropsDlg->m_strRemark = StringFromVar(m_pRPAPropsDlg->m_pRPATab->GetFieldValue("Bemerkung"));	
	m_pRPAPropsDlg->m_strCreateTime = StringFromVar(m_pRPAPropsDlg->m_pRPATab->GetFieldValue("Time"));	
	
	CString filter;
	filter.Format("ID_ORDER = %d", linkid);
	if (m_pRPAPropsDlg->m_pLinkTable->SetFilter(filter))
	{
		variant_t IDFBLE;
		IDFBLE = m_pRPAPropsDlg->m_pLinkTable->GetFieldValue("IDFBAKTI");
		// get FBID for field block
		if ((long)IDFBLE != 0)
		{
			m_pRPAPropsDlg->isFB = true;
			dsActi->m_tab->GetRecordByID(IDFBLE);
			m_pRPAPropsDlg->m_strFLIKFLEK = StringFromVar(dsActi->m_tab->GetFieldValue("FBID"));
		}		
		else if ((long)(IDFBLE = m_pRPAPropsDlg->m_pLinkTable->GetFieldValue("IDLEAKTI")) != 0)// get FLEK for LE
		{
			m_pRPAPropsDlg->isLE = true;
			IDFBLE = m_pRPAPropsDlg->m_pLinkTable->GetFieldValue("IDLEAKTI"); 
			dsActiLE->m_tab->GetRecordByID(IDFBLE);
			m_pRPAPropsDlg->m_strFLIKFLEK = StringFromVar(dsActiLE->m_tab->GetFieldValue("FLEK"));
		}
		
	}
	m_pRPAPropsDlg->m_pLinkTable->SetFilter(""); // reset the filter on the link table
	if (m_pRPAPropsDlg->DoModal () == IDOK) {
		SendMessage(GeoFenster::REFRESH_RPA_LIST_MSG);
		RefreshTableSelection(0,0);
	}
	if (m_pRPAPropsDlg)
		delete m_pRPAPropsDlg;
}

Open in new window

0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22698378
Ok, so m_strRPAStatus is a member variable of the CRPAProperties class and OnRPAProperty is a member method of the GPSView_Fen. Try calling UpdateData(FALSE); from GPSView_Fen::OnRPAProperty() in the following manner:
m_pRPAPropsDlg->m_strRPAStatus = StringFromVar(m_pRPAPropsDlg->m_pRPATab->GetFieldValue("Status"));
m_pRPAPropsDlg->UpdateData(FALSE);

Open in new window

0
 
LVL 8

Author Comment

by:rambovn
ID: 22698386
sorry I sent it before I finished :-(
It worked quite well until I go to the function: void CRejectRpaReason::OnOK()
But what made me confused is why I can update for the combobox, but not for the static :-(


CRPAProperties::CRPAProperties(CWnd* pParent /*=NULL*/)
        : CDialog(CRPAProperties::IDD, pParent),
        m_pParentWnd (pParent)
{
        //{{AFX_DATA_INIT(CRPAProperties)
        m_strRPAStatus = _T("");
        //}}AFX_DATA_INIT
        m_pParentWnd  = pParent;
}
 
void CRPAProperties::DoDataExchange(CDataExchange* pDX)
{
        CDialog::DoDataExchange(pDX);
        //{{AFX_DATA_MAP(CRPAProperties)
        DDX_Text(pDX, IDC_STATIC_RPA_STATUS, m_strRPAStatus);
        DDX_Control(pDX, IDC_COMBO_STATE_REASON, m_StateReasonCtrl);
//      DDX_Control(pDX, IDC_STATIC_RPA_STATUS, m_strRPAStatus);
        //}}AFX_DATA_MAP
}
 
BEGIN_MESSAGE_MAP(CRPAProperties, CDialog)
        ON_BN_CLICKED(IDC_BUTTON_REFUSE_RPA_ON_PROPERTYDLG, OnButtonRefuseRPA)
END_MESSAGE_MAP()
 
BOOL CRPAProperties::OnInitDialog()
{
        CDialog::OnInitDialog();
        PopulateStateReasonCombo();
        return true;
}
 
CRPAProperties* GetRpaProps() {return m_pRPAPropsDlg;}
 
CRPAProperties *m_pRPAPropsDlg;
 
GPSView_Fen::GPSView_Fen() : SelState(GetUserProps())	
{	
	m_pRPAPropsDlg = NULL;
}
 
// Opening the dialog with full information of one Fieldblock
void GPSView_Fen::OnRPAProperty()
{
        m_pRPAPropsDlg = new CRPAProperties(this);
        
        CVectorBlock* bsel;
        CListElements* sel = m_pGeoWinManager->GetSelectedVectors( &bsel );
        CVectorBasis* el = (CVectorBasis*)sel->obj;
        
        // get the dataset
	long linkid = el->ID();
	m_pRPAPropsDlg->m_pRPATab->GetRecordByID(linkid)
        m_pRPAPropsDlg->m_strRPAStatus=   StringFromVar(m_pRPAPropsDlg->m_pRPATab->GetFieldValue("Status"));
 
        if (m_pRPAPropsDlg->DoModal () == IDOK) {
              
        }
        if (m_pRPAPropsDlg)
                delete m_pRPAPropsDlg;
}
 
// After choosing the reason for rejecting RPA, the dialog will be updated with RPA's new status
void CRejectRpaReason::OnOK() 
{
	UpdateData(TRUE);
 
	CComboBox* pCombo = (CComboBox*)GetDlgItem( IDC_COMBO_RPA_REFUSE_REASON );	
	// 	
	CString TaskCodeText; 
	int selectedIndex = pCombo->GetCurSel();
	if (selectedIndex == -1)
	{	
		AfxMessageBox("Bitte geben Sie den Grund der Abweisung an!");
		return;
	}
	else
	{		
		CString stateReasonText;
		DBTable* pRpaTab = m_pParentWnd->GetRPAWebServiceDataset()->m_tab;
		DBTable* pStateReasonTab =  m_pParentWnd->GetRPAWebServiceDataset()->GetStateReasonTable();
		pCombo->GetLBText(selectedIndex, stateReasonText);
		pStateReasonTab->SetFilter("Name = '" + stateReasonText + "'");
		long nID = LongFromVar(pStateReasonTab->GetFieldValue("ID"));
 
		pRpaTab->SetFieldValue("State Reason", (_variant_t)(long)nID);
		
		pRpaTab->SetFieldValue("Status", (_variant_t)("Abgearbeitet"));
		pStateReasonTab->SetFilter("");
		if (m_pParentWnd->GetRpaProps())
		{
		 	m_pParentWnd->GetRpaProps()->m_strRPAStatus = StringFromVar(pRpaTab->GetFieldValue("Status"));
 
		//	m_pParentWnd->GetRpaProps()->m_strRPAStatus.SetWindowText(StringFromVar(pRpaTab->GetFieldValue("Status")))  ;
			
//   			CString Status = StringFromVar(pRpaTab->GetFieldValue("Status"));
// 		 	SetDlgItemText(IDC_STATIC_RPA_STATUS, Status);
		
			//m_pParentWnd->GetRpaProps()->m_strRPAStatus.SetWindowText(Status);
 			m_pParentWnd->GetRpaProps()->m_StateReasonCtrl.SetCurSel(nID);
			m_pParentWnd->GetRpaProps()->Invalidate();
			UpdateData(FALSE);
		}		
		
	}	
	CDialog::OnOK();
}

Open in new window

0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22698422
You need to call the UpdateData method of the window to which m_strRPAStatus belongs because it is mapped to a CString variable. With the combo box you are calling m_pParentWnd->GetRpaProps()->Invalidate(); which takes care of this for you.
0
 
LVL 8

Author Comment

by:rambovn
ID: 22698426
I already tried Updatedata (false); in OnRpaProperty() but it didn't work :-(
0
 
LVL 8

Author Comment

by:rambovn
ID: 22698446
Thank you very much for your patience.
I just added this line this afternoon for trying to solve my Static text problem, without this line, it also worked well for the combo box.
m_pParentWnd->GetRpaProps()->Invalidate();


0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22698450
Can you post the syntax regarding how you called UpdateData(FALSE); in the OnRpaProperty()?

m_pRPAPropsDlg->UpdateData(FALSE); // ?
0
 
LVL 8

Author Comment

by:rambovn
ID: 22698471
void GPSView_Fen::OnRPAProperty()
{
        m_pRPAPropsDlg = new CRPAProperties(this);
       
        CVectorBlock* bsel;
        CListElements* sel = m_pGeoWinManager->GetSelectedVectors( &bsel );
        CVectorBasis* el = (CVectorBasis*)sel->obj;
       
        // get the dataset
        long linkid = el->ID();
        m_pRPAPropsDlg->m_pRPATab->GetRecordByID(linkid)
        m_pRPAPropsDlg->m_strRPAStatus=   StringFromVar(m_pRPAPropsDlg->m_pRPATab->GetFieldValue("Status"));
 
      m_pRPAPropsDlg->UpdateData(FALSE);
        if (m_pRPAPropsDlg->DoModal () == IDOK) {
             m_pRPAPropsDlg->UpdateData(FALSE);
        }
       m_pRPAPropsDlg->UpdateData(FALSE);
        if (m_pRPAPropsDlg)
                delete m_pRPAPropsDlg;
}
I already tried it at 3 places like above

0
 
LVL 19

Expert Comment

by:LordOfPorts
ID: 22698616
Can you display the value of the m_strRPAStatus variable after setting it, i.e. in the code above:

m_pRPAPropsDlg->m_strRPAStatus = StringFromVar(m_pRPAPropsDlg->m_pRPATab->GetFieldValue("Status"));
AfxMessageBox(m_pRPAPropsDlg->m_strRPAStatus);

Is it the correct new value?
0
 
LVL 8

Author Comment

by:rambovn
ID: 22698631
yes it is correct :-(, my problem was so strange for me :-(
OnRPAProperty worked perfectly until now, the problem comes from this function (see the line that is bold), and I already checked the value of " m_pParentWnd->GetRpaProps()->m_strRPAStatus", it is also correct, but why didn't it appear on the dialog?

void CRejectRpaReason::OnOK()
{
        UpdateData(TRUE);
 
        CComboBox* pCombo = (CComboBox*)GetDlgItem( IDC_COMBO_RPA_REFUSE_REASON );      
        //      
        CString TaskCodeText;
        int selectedIndex = pCombo->GetCurSel();
        if (selectedIndex == -1)
        {      
                AfxMessageBox("Bitte geben Sie den Grund der Abweisung an!");
                return;
        }
        else
        {              
                CString stateReasonText;
                DBTable* pRpaTab = m_pParentWnd->GetRPAWebServiceDataset()->m_tab;
                DBTable* pStateReasonTab =  m_pParentWnd->GetRPAWebServiceDataset()->GetStateReasonTable();
                pCombo->GetLBText(selectedIndex, stateReasonText);
                pStateReasonTab->SetFilter("Name = '" + stateReasonText + "'");
                long nID = LongFromVar(pStateReasonTab->GetFieldValue("ID"));
 
                pRpaTab->SetFieldValue("State Reason", (_variant_t)(long)nID);
               
                pRpaTab->SetFieldValue("Status", (_variant_t)("Abgearbeitet"));
                pStateReasonTab->SetFilter("");
                if (m_pParentWnd->GetRpaProps())
                {
                        m_pParentWnd->GetRpaProps()->m_strRPAStatus = StringFromVar(pRpaTab->GetFieldValue("Status"));
 
                //      m_pParentWnd->GetRpaProps()->m_strRPAStatus.SetWindowText(StringFromVar(pRpaTab->GetFieldValue("Status")))  ;
                       
//                      CString Status = StringFromVar(pRpaTab->GetFieldValue("Status"));
//                      SetDlgItemText(IDC_STATIC_RPA_STATUS, Status);
               
                        //m_pParentWnd->GetRpaProps()->m_strRPAStatus.SetWindowText(Status);
                        m_pParentWnd->GetRpaProps()->m_StateReasonCtrl.SetCurSel(nID);
                        UpdateData(FALSE);
                }              
               
        }      
        CDialog::OnOK();
}

0
 
LVL 19

Accepted Solution

by:
LordOfPorts earned 2000 total points
ID: 22698640
Can you try:

m_pParentWnd->GetRpaProps()->UpdateData(FALSE);

instead of:

UpdateData(FALSE);
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 22698768
>>To Andy: My ID is already unique, it already worked for the initialization.

What do you mean by initialisation?
Do you design the dialog then put some text into the static control in the resource editor?  eg. "This is my combo->"
0
 
LVL 8

Author Comment

by:rambovn
ID: 22700331
To Andy: I created the dialog, and by opening it at the 1st time, the static text is filled by the value that I got from the database.
After that, I clicked one button named Reset on this dialog, and tried to fill the static text with the new value, it didn't work. That's what I meant for initialization.
To LordOfPorts: it didn't work.

Thank you very much for your help.

I just want to give up :( But I have to solve it :-(

0
 
LVL 8

Author Comment

by:rambovn
ID: 22700367
To LordOfPorts: sorry, it tried with your last comment again and it worked :-) Now I can smile, it took me 2 days :-)
Thank you very much for your patience and your help again.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question