Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 130
  • Last Modified:

need some help with Editbox

properties of the Editboxsee the text in the CStringif you do not scroll it looks fineif you scroll you can not read the text anymoreI need some help with my Editbox. Please take a look at the bitmaps. I add a long CString to the Editbox and can not read the text anymore if I scroll.
Please help. 500 points with a solution.
Thank you.
Best regards,
Thomas
0
tsp2002
Asked:
tsp2002
  • 5
  • 4
2 Solutions
 
HooKooDooKuCommented:
I don't know what the problem is, but what I do see odd is that you are using a member variable to reference a dialog control.  

If you are using MFC, the two typical ways I've been taught to access the properties of a dialog control are:
1. Create a member variable for the control's value and update the control or the variable using the DoDataExchange
2. Use the GetDlgItem() method to get a temporary pointer to the control's window and operate on the temporary control.

An example of the 2nd method would be something like this:
CEdit* pEdit = (CEdit*) GetDlgItem( IDC_EDIT1 );
pEdit->SetWindowText("Text of the Edit Control");

Open in new window


But when you use this method, to access the control's window, the pointer is only guaranteed to be valid for one Windows Message.  With the very next message to be processed by your application, the temporary pointer created by GetDlgItem may be destroyed by the garbage collector.

Of course there is nothing wrong with storing the results of GetDlgItem() in a member variable.  But you have to keep in mind that that pointer could effectively be destroyed at any moment once the message that was processed to create it is finished.

But if your problem had something to do with improper use of GetDlgItem(), I would think you would be getting program crashes rather than a window that appears to be updating the text in its display without first doing an invalidate on the window.

Is your code processing the messages generated by the scroll bar and you are simply forgetting to invalidate the window 1st, or is Windows handling the scroll bar?
0
 
tsp2002Author Commented:
Hallo,
thank you for your answer.
I so not understand your question:
Is your code processing the messages generated by the scroll bar and you are simply forgetting to invalidate the window 1st, or is Windows handling the scroll bar?
0
 
HooKooDooKuCommented:
Are you doing anything to catch and handle windows messages related to repainting the edit control, or are you (properly) allowing windows to handle the messages that would cause the edit field to properly repaint.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
tsp2002Author Commented:
Are you doing anything to catch and handle windows messages related to repainting the edit contro
NO I do not

are you (properly) allowing windows to handle the messages that would cause the edit field to properly repaint.
I donĀ“t know that
0
 
HooKooDooKuCommented:
If you're using MFC, you should have a MESSAGE_MAP.  If so, you have to make sure your MESSAGE_MAP references the base class your dialog has inherited from.

As an example, if you create a Dialog-Based MFC application, wizard should build you a dialog class (cMyDlg) that inherits from CDialogEx.  If you have a MESSAGE_MAP to handling the clicking of an OK button on your dialog, you should have a minimum MESSAGE_MAP that looks something like this:
BEGIN_MESSAGE_MAP(CMyDlg, CDialogEx)
  ON_BN_CLICKED(IDOK,&CMyDlg::OnBnClickedOk)
END_MESSAGE_MAP()

With this message map, a Button Clicked message on the OK button will be directed to the member function CMyDlg::OnBnClickedOk().  All other messages will be directed to the message map for the CDialogEx base class.  If the wrong class has been specified in the BEGIN_MESSAGE_MAP, messages won't be treated like they are supposed to.
0
 
tsp2002Author Commented:
BEGIN_MESSAGE_MAP(CAuftragAendern_Dialog, CDialog)
      ON_BN_CLICKED(IDOK, OnOK)
      ON_BN_CLICKED(IDCANCEL, OnCancel)
      ON_BN_CLICKED(ID_CANCEL, OnBnClickedCancel)
      ON_WM_CLOSE()
.
.
.

END_MESSAGE_MAP()

I think that is not the reason for the error.
Please, just add a Editbox (as I did) in any of your projects and
add a long Cstring to it (with pointer or DoDataExchange), I guess you will see the same error
0
 
HooKooDooKuCommented:
I've tried to recreate the problem, but it's just not happening on my machine... so it's left me guessing based on the various odd things I've encountered working with MFC projects.

Here's what I'm doing in Visual Studio 2013:
Create a new MFC application.
Dialog based
Uncheck SDL option
MFC Standard
Use MFC in a shared DLL
NEXT
Uncheck everything (no About box, no System menu etc)
NEXT
Uncheck everything but ActiveX controls and Common Control Manifest
FINISH
Add a small Edit Box
Modify Properties to Multiline=TRUE and Vertical Scroll = TRUE and Auto HScroll = FALSE

Modify the Code for the Dlg and the OK button such that my dialog code (in its entirety) is the following
CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CTestDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CTestDlg, CDialogEx)
	ON_BN_CLICKED(IDOK,&CTestDlg::OnBnClickedOk)
END_MESSAGE_MAP()

BOOL CTestDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTestDlg::OnBnClickedOk()
{
	CEdit* pEdit = (CEdit*) GetDlgItem( IDC_EDIT1 );
	CString str = _T("ABC DEF GHI JKL MNO PQR STU VWX YZ\n");
	for(int i=0; i<10; i++)
		str += str;
	pEdit->SetWindowText( str );
}

Open in new window

The only odd thing I'm finding is that new line characters (\n) are getting ignored by the edit control and the text strictly word-wraps rather than forcing a new line at the \n.
0
 
tsp2002Author Commented:
Hi,
you are right. I did the same, a new smal project and it works...only the \n is ignored.
So I guess the error is deep in my big program. I do not know how to find it.
Wait a minute... I found the error !!!!!!!!!!!!!!!!!!!!!!!!!!

HBRUSH CAuftragAendern_Dialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
 {
	
	  HBRUSH hbr     = CreateSolidBrush(RGB(255,211,155));
	  HBRUSH hBGEdit = CreateSolidBrush(RGB(255,255,255));

      //Hintergrund Dialog leichtes grau
	  if(nCtlColor==CTLCOLOR_STATIC)
	 {
		  pDC->SetBkMode(TRANSPARENT);
		  pDC->SetBkColor(RGB(240,240,240));
		  pDC->SetTextColor(RGB(0,0,0));   
		 
	 }

	 if(pWnd->GetDlgCtrlID()==IDC_DATETIMEPICKER1)
	 {
		  pDC->SetBkMode(TRANSPARENT);
		  pDC->SetTextColor(RGB(0,0,255));  
		 
	 }


 without this code it will work, but all my editboxen are not white
 //-------------------------------- here is the error ------------------------------
	  //Editboxen Backgraound in white
	  if(nCtlColor==CTLCOLOR_EDIT)
	 {
		  pDC->SetBkMode(TRANSPARENT);
		  pDC->SetTextColor(RGB(0,0,0)); 
		  return hBGEdit;
	 }
 //-------------------------------------------------------------------------------
	  

	  
	 return hbr;
 }

Open in new window

0
 
tsp2002Author Commented:
I did change my code to the following: now it works just fine....please take a look


in h.file	
CBrush* m_pEditBrush;   <----------------


in .cpp
IMPLEMENT_DYNAMIC(CAuftragAendern_Dialog, CDialog)
CAuftragAendern_Dialog::CAuftragAendern_Dialog(CWnd* pParent /*=NULL*/)
	: CDialog(CAuftragAendern_Dialog::IDD, pParent)
	, m_bAbfrage_Checkbox_Lieferdatum(FALSE)
	, m_bAbfrage_Checkbox_Lieferkw(FALSE)
	, m_bAbfrage_checkbox_Strasse(FALSE)
	, m_bAbfrage_checkbox_Postfach(FALSE)
	, m_bAbfrage_checkbox_fakturiert(FALSE)
	, m_bAbfrage_checkbox_nicht_fakturiert(FALSE)
	, m_bAbfrage_checkbox_zum_teil_fakturiert(FALSE)
	, m_bAbfrage_checkbox_storniert(FALSE)
	, m_bAbfrage_checkbox_zurueckgestellt(FALSE)
	, m_bAbfrage_checkbox_AB_noch_nicht_gesendet(FALSE)
	, m_bGuetenSpezAngeklickt(false)
	 
{
                Create(CAuftragAendern_Dialog::IDD,pParent);
	 m_pEditBrush = new CBrush(RGB(255,255,255));    <------------------ color of Editbox Background
}





//---------------------------------------------------------------------------------------------------------------------------------------
HBRUSH CAuftragAendern_Dialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
 { 
       HBRUSH hbr     = CreateSolidBrush(RGB(255,211,155));          //color of Dialogbox Background

	 if(nCtlColor==CTLCOLOR_STATIC)
	 {
		  pDC->SetBkMode(TRANSPARENT);
		  pDC->SetBkColor(RGB(255,211,155)); 
		  pDC->SetTextColor(RGB(0,0,0));   
		  //return hbr;
	 }

      //-------------------------------------------------------------------
      switch (nCtlColor) 
     {  
               case CTLCOLOR_EDIT:
               {
                          pDC->SetTextColor(RGB(0, 0, 0));
                          pDC->SetBkColor(RGB(255, 255, 255));
                           return (HBRUSH)(m_pEditBrush->GetSafeHandle());
               }
               default:
                {              //return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
                           return hbr;
                }
     }
     //-------------------------------------------------------------------


 }
//---------------------------------------------------------------------------------------------------------------------------------------


void CAuftragAendern_Dialog::PostNcDestroy()
{
	CDialog::PostNcDestroy();
	delete m_pEditBrush;              <----------------
	delete this;
}

Open in new window

0

Featured Post

Independent Software Vendors: 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!

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now