Click here to Skip to main content
15,920,576 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Compiling generated code? Pin
Christian Graus24-Nov-05 11:58
protectorChristian Graus24-Nov-05 11:58 
GeneralRe: Compiling generated code? Pin
Lord Kixdemp24-Nov-05 12:23
Lord Kixdemp24-Nov-05 12:23 
GeneralRe: Compiling generated code? Pin
Christian Graus24-Nov-05 12:26
protectorChristian Graus24-Nov-05 12:26 
GeneralRe: Compiling generated code? Pin
Lord Kixdemp24-Nov-05 14:17
Lord Kixdemp24-Nov-05 14:17 
QuestionCEdit Pin
LeeeNN24-Nov-05 10:37
LeeeNN24-Nov-05 10:37 
AnswerRe: CEdit Pin
BadKarma24-Nov-05 11:17
BadKarma24-Nov-05 11:17 
GeneralRe: CEdit Pin
LeeeNN24-Nov-05 18:56
LeeeNN24-Nov-05 18:56 
GeneralRe: CEdit Pin
BadKarma24-Nov-05 22:22
BadKarma24-Nov-05 22:22 
Hi,

you've got to do it the hard way, dont use CString use a char buffer to access the edit box.
But char buffers are a very hard way to deal with strings so it would be better to use the std::string class. (this requires #include <string>
You will need to get the text from the control then append your extra data and next send the text back to the control. To simplefy this I wrote 2 wrapper funtions SetText and GetText. This gives the following code:
std::string CMyDlg::GetText(UINT uiControl)
{
  //
  //	Get Window to the control
  //
  CWnd* pWnd = GetDlgItem(uiControl);
	
  if(pWnd)
  {
    std::string sTemp;

    //
    //  Get Text length and allocate buffer - the hard way :)
    //
    int iLen = pWnd->GetWindowTextLength();
    char* pBuffer = new char[iLen+1];
		
    //
    //	Get text and assing to string
    //
    pWnd->GetWindowText(pBuffer, iLen+1);		
    sTemp.assign(pBuffer, iLen);

    //
    //  Release the buffer
    //		
    delete pBuffer;

    return sTemp;
  }
  return "";
}

void CMyDlg::SetText(UINT uiControl, std::string sText)
{
  //
  //	Get Window to the control
  //
  CWnd* pWnd = GetDlgItem(uiControl);

  if(pWnd)
  {
    pWnd->SetWindowText(sText.data());
  }
}

void CMyDlg::AddText(std::string sAdd)
{
  std::string sText = GetText(IDC_MY_EDIT);
  sText += sAdd;
  SetText(IDC_MY_EDIT, sText);
}


This should work ...

codito ergo sum
GeneralRe: CEdit Pin
LeeeNN25-Nov-05 20:58
LeeeNN25-Nov-05 20:58 
Questionfatal error C1083: Cannot open include file: 'mbctype.h', in afxv_w32.h Pin
vic1200024-Nov-05 7:22
vic1200024-Nov-05 7:22 
AnswerRe: fatal error C1083: Cannot open include file: 'mbctype.h', in afxv_w32.h Pin
dm1198-Sep-10 20:53
dm1198-Sep-10 20:53 
QuestionBinary presentation of data Pin
Amr M. K.24-Nov-05 6:52
Amr M. K.24-Nov-05 6:52 
AnswerRe: Binary presentation of data Pin
toxcct24-Nov-05 7:27
toxcct24-Nov-05 7:27 
AnswerRe: Binary presentation of data Pin
Maximilien24-Nov-05 9:57
Maximilien24-Nov-05 9:57 
QuestionTutorial for ActiveX with MFC Pin
sweep12324-Nov-05 4:58
sweep12324-Nov-05 4:58 
QuestionWhen ControlSize exceeds parent size Pin
Pazzuzu24-Nov-05 4:47
Pazzuzu24-Nov-05 4:47 
AnswerRe: When ControlSize exceeds parent size Pin
PJ Arends24-Nov-05 10:24
professionalPJ Arends24-Nov-05 10:24 
GeneralRe: When ControlSize exceeds parent size Pin
Pazzuzu24-Nov-05 21:10
Pazzuzu24-Nov-05 21:10 
GeneralRe: When ControlSize exceeds parent size Pin
Pazzuzu25-Nov-05 4:34
Pazzuzu25-Nov-05 4:34 
Questionkilling thread Pin
Boder Coder24-Nov-05 3:44
Boder Coder24-Nov-05 3:44 
AnswerRe: killing thread Pin
toxcct24-Nov-05 4:19
toxcct24-Nov-05 4:19 
AnswerRe: killing thread Pin
Owner drawn24-Nov-05 20:28
Owner drawn24-Nov-05 20:28 
AnswerRe: killing thread Pin
ThatsAlok27-Nov-05 18:19
ThatsAlok27-Nov-05 18:19 
QuestionOutput to printer in Managed C++ Console Pin
Simon Cornish24-Nov-05 3:18
Simon Cornish24-Nov-05 3:18 
AnswerRe: Output to printer in Managed C++ Console Pin
toxcct24-Nov-05 4:20
toxcct24-Nov-05 4:20 

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.