Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9159013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:23:22+00:00 2026-06-17T13:23:22+00:00

void CcalculatorDlg::OnBnClickedButton1() { CString grabData = _T(); m_display.GetLine(0,grabData.GetBuffer(10),10); grabData += _T(1); m_display.SetWindowTextW(grabData.GetBuffer()); grabData.ReleaseBuffer(); }

  • 0
void CcalculatorDlg::OnBnClickedButton1()
{
    CString grabData = _T("");
    m_display.GetLine(0,grabData.GetBuffer(10),10);
    grabData += _T("1");
    m_display.SetWindowTextW(grabData.GetBuffer());
    grabData.ReleaseBuffer();

}

I am trying to make a basic calculator application using MFC, and I am having some trouble with the number inputs.

Above is the code for when the “1” button is pressed. I want it to read in what’s already being displayed in the display control, and then add a 1 onto the end of it like real calculators do. However I just can’t get it to work.

Basically the first button press it works and changes the blank display (edit control) to a 1. But then successive presses don’t continue to add 1’s, and I cannot figure out why.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:23:24+00:00Added an answer on June 17, 2026 at 1:23 pm

    I think the problem in your code is that you tried to modify the string (concatenating _T("1")) after calling GetBuffer() but before calling ReleaseBuffer(). Moreover, you have unbalanced GetBuffer()/ReleaseBuffer() calls.

    Assuming that m_display is a CEdit instance, you can try code like this (worked for me):

    void CcalculatorDlg::OnBnClickedButton1()
    {
        // Get current text from edit control
        // (assume a single-line edit control)
        CString grabData;
        m_display.GetWindowText(grabData);
    
        // Concatenate "1"
        grabData += L'1';
    
        // Update edit control text
        m_display.SetWindowText(grabData);
    }
    

    If you have a multi-line edit control and you want to grab the first (top-most) line using CEdit::GetLine(), you can use code like this (note that according to MSDN documentation, EM_GETLINE doesn’t NUL-terminate the copied line, so you have to explicitly specify line length to ReleaseBuffer()):

    //
    // Read first line from edit control
    //
    
    CString grabData;
    static const int kMaxBufferLength = 80;
    wchar_t* buffer = grabData.GetBuffer(kMaxBufferLength + 1);
    //   Note '+ 1' for NUL string terminator (it seems that EM_GETLINE, which is
    //   wrapped by CEdit::GetLine(), doesn't NUL-terminate the returned string).
    
    const int grabDataLength = m_display.GetLine(0, buffer, kMaxBufferLength);
    grabData.ReleaseBuffer(grabDataLength);
    
    
    // *After* calling ReleaseBuffer(), you can modify the string, e.g.:
    grabData += L'1'; // concatenate "1"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif { // Handle the notificaton when the app is
I'm working on an MFC application, I want to make a global string variable
- (void)viewDidLoad{ [super viewDidLoad]; NSString *path = [[NSBundle mainBundle] pathForResource:@VidName ofType:@mov]; NSURL *url =
void test() { unsigned char c; c = (~0)>>1 ; printf(c is %u\n,c); }
- (void)TargetHit:(int)target{ void (^threadBlock)(void) = ^{ NSLog(@respond to selector %d, [self respondsToSelector:@selector(changeImageOfTarget:)]); [[NSOperationQueue mainQueue]
- (void)connectionDidFinishLoading:(NSURLConnection *)connection { self.listFeedConnection = nil; // release our connection [UIApplication sharedApplication].networkActivityIndicatorVisible =
- (void)fadeOutSplash { UIImageView *splash = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@Default-Landscape~ipad.png]]; [self.window.rootViewController.view addSubview:splash]; // <--
void SaveFiles(out XElement Attachments) { Attachments = null; if (Uploader1.UploadedFiles.Count() > 0) { Attachments
void foo(Node* p[], int size){ _uint64 arr_of_values[_MAX_THREADS]; for (int i=0 ; i < size
void say(char msg[]) { // using pointer to print out the first char of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.