Solved

How to loop through IDC_CONTROLS?

Posted on 2013-06-21
2
291 Views
Last Modified: 2013-06-23
I have nine text fields, named IDC_COMBO1 to IDC_COMBO9 ( values are consecutive ).

I want to obtain the values of each and make one string.

I tried this:

char szComboBuffer[];

  // Loop through all COMBO controls,
     // build final string.
    for (int i = IDC_COMBO1; i <= IDC_COMBO9; ++i)
    {
            GetDlgItemText(gl_hWnd, i, szComboBuffer, 2);
    }
   

Open in new window


I chose 2 as last parameter because they might enter 2 digits in the text field.

If it worked as intended, szComboBuffer would hold the final string.

I am fairly new to this. Can someone help me finish this up? Thanks.
0
Comment
Question by:edvinson
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 39268177
The easiest way would be to use a std::string for that, e.g.

#include <tchar.h>
#include <string>
usineg namespace std;
typedef basic_string<TCHAR> tstring;

TCHAR szComboBuffer[256];
tstring sAllCombos;

  // Loop through all COMBO controls,
     // build final string.
    for (int i = IDC_COMBO1; i <= IDC_COMBO9; ++i)
    {
            GetDlgItemText(gl_hWnd, i, szComboBuffer, 256);

            sAllCombos += sComboBuffer;
    }
   
    MessageBox(NULL,sAllCombos.c_str(),_T("All Together"),MB_OK)';
                                  

Open in new window

0
 
LVL 1

Author Closing Comment

by:edvinson
ID: 39270356
perfect! I ended up taking the long way, but I am rewriting using this. It's much more efficient. Again, I always learn from your solutions.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now